<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Leston's Software Development Blog &#187; Programming</title>
	<atom:link href="http://davidleston.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidleston.com</link>
	<description></description>
	<lastBuildDate>Thu, 26 Nov 2009 08:04:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Architecting for scalability and audit logs by explicitly modeling state transitions</title>
		<link>http://davidleston.com/2009/07/architecting-for-scalability/</link>
		<comments>http://davidleston.com/2009/07/architecting-for-scalability/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 06:38:54 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://davidleston.com/?p=47</guid>
		<description><![CDATA[In his talk, Unsleash Your Domain, Greg Young presents a dense discussion of topics about which I am passionate.  At its core, the talk is about how to guarantee a correct audit log and architect for scalability. Before watching this talk, I suggest brushing up on the following terms if you&#8217;re not already familiar with [...]]]></description>
			<content:encoded><![CDATA[<p>In his talk, <strong>Unsleash Your Domain</strong>, <a title="Greg Young's blog" href="http://codebetter.com/blogs/gregyoung/">Greg Young</a> presents a dense discussion of topics about which I am passionate.  At its core, the talk is about how to guarantee a correct audit log and architect for scalability.</p>
<p>Before watching this talk, I suggest brushing up on the following terms if you&#8217;re not already familiar with them: <a title="Wikipedia article on domain model" href="http://en.wikipedia.org/wiki/Domain_model">domain model</a>, <a title="Entities, Value Objects, Aggregates and Roots at LosTechies.com" href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/05/20/entities-value-objects-aggregates-and-roots.aspx">aggregate root</a> and <a href="http://domaindrivendesign.org/node/132">ubiquitous language</a>. (In one system I work on, we use the words &#8220;session&#8221; and &#8220;ticket&#8221; to describe the same concept.  Precise, consistent and accurate language leads to better communication and understanding.)</p>
<p><a title="Greg Young's talk Unleash Your Domain" href="http://www.infoq.com/presentations/greg-young-unshackle-qcon08">Click here to watch the talk.</a></p>
<p>Here are some valuable lessons I see in Greg&#8217;s talk:</p>
<ul>
<li> Software runs.  It&#8217;s about action.  Most models I&#8217;ve seen focus on nouns, such as customer and order, and make actions, such as place order and cancel order, secondary concepts.  A <a title="Wikipedia article on functional software design" href="http://en.wikipedia.org/wiki/Functional_design">functional design</a> focuses  the model on actions, not aggregate roots.  Software with a focus on action makes testing and auditing, which are fundamentally about verifying action, natural.</li>
</ul>
<ul>
<li> Think of the state of an aggregate root as the result of a stream of events.  As Greg mentioned, Martin Fowler dubbed this design  <a title="Martin Fowler's article on Event Sourcing" href="http://martinfowler.com/eaaDev/EventSourcing.html">Event Sourcing</a>.  Distributed source control systems focus on changes to a file rather than versions of files.  This subtle difference is a behind much of the value distributed source control systems offer.  Greg talks about how building your state from a stream of events can result in the ability to rewind and playback history.  To see how this might be visualized, check out <a href="http://googleblog.blogspot.com/2009/05/went-walkabout-brought-back-google-wave.html">the playback feature of Google Wave, demonstrated at 49 minutes into this video</a>.As a bonus, since <a title="Wikipedial article on dataflow programming" href="http://en.wikipedia.org/wiki/Dataflow_programming">a stream is your data</a>, you can easily start writing <a title="Wikipedia article on functional programming" href="http://en.wikipedia.org/wiki/Functional_programming">code in a functional style</a>, even in <a title="How to program in Java in a functional style" href="http://www.google.com/#q=functional+programming+java">Java</a>.  Sequences are the core interface to data for <a title="Clojure's sequences" href="http://clojure.org/sequences">Clojure</a> and <a title="LINQ's iterators article by Jon Skeet" href="http://www.eggheadcafe.com/tutorials/aspnet/159e4793-6b17-4e89-bd94-3bde8a5f2d50/iterators-iterator-block.aspx">LINQ</a>.Also, Greg mentioned the the ability to use a <a title="Wikipedia article on document-oriented databases" href="http://en.wikipedia.org/wiki/Document-oriented_database">document database</a>.  These are the kinds of databases that power Google and Amazon.</li>
</ul>
<ul>
<li>Look for places to implement <a title="Eventual Consistency Is Not That Scary" href="http://smoothspan.wordpress.com/2007/12/22/eventual-consistency-is-not-that-scary/">eventual consistency</a>.  Here&#8217;s an example of an opportunity for eventual consistency:  You want to provide the ability to mark a blog post as a favorite.  Here&#8217;s a series of steps to implement eventual consistency:  You have an application responsible for rendering the blog post and if it has already been marked as a favorite.  User clicks &#8220;mark as favorite.&#8221;  This triggers a call to a different application which accepts the command, validates it, inserts the command into a queue to update the read-only data stores and response to the client that the command has been accepted.  The UI then displays the item has been marked as a favorite.  If the user refreshes the page before all read-only data stores have been updated, then they may see the blog post as not marked as a favorite.  As Greg would say, so what?  This is unlikely to happen and the consequences are small compared to scalability gained by making this operation asynchronous.</li>
</ul>
<ul>
<li>Greg talks about designing business processes as if they were to be done with paper: &#8220;<a href="http://codebetter.com/blogs/gregyoung/archive/2008/05/18/dddd-12-how-long.aspx">Paper was awesome because it never gave the impression of global consistency and it is the thinking that went into the optimization of paper processes that can help us optimize our transactional systems.</a>&#8220;  I thought his restaurant example in the talk might not click with some viewers, so I&#8217;m expanding on it here.  When you place an order at a restaurant, you&#8217;ve inserted a command in a queue.  The waitress transfers the message from the queue she&#8217;s holding to a queue for the kitchen.  The kitchen then prepares your order and notifies the waitress of the event that the order is ready to be served.  The kitchen may then decrement the inventory records.  The waitress then picks up the order and serves it to you.  The reason why this not a fully consistent state is that the cook knows about your order after you&#8217;ve placed it.  The inventory is decremented after the food is cooked.  It&#8217;s eventually consistent.  And it works.As a slight tangent, human processes are often automated because automation is thought to be the solution to poorly executed processes.  Strive to first standardize processes before automation as the process is often ill-defined.  Sometimes, simply defining a process cures problems.  From <a title="The Toyota Way Fieldbook by Jeffrey Liker and David Meier - link to Amazon" href="http://www.amazon.com/gp/product/0071448934?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0071448934">The Toyota Way Fieldbook</a>: &#8220;Standardization is a key element of the Toyota system. A process that is not standardized is fraught with chaos, variation, and the associated problems of continually “riding the wave.” According to Toyota, standardization is the baseline for continuous improvement, the time when real improvement begins and is measurable.&#8221;</li>
</ul>
<p>As a final note, one could benefit from applying one or some of the ideas in this talk.</p>
<p>Related links:</p>
<ul>
<li><a title="Domain-Driven Design: Tackling Complexity in the Heart of Software by Eric Evans - link to Amazon" href="http://www.amazon.com/gp/product/0321125215?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321125215">Domain-Driven Design: Tackling Complexity in the Heart of Software</a> by <a title="Interview with Eric Evans about domain-driven design" href="http://www.infoq.com/interviews/domain-driven-design-eric-evans">Eric Evans</a></li>
</ul>
<ul>
<li><a title="Wikipedia article on Bertrand Meyer" href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a> talks about <a title="Martin Fowler's article on command and query separation" href="http://martinfowler.com/bliki/CommandQuerySeparation.html">command and query separation</a> in his book <a title="Object Oriented Software Construction by Bertrand Meyer - link to Amazon" href="http://www.amazon.com/gp/product/0136291554?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0136291554">Object Oriented Software Construction</a>.</li>
</ul>
<ul>
<li><a href="http://domaindrivendesign.org/node/91">Bounded context</a></li>
<li><a href="http://behaviour-driven.org/">Behavior Driven Development or BDD</a></li>
<li><a href="http://wiki.github.com/aslakhellesoy/cucumber/given-when-then">Given, When, Then</a></li>
</ul>
<p>&#8220;Man acts as though he were the shaper and master of language, while in fact language remains the master of man.&#8221; -  <a title="Wikipedial article on Martin Heidegger, an influential German philosopher" href="http://en.wikipedia.org/wiki/Martin_Heidegger">Martin Heidegger</a></p>
<p>Update Sept 2, 2009: I received feedback that such an architecture is only for mission critical systems. In his talk, <a title="David Pollack's talk at InfoQ" href="http://www.infoq.com/presentations/actors-scala-immutability-pollack">Buy a Feature: An Adventure in Immutability and Actor</a>, David Pollack, the creator of the <a title="Lift web framework for Scala" href="http://liftweb.net/">Lift web framework</a> for <a title="Wikipedial article on the Scala language for the JVM" href="http://en.wikipedia.org/wiki/Scala_%28programming_language%29">Scala</a>, talks about an application, <a title="the seriously fun way to prioritize serious stuff" href="http://www.innovationgames.com/the-games/Buy+a+Feature">Buy a Feature</a>, which implements this architecture.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2009/07/architecting-for-scalability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clean Code</title>
		<link>http://davidleston.com/2009/07/clean-code/</link>
		<comments>http://davidleston.com/2009/07/clean-code/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 05:46:48 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://davidleston.com/?p=41</guid>
		<description><![CDATA[The Clean Code Talks concentrating on writing testable code. In his talk, Unit Testing, Miško Hevery explains unit testing and makes a case for unit tests. &#8230; In his talk, Don&#8217;t look for things, Miško Hevery provides a practical guide to the Principle of Least Knowledge (aka Law of Demeter, aka Don&#8217;t Ask, Tell) &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>The Clean Code Talks concentrating on writing testable code.</p>
<p>In his talk, <strong>Unit Testing</strong>, <a title="Misko Hevery's about page" href="http://misko.hevery.com/about/">Miško Hevery</a> explains unit testing and makes a case for unit tests.</p>
<a href="http://davidleston.com/2009/07/clean-code/"><p><em>Click here to view the embedded video.</em></p></a>
<p>&#8230;</p>
<p>In his talk, <strong>Don&#8217;t look for things</strong>, Miško Hevery provides a practical guide to <a title="Wikipedia article on the Law of Demeter" href="http://en.wikipedia.org/wiki/Law_of_Demeter">the Principle of Least Knowledge (aka Law of Demeter, aka Don&#8217;t Ask, Tell)</a></p>
<a href="http://davidleston.com/2009/07/clean-code/"><p><em>Click here to view the embedded video.</em></p></a>
<p>&#8230;</p>
<p>In his talk, <strong>Global State and Singletons</strong>, Miško Hevery explains why global state leads to bad APIs and difficult to test code.</p>
<a href="http://davidleston.com/2009/07/clean-code/"><p><em>Click here to view the embedded video.</em></p></a>
<p>&#8230;</p>
<p>In hist talk, <strong>Inheritance, Polymorphism, &amp; Testing</strong>, Miško Hevery presents his premise that most if statements can be replaced with polymorphism and explains why one would want to do so.</p>
<a href="http://davidleston.com/2009/07/clean-code/"><p><em>Click here to view the embedded video.</em></p></a>
<p>&#8230;</p>
<p>In his talk, <strong>GuiceBerry,</strong><span> Luiz-Otavio Zorzella</span> makes a case for using dependency injection in your test code</p>
<a href="http://davidleston.com/2009/07/clean-code/"><p><em>Click here to view the embedded video.</em></p></a>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2009/07/clean-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing in batches and improving maintainability</title>
		<link>http://davidleston.com/2008/06/processing-in-batches-and-improving-maintainability/</link>
		<comments>http://davidleston.com/2008/06/processing-in-batches-and-improving-maintainability/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 16:12:56 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=38</guid>
		<description><![CDATA[Here&#8217;s a common pattern: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 void process&#40;final List&#60;Foo&#62; foos&#41; &#123; final ArrayList&#60;bar&#62; batch = new ArrayList&#60;bar&#62;&#40;batchSize&#41;; &#160; for &#40;final Foo foo : foos&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a common pattern:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">void</span> process<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>Foo<span style="color: #339933;">&gt;</span> foos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> ArrayList<span style="color: #339933;">&lt;</span>bar<span style="color: #339933;">&gt;</span> batch <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>bar<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>batchSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Foo foo <span style="color: #339933;">:</span> foos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isValid<span style="color: #009900;">&#40;</span>foo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">final</span> Bar transformed <span style="color: #339933;">=</span> transform<span style="color: #009900;">&#40;</span>foo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            batch.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>transformed<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>batch.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> batchSize <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                processBatch<span style="color: #009900;">&#40;</span>batch<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                batch.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    processBatch<span style="color: #009900;">&#40;</span>batch<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// returns true if we want to process this Foo, otherwise returns false</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> isValid<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Foo foo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// makes a Bar out of a Foo</span>
<span style="color: #000000; font-weight: bold;">private</span> Bar transform<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Foo foo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> processBatch<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> ArrayList<span style="color: #339933;">&lt;</span>Bar<span style="color: #339933;">&gt;</span> bars<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    openTransaction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Bar bar <span style="color: #339933;">:</span> bars<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        executeQuery<span style="color: #009900;">&#40;</span>bar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    closeTransaction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We have some code duplication: <code>processBatch</code> appears twice in <code>process</code>.  Also, we&#8217;re iterating over two collections in order to process each Bar: we&#8217;re iterating over <code>foos</code> in <code>process</code> and <code>bars</code> in <code>processBatch</code>.  With the help of <a href="http://code.google.com/p/google-collections/">Google Collections</a>, we can do better:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">void</span> process<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>Foo<span style="color: #339933;">&gt;</span> foos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> Iterator<span style="color: #339933;">&lt;</span>Foo<span style="color: #339933;">&gt;</span> validFoos <span style="color: #339933;">=</span> Iterators.<span style="color: #006633;">filter</span><span style="color: #009900;">&#40;</span>foos.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, isValid<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">final</span> Iterator<span style="color: #339933;">&lt;</span>Bar<span style="color: #339933;">&gt;</span> bars <span style="color: #339933;">=</span> Iterators.<span style="color: #006633;">transform</span><span style="color: #009900;">&#40;</span>validFoos, transform<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">final</span> Iterator<span style="color: #339933;">&lt;</span>Iterator<span style="color: #339933;">&lt;</span>Bar<span style="color: #339933;">&gt;&gt;</span> batches <span style="color: #339933;">=</span> Iterators.<span style="color: #006633;">partition</span><span style="color: #009900;">&#40;</span>bars, batchSize, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>batches.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Iterator</span> batch <span style="color: #339933;">=</span> batches.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        processBatch<span style="color: #009900;">&#40;</span>batch<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Predicate isValid <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// returns true if we want to process this Foo, otherwise returns false</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> apply<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Foo foo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Function transform <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// makes a Bar out of a Foo</span>
    <span style="color: #000000; font-weight: bold;">public</span> Bar apply<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Foo foo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> processBatch<span style="color: #009900;">&#40;</span>Iterator<span style="color: #339933;">&lt;</span>Bar<span style="color: #339933;">&gt;</span> bars<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    openTransaction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>bars.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> Bar bar <span style="color: #339933;">=</span> batch.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        executeQuery<span style="color: #009900;">&#40;</span>bar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    closeTransactioin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You may want to look at the <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/Iterators.html" title="com.google.common.collect.Iterators">Javadoc for the Iterators class in Google Collections</a> to better understand what&#8217;s happening here.</p>
<p>We removed the duplicate code. And while we still have two loops, one in <code>process</code> and one in <code>processBatch</code>, these loops are iterating over the same collection: <code>foos</code>.  In addition, <code>process</code> has fewer lines of code.  Granted, we have more lines of code elsewhere, but a real <code>process</code> method is likely to be more complex.  By reducing the number of code blocks (braces) in <code>process</code>, we&#8217;re making it easier to read and maintain.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2008/06/processing-in-batches-and-improving-maintainability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Authoring Iterators Using Google&#8217;s Collections Library</title>
		<link>http://davidleston.com/2008/06/iterators-google-collections/</link>
		<comments>http://davidleston.com/2008/06/iterators-google-collections/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 03:23:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=35</guid>
		<description><![CDATA[Let&#8217;s implement an iterator. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 /** * Removes duplicates from the elements returned by provided iterator. * The provided iterator must [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s implement an iterator.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Removes duplicates from the elements returned by provided iterator.
 * The provided iterator must return the elements in the order elements in the order defined by the comparator.
 * The first element of a series of duplicates is returned by this iterator.
 * @param  Type of element returned by the iterator.
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> DedupingOrderedCollectionIterator<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">implements</span> Iterator<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> PeekingIterator<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> iterator<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Comparator<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">super</span> E<span style="color: #339933;">&gt;</span> comparator<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param iterator iterates over an ordered collection
     * @param comparator implements the same comparison used to order the collection
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> DedupingOrderedCollectionIterator<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Iterator<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> E<span style="color: #339933;">&gt;</span> iterator, <span style="color: #000000; font-weight: bold;">final</span> Comparator<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">super</span> E<span style="color: #339933;">&gt;</span> comparator<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">iterator</span> <span style="color: #339933;">=</span> Iterators.<span style="color: #006633;">peekingIterator</span><span style="color: #009900;">&#40;</span>iterator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">comparator</span> <span style="color: #339933;">=</span> comparator<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> hasNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> iterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> E next<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> E next <span style="color: #339933;">=</span> iterator.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>iterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> comparator.<span style="color: #006633;">compare</span><span style="color: #009900;">&#40;</span>next, iterator.<span style="color: #006633;">peek</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            iterator.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> next<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> remove<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">UnsupportedOperationException</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>First, if you&#8217;re confused about the generic wildcards, watch <a href="http://www.youtube.com/watch?v=pi_I7oD_uGI">Josh Bloch&#8217;s presentation entitled <b>Effective Java Reloaded</b></a> and watch for the reference of &#8220;producer extends, consumer super&#8221; (aka PECS) or reference <a title="Effective Java(TM) Programming Language Guide (The Java Series) by Joshua Bloch" href="http://www.amazon.com/gp/product/0201310058?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0201310058">Josh Bloch&#8217;s second edition of Effective Java</a>.</p>
<p>Second, using <a title="Javadoc for com.google.common.collect.PeekingIterator&lt;E&gt;" href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/PeekingIterator.html">Google&#8217;s PeekingIterator</a> often reduces the code you need to deal with iterators.</p>
<p>Third, when implementing an iterator, you usually have to worry about what happens when <code>next()</code> is called when <code>hasNext()</code> would return false.  What exception are you supposed to throw?  And I keep coding the same implementation for <code>remove()</code> and always forget what exception it&#8217;s supposed to throw. <a title="com.google.common.collect.AbstractIterator&lt;T&gt;" href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/AbstractIterator.html"> Google&#8217;s AbstractIterator</a> to the rescue!</p>
<p>Here&#8217;s the same iterator written with com.google.common.collect.AbstractIterator&lt;T&gt;:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Removes duplicates from the elements returned by provided iterator.
 * The provided iterator must return the elements in the order elements in the order defined by the comparator.
 * The first element of a series of duplicates is returned by this iterator.
 * @param  Type of element returned by the iterator.
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> DedupingOrderedCollectionIterator<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> AbstractIterator<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> PeekingIterator<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> iterator<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Comparator<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">super</span> E<span style="color: #339933;">&gt;</span> comparator<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param iterator iterates over an ordered collection
     * @param comparator implements the same comparison used to order the collection
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> DedupingOrderedCollectionIterator<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Iterator<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> E<span style="color: #339933;">&gt;</span> iterator, <span style="color: #000000; font-weight: bold;">final</span> Comparator<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">super</span> E<span style="color: #339933;">&gt;</span> comparator<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">iterator</span> <span style="color: #339933;">=</span> Iterators.<span style="color: #006633;">peekingIterator</span><span style="color: #009900;">&#40;</span>iterator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">comparator</span> <span style="color: #339933;">=</span> comparator<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> E computeNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>iterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">final</span> E next <span style="color: #339933;">=</span> iterator.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>iterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> comparator.<span style="color: #006633;">compare</span><span style="color: #009900;">&#40;</span>next, iterator.<span style="color: #006633;">peek</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                iterator.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">return</span> next<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> endOfData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>AbstractIterator allows you to write concise iterators with consistent behavior.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2008/06/iterators-google-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parleys.com</title>
		<link>http://davidleston.com/2008/04/parleyscom/</link>
		<comments>http://davidleston.com/2008/04/parleyscom/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 19:53:16 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Podcast]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=32</guid>
		<description><![CDATA[Parleys.com publishes talks from software conferences.  I like seeing high-quality slides alongside video of the speaker.  Paryleys&#8217; podcast is an audio only version of the talks you can watch on their site. Two of my favorite talks are: Flow of Change which discusses managing change in source control systems Speaker: Tony Smith, European Technical Services [...]]]></description>
			<content:encoded><![CDATA[<p><a title="View talks from software conferences" href="http://parleys.com">Parleys.com</a> publishes talks from software conferences.  I like seeing high-quality slides alongside video of the speaker.  <a title="Parley's podcast RSS feed" href="http://parleys.libsyn.com/rss">Paryleys&#8217; podcast</a> is an audio only version of the talks you can watch on their site. Two of my favorite talks are:</p>
<ul>
<li><a title="by Tony Smith, European Technical Services Manager for Perforce Software" href="http://www.parleys.com/display/V21Beta/Home#talk=1179649;slide=1;title=Flow%20of%20Change">Flow of Change</a> which discusses managing change in source control systems<br />
Speaker: Tony Smith, European Technical Services Manager for Perforce Software</li>
<li><a title="by Mary Poppendieck author of Lean Software Development: An Agile Toolkit" href="http://www.parleys.com/display/V21Beta/Home#talk=4653075;slide=12;title=The%20Truck%20Driving%20Problem">The Truck Driving Problem</a> which discusses developing innovation<br />
Speaker: Mary Poppendieck, author of <a href="http://www.amazon.com/gp/product/0321150783?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321150783">Lean Software Development: An Agile Toolkit</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2008/04/parleyscom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creative use of closures in testing.</title>
		<link>http://davidleston.com/2007/10/creative-use-of-closures-in-testing/</link>
		<comments>http://davidleston.com/2007/10/creative-use-of-closures-in-testing/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 20:52:15 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=30</guid>
		<description><![CDATA[Having moved to Java, I do miss closures. xUnit.net has a creative use of closures in their unit testing framework: 1 2 3 4 5 6 7 8 9 &#91;Test&#93; public void DivideByZeroThrowsException&#40;&#41; &#123;   Assert.Throws&#60;System.DivideByZeroException&#62;&#40;   delegate   &#123;   DivideNumbers&#40;5, 0&#41;;   &#125;&#41;; &#125; This code snippet was taken from xUnit.net&#8217;s documentation. Previously, [...]]]></description>
			<content:encoded><![CDATA[<p>Having moved to Java, I do miss closures.  xUnit.net has a creative use of closures in their unit testing framework:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>Test<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> DivideByZeroThrowsException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  Assert.<span style="color: #0000FF;">Throws</span><span style="color: #008000;">&lt;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">DivideByZeroException</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>
    <span style="color: #FF0000;">delegate</span>
    <span style="color: #000000;">&#123;</span>
      DivideNumbers<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>This code snippet was taken from <a href="http://www.codeplex.com/xunit/Wiki/View.aspx?title=HowToUse&amp;referringTitle=Home">xUnit.net&#8217;s documentation</a>.</p>
<p>Previously, each test method could have an expected exception.  Now, one can have multiple calls which are expected to throw an exception in a single test method.  Good thinking!</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2007/10/creative-use-of-closures-in-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Phishing and other scams.</title>
		<link>http://davidleston.com/2007/10/phishing-and-other-scams/</link>
		<comments>http://davidleston.com/2007/10/phishing-and-other-scams/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 20:42:12 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=29</guid>
		<description><![CDATA[I always find these security talks entertaining. In his talk, Searching for Evil, Professor Ross Anderson discusses research done by himself, Dr. Richard Clayton, Tyler Moore, Steven Murdoch, and Shishir Nagaraja. Related links: Security Engineering: A Guide to Building Dependable Distributed Systems by Ross J. Anderson &#8211; book on Amazon]]></description>
			<content:encoded><![CDATA[<p>I always find these security talks entertaining.</p>
<p>In his talk, <strong>Searching for Evil</strong>, Professor <a title="biography on Wikipedia" href="http://en.wikipedia.org/wiki/Ross_Anderson">Ross Anderson</a> discusses research done by himself, Dr. Richard Clayton, Tyler Moore, Steven Murdoch, and Shishir Nagaraja.<br />
<a href="http://davidleston.com/2007/10/phishing-and-other-scams/"><p><em>Click here to view the embedded video.</em></p></a></p>
<p>Related links:</p>
<ul>
<li><span class="sans"><span id="btAsinTitle"><a title="Statistically improbable phrases found in this book: birthday theorem, emission security, statistical security, jamming margin, iris codes, copyright marking, compromising emanations" href="http://www.amazon.com/gp/product/0471389226?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0471389226">Security Engineering: A Guide to Building Dependable Distributed Systems by Ross J. Anderson &#8211; book on Amazon</a><br />
</span></span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2007/10/phishing-and-other-scams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design by Contract</title>
		<link>http://davidleston.com/2007/10/design-by-contract/</link>
		<comments>http://davidleston.com/2007/10/design-by-contract/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 20:38:22 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=28</guid>
		<description><![CDATA[I would like to see design by contract become mainstream. JSR-305, Annotations for Software Defect Detection, is a step in the right direction. The applicability of this standard is broader than the name suggests. Here&#8217;s a talk about the JSR by Bill Pugh: I would like to see compile-time and full IDE support for design [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to see <a href="http://en.wikipedia.org/wiki/Design_by_contract">design by contract</a> become mainstream.  <a href="http://jcp.org/en/jsr/detail?id=305">JSR-305</a>, <strong>Annotations for Software Defect Detection</strong>, is a step in the right direction.  The applicability of this standard is broader than the name suggests.  Here&#8217;s a talk about the JSR by Bill Pugh:</p>
<a href="http://davidleston.com/2007/10/design-by-contract/"><p><em>Click here to view the embedded video.</em></p></a>
<p>I would like to see compile-time and full IDE support for design by contact.</p>
<p>Related links:</p>
<ul>
<li><a href="http://www.amazon.com/gp/product/0201634600?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0201634600">Design by Contract, by Example by Richard Mitchell and Jim McKim &#8211; book on Amazon</a></li>
<li><a href="http://www.amazon.com/gp/product/0735622531?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0735622531">The Practical Guide to Defect Prevention by Marc McDonald, Robert Musson, and Ross Smith &#8211; book on Amazon</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2007/10/design-by-contract/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Favorite JavaOne Videos</title>
		<link>http://davidleston.com/2007/09/favorite-javaone-videos/</link>
		<comments>http://davidleston.com/2007/09/favorite-javaone-videos/#comments</comments>
		<pubDate>Tue, 25 Sep 2007 14:50:53 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=27</guid>
		<description><![CDATA[I&#8217;ve moved over to Java. Here are my favorite sessions from JavaOne. Videos require free registration. You only need to register once for all the videos. Language: Languag-Oriented Programming and Language Workbenches Scala is a functional and object-ortiented language that runs on the JVM, it&#8217;s similar to F# (F sharp) Closures for Java Fast x86 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve moved over to Java.  Here are my favorite sessions from JavaOne.<br />
Videos require free registration. You only need to register once for all the videos.<br />
Language:</p>
<ul>
<li><a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-1589/index.html">Languag-Oriented Programming and Language Workbenches</a><a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-1589/index.html"></a></li>
<li><a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-2844/index.html">Scala is a functional and object-ortiented language that runs on the JVM</a>, it&#8217;s similar to <a href="http://en.wikipedia.org/wiki/F_Sharp_(programming_language)">F#</a> (F sharp)<br />
<a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-2844/index.html"></a></li>
<li><a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-2294/index.html">Closures for Java</a><a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-2294/index.html"><br />
</a></li>
<li><a href=" http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-13820/index.html">Fast x86 Emulation in Java</a> This reminds me of the <a href="http://gcc.gnu.org/projects/cli.html">CLI back-end for GCC</a><a href="http://gcc.gnu.org/projects/cli.html"><br />
</a></li>
</ul>
<p>Architecture:</p>
<ul>
<li><a href=" http://sessions.sun.com/learning/javaoneonline/sessions/2006/TS-6037/index.html">To Know the Dependencies is to Know the Architecture &#8211; Dependency Structure Matrix</a><br />
<a href="http://sessions.sun.com/learning/javaoneonline/sessions/2006/TS-6037/index.html"></a></li>
<li><a href=" http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-1419/index.html">OSGi Best Practices</a><br />
<a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-1419/index.html"></a></li>
<li><a href=" http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-7755/index.html">Advanced Spring Framework &#8211; Spring OSGi</a><br />
<a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-7755/index.html"></a></li>
<li><a href="http://developers.sun.com/learning/javaoneonline/sessions/2006/TS-4251/index.html ">Extreme Web Caching</a><a href="http://developers.sun.com/learning/javaoneonline/sessions/2006/TS-4251/index.html "> </a></li>
</ul>
<p>Concurrency:</p>
<ul>
<li><a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-2885/index.html">High-Performance Java in a Multicore World &#8211; memory latency matters</a><br />
<a href="http://sessions.sun.com/learning/javaoneonline/sessions/2007/TS-2885/index.html"></a></li>
<li><a href=" http://sessions.sun.com/learning/javaoneonline/sessions/2006/TS-5354/index.html">Scaling Up a Real Application on Azul</a><a href="http://sessions.sun.com/learning/javaoneonline/sessions/2006/TS-5354/index.html"><br />
</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2007/09/favorite-javaone-videos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated Testing &#8211; Model-Based Testing</title>
		<link>http://davidleston.com/2007/09/automated-testing-model-based-testing/</link>
		<comments>http://davidleston.com/2007/09/automated-testing-model-based-testing/#comments</comments>
		<pubDate>Sat, 22 Sep 2007 22:05:05 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=26</guid>
		<description><![CDATA[In his talk, Model-Based Testing: Black or White?, Mark Utting discusses the difference between black-box and white-box models and their affect on the ability to automate testing. Related links: Practical Model-Based Testing: A Tools Approach by Mark Utting and Bruno Legeard &#8211; book on Amazon]]></description>
			<content:encoded><![CDATA[<p>In his talk, <strong>Model-Based Testing: Black or White?</strong>, Mark Utting discusses the difference between black-box and white-box models and their affect on the ability to automate testing.<br />
<a href="http://davidleston.com/2007/09/automated-testing-model-based-testing/"><p><em>Click here to view the embedded video.</em></p></a></p>
<p>Related links:</p>
<ul>
<li><a title="Statistically improbable phrases found in this book: model coverage criteria, test selection criteria, predicate coverage, test selection criterion, requirements identifiers" href="http://www.amazon.com/gp/product/0123725011?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0123725011">Practical Model-Based Testing: A Tools Approach by Mark Utting and Bruno Legeard &#8211; book on Amazon</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2007/09/automated-testing-model-based-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Closures for Java</title>
		<link>http://davidleston.com/2007/08/closures-for-java/</link>
		<comments>http://davidleston.com/2007/08/closures-for-java/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 07:45:15 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=24</guid>
		<description><![CDATA[In his talk, Closures for Java, Neal Gafter provides a description of and an argument for closures in Java.]]></description>
			<content:encoded><![CDATA[<p>In his talk, <strong>Closures for Java</strong>, Neal Gafter provides a description of and an argument for closures in Java.</p>
<a href="http://davidleston.com/2007/08/closures-for-java/"><p><em>Click here to view the embedded video.</em></p></a>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2007/08/closures-for-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Functional list processing with anonymous delegates</title>
		<link>http://davidleston.com/2006/12/functional-list-processing-with-anonymous-delegates/</link>
		<comments>http://davidleston.com/2006/12/functional-list-processing-with-anonymous-delegates/#comments</comments>
		<pubDate>Mon, 18 Dec 2006 09:55:46 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=17</guid>
		<description><![CDATA[Derrick Coetzee has an article about functional list processing with anonymous delegates. Keep code close to where it&#8217;s used.]]></description>
			<content:encoded><![CDATA[<p>Derrick Coetzee has an article about <a href="http://blogs.msdn.com/devdev/archive/2006/06/30/652802.aspx">functional list processing with anonymous delegates</a>. Keep code close to where it&#8217;s used.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2006/12/functional-list-processing-with-anonymous-delegates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using @ infront of literal strings</title>
		<link>http://davidleston.com/2006/06/using-infront-of-literal-strings/</link>
		<comments>http://davidleston.com/2006/06/using-infront-of-literal-strings/#comments</comments>
		<pubDate>Fri, 16 Jun 2006 04:28:02 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=12</guid>
		<description><![CDATA[Using @ infront of literal strings lets you do: instead of: &#8220;C:\\directory\\file.xml&#8221; or &#8220;SELECT field FROM table where field=var&#8221; you can do: @&#8221;C:\directory\file.xml&#8221; and @&#8221;SELECT field FROM table WHERE field = var&#8221;]]></description>
			<content:encoded><![CDATA[<p>Using @ infront of literal strings lets you do:</p>
<p>instead of:<br />
&#8220;C:\\directory\\file.xml&#8221;<br />
or<br />
&#8220;SELECT field FROM table where field=var&#8221;</p>
<p>you can do:<br />
@&#8221;C:\directory\file.xml&#8221;<br />
and<br />
@&#8221;SELECT<br />
field<br />
FROM<br />
table<br />
WHERE<br />
field = var&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2006/06/using-infront-of-literal-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FTP with streams in .net c# vb.net</title>
		<link>http://davidleston.com/2006/06/ftp-with-streams-in-net-c-vbnet/</link>
		<comments>http://davidleston.com/2006/06/ftp-with-streams-in-net-c-vbnet/#comments</comments>
		<pubDate>Sat, 10 Jun 2006 06:28:01 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=11</guid>
		<description><![CDATA[There needs to be a good opensource ftp library for .net.  I want to be able to write to the FTP stream, not pass a byte array or even a pointer to a file.  Why can&#8217;t I get a Stream Upload(string filename) closing the stream would just end the file upload, not the network connection.  [...]]]></description>
			<content:encoded><![CDATA[<p>There needs to be a good opensource ftp library for .net.  I want to be able to write to the FTP stream, not pass a byte array or even a pointer to a file.  Why can&#8217;t I get a</p>
<p>Stream Upload(string filename)</p>
<p>closing the stream would just end the file upload, not the network connection.  And I want multiple connections and async methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2006/06/ftp-with-streams-in-net-c-vbnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Screen scraping poker web sites</title>
		<link>http://davidleston.com/2006/06/screen-scraping-poker-web-sites/</link>
		<comments>http://davidleston.com/2006/06/screen-scraping-poker-web-sites/#comments</comments>
		<pubDate>Sat, 10 Jun 2006 06:13:49 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=10</guid>
		<description><![CDATA[Screen scraping is very brittle. It will require continual maintenance and will never be complete. A good screen scraper is like writing a parser. Extracting semantic meaning from text with a poor signal to noise ratio is non-trivial. Ideally, you would access the data via an API or a feed. Google, Amazon, Flickr and many [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Screen_scraping">Screen scraping</a> is very brittle.  It will require continual maintenance and will never be complete.  A good screen scraper is like writing a parser.  Extracting semantic meaning from text with a poor signal to noise ratio is non-trivial.</p>
<p>Ideally, you would access the data via an API or a feed. <a title="Google APIs" href="http://code.google.com/more/#products-apis-android"> Google</a>, <a title="Amazon Web Services" href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fbrowse.html%3Fnode%3D3435361&amp;tag=davidleston-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325">Amazon</a>, <a title="Flickr APIs" href="http://www.flickr.com/services/api/">Flickr</a> and many other sites provide free programmatic access to data.  Sites like <a title="Ebates feeds" href="http://www.ebates.com/cash-back/rss-feeds.htm">Ebates</a> offer feeds of data for free.  If your data is not available for free, you may be able to purchase access to an API or feed.</p>
<p>Screen scraping can be used well for other purposes, e.g. testing the UI layer of a web application.  In this application of screen scraping, the same organization generates and tests the UI.</p>
<p>What you really want is to be inside these poker web sites.  You want to be able to be a sort of plug-in for your customers.  I suggest taking a look at <a href="http://bookburro.org/">the Book Burro extension for Firefox</a>, then visit <a title="Webbots, Spiders, and Screen Scrapers: A Guide to Developing Internet Agents with PHP/CURL by Michael Schrenk" href="http://www.amazon.com/gp/product/1593271204?ie=UTF8&amp;tag=davidleston-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1593271204">Amazon</a>.  Book Burro adds an interface widget on top of the Amazon page with prices from other bookstores on the web.  This is a cross-platform solution.</p>
<p>I&#8217;ve read that the poker sites aren&#8217;t much bothered by &#8216;poker bots&#8217;.  As long as people gamble, they&#8217;re happy.  Maybe you could find a poker site that would let you plug in your software&#8230; or make your own site for all the users of your software to play on and they think they&#8217;re playing other people.  A game server, now that&#8217;s a completely different kind of software.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2006/06/screen-scraping-poker-web-sites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Faster first byte.</title>
		<link>http://davidleston.com/2006/02/faster-first-byte/</link>
		<comments>http://davidleston.com/2006/02/faster-first-byte/#comments</comments>
		<pubDate>Mon, 20 Feb 2006 08:57:18 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=7</guid>
		<description><![CDATA[override render(HtmlWriter) HtmlWriter.Flush DoSomeExpensiveOperation // or join with a thread that&#8217;s loading state base.Render(HtmlWriter) This way, you can send the headers and navigation to the client so they&#8217;ll see something while you&#8217;re waiting for something to finish. Perhaps the client won&#8217;t even finish downloading the headers when the render completes, you&#8217;ve gotten the first byte [...]]]></description>
			<content:encoded><![CDATA[<p>override render(HtmlWriter)<br />
HtmlWriter.Flush<br />
DoSomeExpensiveOperation<br />
// or join with a thread that&#8217;s loading state<br />
base.Render(HtmlWriter)</p>
<p>This way, you can send the headers and navigation to the client so they&#8217;ll see something while you&#8217;re waiting for something to finish.  Perhaps the client won&#8217;t even finish downloading the headers when the render completes, you&#8217;ve gotten the first byte out faster.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2006/02/faster-first-byte/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Should you be persisting more state?</title>
		<link>http://davidleston.com/2006/02/should-you-be-persisting-more-state/</link>
		<comments>http://davidleston.com/2006/02/should-you-be-persisting-more-state/#comments</comments>
		<pubDate>Mon, 20 Feb 2006 08:47:15 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidleston.com/?p=5</guid>
		<description><![CDATA[Lost state is state that has been destroyed, deleted, garbage collected or otherwise removed from storage not because of some domain specified reason.  In the best case because of limited storage capabilities, but because the value of the state is underestimated. Microsoft Word has autosave.  By default, every ten minutes the document you’re editing is [...]]]></description>
			<content:encoded><![CDATA[<p>Lost state is state that has been destroyed, deleted, garbage collected or otherwise removed from storage not because of some domain specified reason.  In the best case because of limited storage capabilities, but because the value of the state is underestimated.</p>
<p>Microsoft Word has autosave.  By default, every ten minutes the document you’re editing is persisted to disk in case of an unexpected termination of the application.  I always change this to one minute, because why would you ever want to wait ten?</p>
<p>And why doesn’t New Egg’s shopping cart remember what I had in it?  I’ve had business people tell me customers get angry when they see items in their cart many months later.  I argue, at least have it be an option to review.  Like an automated (private) wish list.</p>
<p>Suppose you have a web server produce views of product information that is expensive to acquire. Perhaps it’s over a web service or a remote database.  Often, you’ll cache this information in memory, trading aging data for faster request processing.  But what if there’s a power outage, and both the web server and database suddenly shut down.  If your application starts running before the web service or database, then your application is missing an opportunity to process requests. If you had stale data, you could still provide information to anxious customers.  Even if you didn’t want to show old quantity levels or prices, you could still provide a description, and maybe a notice that you’ll be fully operational in a moment.</p>
<p>Consider dumping in-memory state, such as a cache, to disk if the connection to the data source is lost or during low load.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidleston.com/2006/02/should-you-be-persisting-more-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
