<?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>Free Association</title>
	<atom:link href="http://daviddoolin.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://daviddoolin.com</link>
	<description>Polymath</description>
	<lastBuildDate>Sat, 16 Mar 2013 18:53:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Test-driven development: structuring workflow</title>
		<link>http://daviddoolin.com/mastery/testdriven-development-structuring-workflow/</link>
		<comments>http://daviddoolin.com/mastery/testdriven-development-structuring-workflow/#comments</comments>
		<pubDate>Sun, 20 Jan 2013 17:17:00 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Mastery]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=5874</guid>
		<description><![CDATA[Test driven development (TDD) is perceived as being much more difficult than writing programs without tests. It&#8217;s true that it is more difficult. It&#8217;s not true that it&#8217;s much more difficult. It is, however, a skill and it must be learned just as any other must be learned. Having tools helps. Many modern scripting languages [...]]]></description>
				<content:encoded><![CDATA[<p>Test driven development (TDD) is perceived as being much more difficult than writing programs without tests. It&#8217;s true that it is more difficult. It&#8217;s not true that it&#8217;s <em>much</em> more difficult.</p>
<p>It is, however, a skill and it must be learned just as any other must be learned.</p>
<p>Having tools helps. Many modern scripting languages such as Python and Ruby have testing tools built into the language or in standard libraries. With other languages, such as c or c++, some effort must be made to set up an appropriate tool chain. This tool chain usually require using either pre-written libraries, or writing the necessary test infrastructure internally.</p>
<p>At least as important as having useful tools is creating the right habits for test driving coding. These test-first habits live in your workflow.</p>
<h2>Structuring workflow</h2>
<p>Learning how to do anything once is not that hard. Mastering the practice of a discipline requires building effective habits. For example, many people have exercise equipment at home, and know how to use it. But they go to the gym instead, where they find context, motivation and inspiration. The habit is at the gym, not at home.</p>
<p>While motivation and inspiration can be elusive, creating an appropriate context is mechanical. It&#8217;s as easy (and difficult) as creating an appropriate set of habits. Here are a few habits I&#8217;ve found useful for practicing test driven development:</p>
<ol>
<li>In your editor of choice, always open spec or test files in a known buffer which you can get to with a keystroke or two. I&#8217;m currently using vim, so I always know that the file containing tests is in buffer 1: <code>ESC:b1</code> gets me there in a flash.</li>
<li>Use a repl like irb or pry to check syntax. This is more helpful than it first appears. It takes the place of all those <code>puts</code> and <code>print</code>s. If you&#8217;re working with a compiled language, write stupid simple standalone programs to check behavior. This can as efficient as cat-ing a program into gcc from the command line.</li>
<li>Always commit a test first, or never less than a test in parallel with new code. Never commit untested code. This is not the same as <em>never pushing</em> untested code.</li>
<li>Scope objects and internal API in the test or spec file and build your functionality in the test file first.</li>
<li>More? You tell me, comments are open!</li>
</ol>
<p>Following these rules helps me create a workflow structure conducive to TDD.</p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/mastery/testdriven-development-structuring-workflow/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Vending machines Vegas style</title>
		<link>http://daviddoolin.com/marketing/vending-machines-vegas-style/</link>
		<comments>http://daviddoolin.com/marketing/vending-machines-vegas-style/#comments</comments>
		<pubDate>Sat, 19 Jan 2013 17:24:47 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Marketing]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=5862</guid>
		<description><![CDATA[I&#8217;m skimming Hoare&#8217;s Communicating Sequential Processes, a rather technical book on concurrency. One of the examples discusses a vending machine providing a food sample first, before payment. The vending machine is used as an illustration for Hoare&#8217;s theoretical notation. But think of that vending machine for a moment. A vending machine which randomly serves free [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m skimming Hoare&#8217;s <em>Communicating Sequential Processes</em>, a rather technical book on concurrency.</p>
<p>One of the examples discusses a vending machine providing a food sample first, before payment. The vending machine is used as an illustration for Hoare&#8217;s theoretical notation.</p>
<p>But think of that vending machine for a moment.</p>
<p><em>A vending machine which randomly serves free stuff</em>. For example, on average, 10% is served free.</p>
<p>It could work two ways:</p>
<ol>
<li>Refund the money, &#8220;compliments of the house&#8221;, or</li>
<li>Just walk up and push a random button, free food pops out.</li>
</ol>
<p>I have a hunch the sales volume would go up. Way, way up.</p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/marketing/vending-machines-vegas-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Constructors should set state, nothing more</title>
		<link>http://daviddoolin.com/coding/constructors-set-state/</link>
		<comments>http://daviddoolin.com/coding/constructors-set-state/#comments</comments>
		<pubDate>Thu, 03 Jan 2013 23:25:25 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=459</guid>
		<description><![CDATA[If a constructor has to do a lot of processing to set its initial state, that&#8217;s a code smell. When a constructor is used for the main processing part of a class, such the code requires an instance of Foo to spend a lot of cycles computing Bar, that&#8217;s almost a sure indicator the design [...]]]></description>
				<content:encoded><![CDATA[<p>If a constructor has to do a lot of processing to set its initial state, that&#8217;s a code smell.</p>
<p>When a constructor is used for the main processing part of a class, such the code requires an instance of Foo to spend a lot of cycles computing Bar, that&#8217;s almost a sure indicator the design needs improvement. It may not need a lot of improvement, but it almost surely needs rethinking.</p>
<p>Constructors should only set state, really. If arguments<br />
must be passed, those should be easy to instantiate themselves.</p>
<p>I&#8217;m not the only person who believes <a href="http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/">doing work in constructors is a flaw</a>.</p>
<p>You can google &#8220;doing work in constructors&#8221; to find like thinking.</p>
<h2>Really bad smell</h2>
<p>Check this out:</p>
<pre class="brush: cpp; title: ; notranslate">
Foo::Foo(Bar b) : b(b) {

 private_m = Baz::some_wackadoodle_preset_structure;
};
</pre>
<p>I recently had to find a way to test such a constructor, where the constructor depended on some static (global) value of another class, which was initialized elsewhere.</p>
<p>Very painful.</p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/coding/constructors-set-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design rule of thumb: 1 loop per method</title>
		<link>http://daviddoolin.com/coding/design-rule-of-thumb-1-loop-per-method/</link>
		<comments>http://daviddoolin.com/coding/design-rule-of-thumb-1-loop-per-method/#comments</comments>
		<pubDate>Sat, 20 Oct 2012 03:03:22 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[integration testing]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=5711</guid>
		<description><![CDATA[Here&#8217;s a great little guideline for writing testable code: limit the number of loops in any function or method to 1 at each level of nesting. Consider the following function with two &#8220;top level&#8221; loops: Refactor 1 The body of a loop is often a great candidate for a refactoring. Do this instead: Instead of [...]]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s a great little guideline for writing testable code: limit the number of loops in any function or method to 1 at each level of nesting.</p>
<p>Consider the following function with two &#8220;top level&#8221; loops:</p>
<pre class="brush: python; title: ; notranslate">
def function():
    for ():
        ....
        ....
        ....
    for ():
        ....
        ....
        ....
</pre>
<h2>Refactor 1</h2>
<p>The body of a loop is often a great candidate for a refactoring. Do this instead:</p>
<pre class="brush: python; title: ; notranslate">

def helper1():
    for():
        ...
        ...
        ...

def helper2():
    for():
        ...
        ...
        ...

def function():
    helper1()
    helper2()
</pre>
<p>Instead of sweating one nasty integration test for the function with two loops, you now have two unit tests (test_helper1, test_helper2) and two integration tests (test_function1, test_function2).</p>
<h2>Refactor 2</h2>
<pre class="brush: python; title: ; notranslate">
def function1():
    for ():
        ...
        ...
        ...

def function2():
    for ():
        ...
        ...
        ...

function1()
function2()
</pre>
<p>Depending on what function1 and function2 accomplish, they might be amenable to unit testing as well. </p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/coding/design-rule-of-thumb-1-loop-per-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The is pattern for queries</title>
		<link>http://daviddoolin.com/coding/the-is-pattern-for-queries/</link>
		<comments>http://daviddoolin.com/coding/the-is-pattern-for-queries/#comments</comments>
		<pubDate>Fri, 27 Jul 2012 01:42:20 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[literate programming]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=5695</guid>
		<description><![CDATA[One way to partition functionality within classes is to separate command (mutate) actions from query (inspect) actions. Query actions have a number of well-established naming conventions. Let&#8217;s examine the &#8220;is_whatever?&#8221; pattern. Consider a car, a spider and word (Ruby syntax): The convention is that any function or method prefixed with &#8220;is&#8221; queries for a boolean [...]]]></description>
				<content:encoded><![CDATA[<p>One way to partition functionality within classes is to <a href="http://daviddoolin.com/coding/naming-functions-and-methods/" title="Command methods and query methods">separate command (mutate) actions from query (inspect) actions</a>.</p>
<p>Query actions have a number of well-established naming conventions. Let&#8217;s examine the &#8220;is_whatever?&#8221; pattern.</p>
<p>Consider a car, a spider and word (Ruby syntax):</p>
<pre class="brush: ruby; title: ; notranslate">
car.is_vehicle?       # true
spider.is_insect?     # false, spiders are arachnids
word.is_abbreviation? # 4. WTF!?
</pre>
<p>The convention is that any function or method prefixed with &#8220;is&#8221; queries for a boolean value. Returning anything other than <code>true</code> or <code>false</code> will induce cognitive dissonance in the reader.</p>
<p>The reader might well be you, next year.</p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/coding/the-is-pattern-for-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Naming functions and methods</title>
		<link>http://daviddoolin.com/coding/naming-functions-and-methods/</link>
		<comments>http://daviddoolin.com/coding/naming-functions-and-methods/#comments</comments>
		<pubDate>Mon, 14 May 2012 18:13:52 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Best practice]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=405</guid>
		<description><![CDATA[Function and method naming is not terribly difficult if the following two guidelines are observed: Query functions return stuff. For example, new, create, get are all functions which ask for something in return. Command functions change state. For example, set, adjust, compute. Try very, very hard not to &#8220;mix and match&#8221;. Functions which both query [...]]]></description>
				<content:encoded><![CDATA[<p>Function and method naming is not terribly difficult if the following two guidelines are observed:</p>
<p>Query functions return stuff. For example, <code>new</code>, <code>create</code>, <code>get</code> are all functions which ask for something in return.</p>
<p>Command functions change state. For example, <code>set</code>, <code>adjust</code>, <code>compute</code>.</p>
<p>Try very, very hard not to &#8220;mix and match&#8221;. Functions which both query and command are really hard to test, and worse, they are much harder to understand.</p>
<p>Think of it this way: testing a query function means testing only that the returned result is correct. Testing a command function means testing only the state of the object as a result of the command. If you have a function which commands and queries, you may find your function has weird interactions. Basically, your test code has to test the return, the state, and every possible interaction.</p>
<p>Plus, it&#8217;s just semantically confusing otherwise.</p>
<p>Update 2012/05/19: Command and query are analogous to &#8220;inspect&#8221; and &#8220;mutate&#8221; in the c++ world. </p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/coding/naming-functions-and-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Good reason to learn Java, C/C++</title>
		<link>http://daviddoolin.com/coding/good-reason-to-learn-java-cc/</link>
		<comments>http://daviddoolin.com/coding/good-reason-to-learn-java-cc/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 19:07:51 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Feathers]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=375</guid>
		<description><![CDATA[C, C++ and Java may seem simply annoyances to programmers weened on scripting languages. But learning one or more of these languages is worthwhile, for many reasons. One reason is this: Vast amounts of software engineering literature provide examples using these languages. Currently, I&#8217;m reading &#8220;Working Effectively with Legacy Code&#8221; by Michael C. Feathers. All [...]]]></description>
				<content:encoded><![CDATA[<p>C, C++ and Java may seem simply annoyances to programmers weened on scripting languages. But learning one or more of these languages is worthwhile, for many reasons.</p>
<p>One reason is this: <em>Vast amounts of software engineering literature provide examples using these languages.</em></p>
<p>Currently, I&#8217;m reading &#8220;Working Effectively with Legacy Code&#8221; by Michael C. Feathers. </p>
<p>All the code in the book is (of course) C, C++ or Java. But the principles documented in the book are language independent.</p>
<p>The last example in the book, on extraction refactoring, is something I&#8217;ve been doing for years, and didn&#8217;t know there was a name for it. That&#8217;s pretty cool.</p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/coding/good-reason-to-learn-java-cc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning to test-first</title>
		<link>http://daviddoolin.com/coding/learning-to-test-first/</link>
		<comments>http://daviddoolin.com/coding/learning-to-test-first/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 01:13:12 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=379</guid>
		<description><![CDATA[If you didn&#8217;t learn it that way, test-first isn&#8217;t the easiest way to program. But it can be learned. Write the code you&#8217;re going to write anyway. Test your just-written code thoroughly. Keep your tests and throw away all your code. Now rewrite your code. It takes extra time, but only the first time. Given [...]]]></description>
				<content:encoded><![CDATA[<p>If you didn&#8217;t learn it that way, test-first isn&#8217;t the easiest way to program.</p>
<p>But it can be learned.</p>
<ol>
<li>Write the code you&#8217;re going to write anyway.</li>
<li>Test your just-written code thoroughly.</li>
<li>Keep your tests and throw away all your code.</li>
<li>Now rewrite your code.</li>
</ol>
<p>It takes extra time, but only the first time.</p>
<p>Given you&#8217;re writing test code anyway, test-first will pay you back the second or third time you write the code.</p>
<p>If you&#8217;re not writing test code, move along, nothing to see here.</p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/coding/learning-to-test-first/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing: clients will pay now or pay later</title>
		<link>http://daviddoolin.com/coding/testing-clients-will-pay-now-or-pay-later/</link>
		<comments>http://daviddoolin.com/coding/testing-clients-will-pay-now-or-pay-later/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 15:46:13 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Freelancing]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=336</guid>
		<description><![CDATA[A former freelancer sends a message to a programming email list, explaining his full time job doesn&#8217;t give him enough time to update his former client&#8217;s website. And it&#8217;s on an obsolete and soon-to-be-unsupported version of the web application framework (which framework is irrelevant). The main gotcha: he didn&#8217;t write any test code. Most likely, [...]]]></description>
				<content:encoded><![CDATA[<p>A former freelancer sends a message to a programming email list, explaining his full time job doesn&#8217;t give him enough time to update his former client&#8217;s website. And it&#8217;s on an obsolete and soon-to-be-unsupported version of the web application framework (which framework is irrelevant).</p>
<p>The main gotcha: he didn&#8217;t write any test code.</p>
<p>Most likely, the client was unable or unwilling to pay for the test code when the site was first created.</p>
<p>Most likely, the client will not be interested in paying for test code now.</p>
<p>The irony here is that had the developer originally written test code, he would have much more confidence updating the site.</p>
<p>The client pays regardless: either someone comes and cleans it up, or the client pays for a new web site. At this point, <em>not</em> writing test code increases developer time as the new developer reverse engineers the existing code. Might as well test.</p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/coding/testing-clients-will-pay-now-or-pay-later/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to finish a project</title>
		<link>http://daviddoolin.com/productivity/how-to-finish-a-project/</link>
		<comments>http://daviddoolin.com/productivity/how-to-finish-a-project/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 23:45:58 +0000</pubDate>
		<dc:creator>Dave Doolin</dc:creator>
				<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://daviddoolin.com/?p=369</guid>
		<description><![CDATA[Finishing a project is not hard. Finishing might be really boring, but it&#8217;s in no way difficult. Here&#8217;s how to finish those projects: Do all the work. Publish what you did, like write a blog post or something. Promote it everywhere sensible. I bet you have a project which wants only three or four hours [...]]]></description>
				<content:encoded><![CDATA[<p>Finishing a project is not hard.</p>
<p>Finishing might be really boring, but it&#8217;s in no way difficult.</p>
<p>Here&#8217;s how to finish those projects:</p>
<ol>
<li>Do all the work.</li>
<li>Publish what you did, like write a blog post or something.</li>
<li>Promote it everywhere sensible.</li>
</ol>
<p>I bet you have a project which wants only three or four hours to call done. Why not just do it?</p>
]]></content:encoded>
			<wfw:commentRss>http://daviddoolin.com/productivity/how-to-finish-a-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
