<?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>Endlessly Curious &#187; Programming</title>
	<atom:link href="http://www.endlesslycurious.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.endlesslycurious.com</link>
	<description>by Daniel Brown</description>
	<lastBuildDate>Thu, 03 Jun 2010 16:53:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Evils of Global State and Singletons</title>
		<link>http://www.endlesslycurious.com/2010/06/03/the-evils-of-global-state-and-singletons/</link>
		<comments>http://www.endlesslycurious.com/2010/06/03/the-evils-of-global-state-and-singletons/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 16:53:04 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1377</guid>
		<description><![CDATA[In this Google Clean Code talk, Miško Hevery presents the evils of global state, how this relates to Singletons, testing and what to do about it.

Questions starting at 31:20 are pretty interesting.
]]></description>
			<content:encoded><![CDATA[<p>In this Google Clean Code talk, Miško Hevery presents the evils of global state, how this relates to Singletons, testing and what to do about it.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/-FRm3VPhseI&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/-FRm3VPhseI&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Questions starting at 31:20 are pretty interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2010/06/03/the-evils-of-global-state-and-singletons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>But I can write that in&#8230;</title>
		<link>http://www.endlesslycurious.com/2010/05/28/but-i-can-write-that-in/</link>
		<comments>http://www.endlesslycurious.com/2010/05/28/but-i-can-write-that-in/#comments</comments>
		<pubDate>Fri, 28 May 2010 09:00:18 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Reuse]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1335</guid>
		<description><![CDATA[I have lost count of the times I have heard a developer exclaim &#8216;but I could write that in X days&#8217; when discussing adopting an existing piece of technology developed somewhere else.   This is usually given as a reason not to adopt an existing external solution but to instead write a custom solution with [...]]]></description>
			<content:encoded><![CDATA[<p>I have lost count of the times I have heard a developer exclaim &#8216;but I could write that in X days&#8217; when discussing adopting an existing piece of technology developed somewhere else.   This is usually given as a reason not to adopt an existing external solution but to instead write a custom solution with some minor improvement or feature.  There are two big flaws in this line of reasoning.</p>
<p>The first is the assumption that you could create something with the same quality level as the existing solution in the stated number of days; most likely you will be lucky to have a functional prototype with minimal functionality.  It is highly unlikely that you will have produced something that is as well tested, optimised and documented as the existing solution.</p>
<p>Secondly, as developers writing software which we intend to sell to users to pay the bills, we should be focused on the core features that define our product.  It is these core features we should be pouring our energy and time into designing, building and testing.  Developing alternatives to existing technology that is not in our core feature set is a waste of valuable time and energy and will not differentiate our product from that of our competitors.</p>
<p>We should instead be looking to leverage as many established technologies or components as possible when developing new systems as this lets us spend most of our time where it matters most on our core differentiating features.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2010/05/28/but-i-can-write-that-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing MatPlotLib on Snow Leopard with MacPorts</title>
		<link>http://www.endlesslycurious.com/2009/12/08/installing-matplotlib-on-snow-leopard-with-macports/</link>
		<comments>http://www.endlesslycurious.com/2009/12/08/installing-matplotlib-on-snow-leopard-with-macports/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 09:00:13 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1357</guid>
		<description><![CDATA[I have been trying to install the excellent MatPlotLib graphing module for the Python programming language on my iMac for a while now. Unlike most python module installations I&#8217;ve done the excellent python SetupTools (a.k.a easy_install) has not been up to the task.  So I ended up using MacPorts (version 1.8.1) to get MatPlotLib (version 0.99.1.1) installed on Snow [...]]]></description>
			<content:encoded><![CDATA[<p>I have been trying to install the excellent <a href="http://matplotlib.sourceforge.net/index.html">MatPlotLib</a> graphing module for the <a href="http://www.python.org/">Python</a> programming language on my iMac for a while now. Unlike most python module installations I&#8217;ve done the excellent python <a href="http://pypi.python.org/pypi/setuptools">SetupTools</a> (a.k.a easy_install) has not been up to the task.  So I ended up using <a href="http://www.macports.org/">MacPorts</a> (version 1.8.1) to get MatPlotLib (version 0.99.1.1) installed on <a title="Apple.com" href="http://www.apple.com/macosx/">Snow Leopard</a> (OS X 10.6.2) with X-Code (3.2.1 &#8211; 1613).</p>
<p>So here is a brief description of how to do it:</p>
<ol>
<li>Install the <a href="http://developer.apple.com/tools/xcode/">X-Code</a> developer tools (for GCC, make and other build tools) from your Snow Leopard installation DvD.</li>
<li>Install the <a href="http://en.wikipedia.org/wiki/X_Window_System">X11</a> Window System from your Snow Leopard installation DvD.</li>
<li>Run &#8216;<a href="http://www.apple.com/softwareupdate/">Software Update</a>&#8216; from the apple menu on your Mac to get the latest X-Code updates.</li>
<li>Download the latest MacPorts installer (.dmg file extension) for Snow Leopard from here: <a title="Mac Ports" href="http://distfiles.macports.org/MacPorts/">http://distfiles.macports.org/MacPorts/</a>.</li>
<li>Mount the installer image file (.dmg) and run the contained MacPorts installer (.pkg).</li>
<li>Once installation is complete open a terminal window from Applications-&gt;Utilities-&gt;Terminal.</li>
<li>Type &#8216;<span style="color: #008000;">port</span>&#8216; at the terminal then press enter to run MacPorts.  You should see output like the following if it installed correctly:<br />
<span style="color: #808000;">MacPorts 1.8.1<br />
Entering interactive mode&#8230; (&#8220;help&#8221; for help, &#8220;quit&#8221; to quit)</span><br />
Then type &#8216;<span style="color: #008000;">quit</span>&#8216; then press enter to exit port&#8217;s interactive mode.</li>
<li>Type &#8216;<span style="color: #008000;">sudo port selfupdate</span>&#8216; and press enter to update MacPorts to the latest version.  You will be asked to enter the administrators password before continuing.  Depending on how new the version you downloaded is, MacPorts may do some upgrading.</li>
<li>Once the update is finished type &#8216;<span style="color: #008000;">sudo port install py26-matplotlib</span>&#8216; and press enter.  This will attempt to install the latest version of matplotlib for Python version 2.6.*.   You may be asked to enter the administrators password before continuing.  MacPorts will now download, configure, build and stage the dependencies needed to build the latest matplotlib for Python 2.6.  This took at least thirty minutes on my iMac and involved lots and lots of scrolling text output from the build process.</li>
<li>Next we need to switch our environment to use version 2.6.* of Python that MacPorts just built and installed with matplotlib.  To do this run the following two commands, note you may be asked to enter the administrators password before continuing:
<ol>
<li>&#8216;<span style="color: #008000;">sudo port install python_select</span>&#8216; and hit enter.</li>
<li>&#8216;<span style="color: #008000;">sudo python_select python26</span>&#8216; and hit enter.</li>
</ol>
</li>
<li>To test this all worked type the following: &#8216;python -V&#8217; and hit enter.  You should see output like &#8216;<span style="color: #808000;">Python 2.6.4</span>&#8216; which should match the version of python MacPorts built and installed.</li>
<li>Finally to test if matplotlib was installed correctly do the following:
<ol>
<li>Type &#8216;<span style="color: #008000;">python</span>&#8216; and hit enter to enter the python interactive shell.</li>
<li>Type &#8216;<span style="color: #008000;">import matplotlib</span>&#8216; and hit enter, this will import the matplotlib module.  There should be no output if this works.</li>
<li>Type &#8216;<span style="color: #008000;">print matplotlib.__version__</span>&#8216; and hit enter. This will print the version of matplotlib that is installed, you should see output like &#8216;<span style="color: #808000;">0.99.1.1</span>&#8216;.</li>
<li>Type &#8216;<span style="color: #008000;">exit()</span>&#8216; to quit the python interactive shell.</li>
</ol>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2009/12/08/installing-matplotlib-on-snow-leopard-with-macports/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using SQLite in Python</title>
		<link>http://www.endlesslycurious.com/2009/06/24/using-sqlite-in-python/</link>
		<comments>http://www.endlesslycurious.com/2009/06/24/using-sqlite-in-python/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 09:00:14 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1318</guid>
		<description><![CDATA[Python has had support for SQLite built-in since version 2.5.
This is a very convenient pairing as SQLite is an excellent lightweight SQL implementation that I find very useful for a variety of tasks e.g. data mining.  Or any task involving manipulating complex data sets where I&#8217;d otherwise end up resorting to using a full blown [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Python.org" href="http://python.org/">Python</a> has had <a title="PyDocs" href="http://docs.python.org/library/sqlite3.html">support</a> for <a title="SQLite.org" href="http://sqlite.org/">SQLite</a> built-in since version 2.5.</p>
<p>This is a very convenient pairing as SQLite is an excellent lightweight SQL implementation that I find very useful for a variety of tasks e.g. data mining.  Or any task involving manipulating complex data sets where I&#8217;d otherwise end up resorting to using a full blown SQL server like <a href="http://www.mysql.com/">MySQL</a>.</p>
<p>Here is a simple example of using SQLite in Python using it&#8217;s built-in sqlite3 module:</p>
<pre class="brush: python;">
import sqlite3

# craete a connection
con = sqlite3.connect('test.db')

# create a cursor
cur = con.cursor()

# create a test table
cur.execute( &quot;CREATE TABLE testTable (myKey INT, myValue INT)&quot; )

# insert some data
for i in range(0,10):
 cur.execute( &quot;INSERT INTO testTable VALUES ( %d, %d )&quot;%(i,i*i) )

# select the data
for row in cur.execute( &quot;SELECT * FROM testTable&quot; ):
 print row

# destroy (drop) our test table
cur.execute( &quot;DROP TABLE testTable&quot; )

# close the connection
con.close()
</pre>
<p>As you can see Python makes handling SQLite (a C language library) much easier, less error prone, and the resulting code much more compact than SQLite&#8217;s native C.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2009/06/24/using-sqlite-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fail to succeed!</title>
		<link>http://www.endlesslycurious.com/2009/04/01/fail-to-succeed/</link>
		<comments>http://www.endlesslycurious.com/2009/04/01/fail-to-succeed/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 09:00:41 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Failure]]></category>
		<category><![CDATA[Knowledge]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1229</guid>
		<description><![CDATA[The more experienced I become the more aware I become of what I don&#8217;t know and the more I come to terms with the fact that I make mistakes.
The awareness of what I don&#8217;t know helps keep me humble, humility makes working as part of a team easier:  as there is no pressure to have [...]]]></description>
			<content:encoded><![CDATA[<p>The more experienced I become the more aware I become of what I don&#8217;t know and the more I come to terms with the fact that I make mistakes.</p>
<p>The awareness of what I don&#8217;t know helps keep me humble, humility makes working as part of a team easier:  as there is no pressure to have to know everything or not make mistakes.  In fact I tend to expect to make mistakes more now than when I first started programming.  Perhaps it is the years I have spent shipping games that finally proved to me that I too write software that contains bugs (the horror!).</p>
<p>I remember a professor at university telling me that the main difference between a professor and a first year student working on a programming task is that the student will start working immediately and also start making mistakes immediately, the professor will think for a while then start work and start making mistakes as well.  I have found this observation to have a surprising amount of truth in it,:whether it is at university, work or even sports.</p>
<p>Mistakes are healthy: without mistakes we would have not reason to every really think about what we are doing e.g. why didn&#8217;t that work?  By continually pushing (or stretching) ourselves to failure we discover our boundaries, once we know where are our boundaries are we can then start to work on pushing them further.  However if we always play it safe and never push ourselves (which can be scary) we will never discover our boundaries which makes improvement much harder and also makes approaching those boundaries harder due to fear (typically of loss of control).</p>
<p>An excellent example of this is people learning to ice skate: young children will tend to fling themselves around the rink with wild abandon falling all over the place (as failure is expected but irrelevant due to lack of social stigma), yet adult beginners typically skate in a much more conservative fashion taking less risks (as there is social stigma against falling as an adult: falling is seen as failure).  Interestingly when observing ice hockey players, it is noticeable that those with the best skating technique are typically falling more than the other the non-beginner players on the ice, as they do not fear falling.</p>
<p>As most of us are not engaged in high risk activities on a daily basis we can easily begin to revise how we think about failure and to learn to embrace it as a powerful tool for self improvement.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2009/04/01/fail-to-succeed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beware the Golden Hammer!</title>
		<link>http://www.endlesslycurious.com/2009/03/19/beware-the-golden-hammer/</link>
		<comments>http://www.endlesslycurious.com/2009/03/19/beware-the-golden-hammer/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 09:00:48 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[anti-pattern]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1180</guid>
		<description><![CDATA[The &#8216;Golden Hammer&#8216; is a very common anti-pattern, which can be best summed up by the phrase &#8220;if all you have is a hammer, everything looks like a nail&#8220;.  This anti-pattern occurs when the perpetrator has typically learned a particularly powerful technique or design (the hammer),  which they then go on to apply blindly to [...]]]></description>
			<content:encoded><![CDATA[<p>The &#8216;<a title="Wikipedia" href="http://en.wikipedia.org/wiki/Golden_hammer">Golden Hammer</a>&#8216; is a very common <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns">anti-pattern</a>, which can be best summed up by the phrase &#8220;<em>if all you have is a hammer, everything looks like a nail</em>&#8220;.  This anti-pattern occurs when the perpetrator has typically learned a particularly powerful technique or design (the hammer),  which they then go on to apply blindly to all problems (the nails) they encounter whether it is a suitable solution or not.</p>
<p>This can be especially evident amongst beginner programmers, who are learning new techniques almost constantly, but it only seems to become a dangerous anti-pattern if the individual becomes overly fixated on a particular technique.</p>
<p>Interestingly this anti-pattern can apply to more than just individuals, in my experience it can also apply to teams or even entire organisations.  One of the ways I have seen this manifest at a team or organisational level is with attempts to solve social problems with technology solutions.  This trait seems to be especially strong in software development organisations: perhaps because technology is their usual solution to problems.</p>
<p>Such social issues faced by development teams and organisations can include things like not breaking the build, lack of communication or lack of testing.  These problems really are not technology problems, they are social (people) problems, yet time and again I have witnessed technology solutions to these problems.  For example, more elaborate and sophisticated check-in systems being introduced in response to constantly broken builds, where a much simpler social solution such as peer pressure to not break the build would be much more effective.</p>
<p>Avoiding the Golden Hammer when programming is achievable with some self awarness and honesty: are you using your current technique for the right reasons?  However, identifying and interveening when a team or organisation is about to use the Golden Hammer is much more challenging as it can involve going against the solution favoured by the majority along with the polical implications that brings&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2009/03/19/beware-the-golden-hammer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No bad programming languages</title>
		<link>http://www.endlesslycurious.com/2009/03/03/no-bad-programming-languages/</link>
		<comments>http://www.endlesslycurious.com/2009/03/03/no-bad-programming-languages/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 09:00:57 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1143</guid>
		<description><![CDATA[I encountered some truly hideous source code today in a programming language in which I wouldn&#8217;t have thought hideous obscure code was possible:  C#.  It was my first real experience of abject horror when looking at the source code of a C# application. Obviously with hindsight it would seem that you can write hugely, dense, [...]]]></description>
			<content:encoded><![CDATA[<p>I encountered some truly hideous source code today in a programming language in which I wouldn&#8217;t have thought hideous obscure code was possible:  C#.  It was my first real experience of abject horror when looking at the source code of a <a title="Wikipedia" href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)">C#</a> application. Obviously with hindsight it would seem that you can write hugely, dense, brittle and hard to understand programs in any programming language.  And yet I would not expect a C# source code to be this obtuse or brittle but I would expect a <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Perl">Perl</a> script to be dense and hard to read.</p>
<p>It is not that I have anything against Perl as a programming language: it is a fine language.  I find that Perl&#8217;s motto of `There&#8217;s more than one way to do it.&#8217; means that it is a programming language with (you guessed it) more than one way to implement most operations.  This flexibility is a double edged sword: it allows a lot of creativity in program implementation, yet it also means that a dozen Perl coders will produce a dozen radically different scripts for the same problem.  This makes Perl quite hard on beginners or infrequent maintainers of Perl scripts: as to understand any given Perl script requires an understanding of much more of the Perl programming language than it would for most comparable programming languages.</p>
<p>I digress.</p>
<p>I&#8217;ve known for years that it is possible to write awful obscure code in low level languages like C and C++ but it really hadn&#8217;t occurred to me that a high level language like C# could be abused to the same degree.  Thinking about this some more, it is not the fault of the programming language itself but of the programmer that is using it.</p>
<p>So, brittle obtuse code is the result of a bad programmer not a bad programming language: well except maybe <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Brainfuck">Brain Fuck</a> (but thats kinda the point).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2009/03/03/no-bad-programming-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You Aren&#8217;t Gonna Need It!</title>
		<link>http://www.endlesslycurious.com/2009/02/16/you-arent-gonna-need-it/</link>
		<comments>http://www.endlesslycurious.com/2009/02/16/you-arent-gonna-need-it/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 09:00:28 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[YAGNI]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1104</guid>
		<description><![CDATA[A very common trap to fall into while implementing a new system or feature is to add functionality to &#8216;future proof&#8217; your code for a use case that you imagine in may be required in the future.  The future for the purposes of this post is any time that is not in your current development [...]]]></description>
			<content:encoded><![CDATA[<p>A very common trap to fall into while implementing a new system or feature is to add functionality to &#8216;future proof&#8217; your code for a use case that you imagine in may be required in the future.  The future for the purposes of this post is any time that is not in your current development iteration.</p>
<p>This may seem harmless but consider that the future use cases you are imagining are not something you fully understand yet: as most of us will admit we are pretty bad at anticipating the future.  So how can we hope to implement future functionality successfully?  The most likely outcome is that whatever you implement now not be sufficient when you actually try to use it in the future.  This will mean more time will have to be invested in the future to <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Code_refactoring">refactor</a> or replace the functionality with what is actually required.</p>
<p>Unless you also plan to implement a full set of tests for this new functionality then you are adding extra code to your program that will not be correct and will not stay correct.  This can also lead to really weird run time behavior if the flow of program execution goes into your new &#8216;future proof&#8217; functionality unexpectedly: which can be <em>very</em> hard to debug.  Adding functionality for future use without corresponding tests also means that as the rest of your program evolves the future functionality does not evolve with it, this means by the time you actually try to use it that it is most likely hopelessly out of sync with the rest of the code base.</p>
<p>The future functionality is also expanding the size of the source code of your program which leads to unnecessary <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Code_bloat">code bloat</a>.  In some compiled languages (e.g. C++) code bloat will lead to increased memory usage and decreased program performance which is highly undesirable.</p>
<p>Another thing to consider from a business stand point is that you are spending time and money implementing future functionality when you are not being paid for it.  This is a strong indication to me that implementing future functionality makes little business sense.  As it means spending money now paying developers to implement functionality that you can&#8217;t sell right now.</p>
<p>There is a handy acronym for this: it is <a title="Wikipedia" href="http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It">YAGNI</a> which stands for &#8216;You Aren&#8217;t Gonna Need It&#8217;.  The essence of this concept is to only implement the functionality you need right <em>now</em> and to implement in as simple and robust a fashion as possible.  As simple robust code (preferable with acompaning unit tests) is code that can be easily refactored in the future to meet future needs and that is cost effcient!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2009/02/16/you-arent-gonna-need-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exceptions: Don&#8217;t bite off more than you can chew!</title>
		<link>http://www.endlesslycurious.com/2009/01/08/exceptions-dont-bite-off-more-than-you-can-chew/</link>
		<comments>http://www.endlesslycurious.com/2009/01/08/exceptions-dont-bite-off-more-than-you-can-chew/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 09:00:04 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Exceptions]]></category>
		<category><![CDATA[gotcha]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=871</guid>
		<description><![CDATA[Many modern programming languages feature some form of exception handling facility, and although I am going to be talking particularly about  C# in this post, it can probably be applied to any language that has exception handling.  Exception handling is very useful for the graceful handling of unexpected errors (exceptions) during program execution, however [...]]]></description>
			<content:encoded><![CDATA[<p>Many modern programming languages feature some form of <a href="http://en.wikipedia.org/wiki/Exception_handling">exception handling</a> facility, and although I am going to be talking particularly about  <a href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)">C#</a> in this post, it can probably be applied to any language that has exception handling.  Exception handling is very useful for the graceful handling of unexpected errors (exceptions) during program execution, however there are a few gotchas to be aware of when using exception handling.</p>
<p>Possibly one of the most important practices in the effective use of exceptions is to only catch the exceptions you are expecting and that you can handle safely, however a very common mistake when starting to use exceptions is to catch (and possibly suppress) every exception. For example:</p>
<pre>
<pre class="brush: csharp;">try
{
// some code that throws exceptions occasionally
}catch{}</pre>
</pre>
<p>In the above example the programmer has discovered that their initial code is occasionally throwing exceptions, so they have enclosed the offending block of code in a try/catch block.  The use of a try/catch block means that any exceptions that occur inside the try clause are caught by the catch clause, this prevents the program from crashing due to unhanded exceptions.  However, the use of an empty catch clause means that <em>any</em> exception that is thrown will be caught by the catch clause.  The drawback to this is that the catch clause is empty, which means that every exception caught effectively disappears, which makes debugging and diagnosing abnormal program behavior incredibly hard, as that empty catch clause is effectively an exception black hole destroying any evidence.  This form of &#8216;exception handling&#8217; is worse in my opinion than no exception handling: though it may prevent the program crashing due to unhandled exceptions it makes debugging the program exceptionally hard.  The following snippet is an improvement:</p>
<pre>
<pre class="brush: csharp;">try
{
// some code that throws exceptions occasionally
}
catch( Exception e )
{
// some exception handling
}</pre>
</pre>
<p>The above snippet is a distinct improvement on the previous snippet as the catch clause now catches exceptions and attempts to perform some form of exception recovery or logging. This is a lot better as at least some form of corrective action is taking place.  Yet there is still a drawback: the catch clause is still catching <em>every</em> exception that is thrown by the try block. This means that even the abnormal exception types the programmer does not expect are being caught.  The following is a better snippet:</p>
<pre>
<pre class="brush: csharp;">try
{
// some code that throws exceptions occasionally
}
catch( System.ArgumentException e )
{
// some specific exception handling
}</pre>
</pre>
<p>In this example the programmer is now only catching the exceptions they expect their code to throw, which means that unexpected and abnormal exceptions are not caught. This is an improvement, as these unexpected exceptions will now filter up the call stack to more appropriate exception handlers and eventually to the try/catch clause in the main function of the application.  This means that when something truly rare and weird happens, e.g. an underlying system breaks causing an unexpected exception, that the truly exceptional exception is not caught by the original try/catch block but filters up to higher level exception handlers which hopefully alert the user (or at least the investigating programmer) that a truly exceptional event has occurred.</p>
<pre>
<pre class="brush: csharp;">try
{
// some code that throws exceptions occasionally
}
catch( System.ArgumentException e )
{
// some specific exception handling
}
catch( Exception e )
{
// generic exception handling
}</pre>
</pre>
<p>In this last example specific exceptions are caught by the first catch clause which catches only the exceptions the programmer is expecting and then a second catch clause catches all the other exceptions the programmer did not expect.  This form of exception handling is good if there is no general exception handler further up the call stack to catch the unexpected exceptions e.g. in a library.  In summary exception handling is a very useful tool but you need todevelop the habit of catching exceptions responsibly and to not catch exceptions you don&#8217;t intend to handle.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2009/01/08/exceptions-dont-bite-off-more-than-you-can-chew/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fail fast, fail cheap!</title>
		<link>http://www.endlesslycurious.com/2008/11/27/fail-fast-fail-cheap/</link>
		<comments>http://www.endlesslycurious.com/2008/11/27/fail-fast-fail-cheap/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 09:00:18 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[productivity]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=852</guid>
		<description><![CDATA[I was explaining this to some junior programmers the other day and it&#8217;s worth repeating.  Failure is fine in software engineering, in fact it is expected: I get nervous if something works first time these days as I know my limits and expect to make mistakes.  However I think that new programmers don&#8217;t always realise [...]]]></description>
			<content:encoded><![CDATA[<p>I was explaining this to some junior programmers the other day and it&#8217;s worth repeating.  Failure is fine in software engineering, in fact it is <em>expected</em>: I get nervous if something works first time these days as I know my limits and expect to make mistakes.  However I think that new programmers don&#8217;t always realise that failure is acceptable and in some cases failure is <em>preferred</em>, this is especially true during research and development tasks.  Consider the following diagram representing three programmers A, B and C working on a task over a period of time, each arrow represents one attempt at a solution.</p>
<p><img class="aligncenter size-full wp-image-853" title="Fail Fast" src="http://www.endlesslycurious.com/wp-content/uploads/2008/11/failfast.jpg" alt="" width="480" height="176" /></p>
<p>Assume the task that has been set is complex and contains some degree of uncertainty which means that the first few attempts will probably fail.  Which programmer would you want working on the task?  If the task is actually impossible then programmer A will be the cheapest from a business standpoint as they fail earliest followed by programmer B and finally programmer C.  Also, programmer A will have five attempts at a solution compared to programmer B&#8217;s two and a half attempts and programmer C&#8217;s single attempt.  As iteration leads to improved quality (<a href="http://www.codinghorror.com/blog/archives/000788.html">Boyd&#8217;s Law</a>) this means that programmer A is also likely to hit on a more superior solution than programmer B or programmer C in the same time period.</p>
<p>The interesting thing here is that in my experience new programmers tend to work like programmer C: they will attempt a single solution working diligently to overcome any hurdles they encounter, no matter how severe the hurdle.  This sounds harmless but remember that few things are impossible in programming, so the more a programmer hammers away at a problem the more likely they are to fudge a solution and that solution (in my experience) is not often of a high quality.  The counter point to this is that more productive programmers will rapidly discard attempts early in each attempt when it becomes clear that the solution though possible is not actually <em>desirable</em> e.g. the dog is hungry and solutions include: A) feed the dog B) kill the dog.</p>
<p>This can also be observed by monitoring how long a programmer will remain stuck for before asking for assistance.  The most productive programmers will get help within minutes of becoming completly stuck.  However the least productive (and often least experienced) programmers will often struggle with the problem for days before actually asking for assistance and this delay is expensive in terms of money, deadlines and product quality.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2008/11/27/fail-fast-fail-cheap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
