<?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>Digital Dim Sum &#187; coding</title>
	<atom:link href="http://www.digitaldimsum.co.uk/category/computing/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digitaldimsum.co.uk</link>
	<description>Bite sized info snacks for the digital generation</description>
	<lastBuildDate>Tue, 23 Jun 2009 16:58:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Simple code is music to my ears</title>
		<link>http://www.digitaldimsum.co.uk/2008/08/12/simple-code-is-music-to-my-ears/</link>
		<comments>http://www.digitaldimsum.co.uk/2008/08/12/simple-code-is-music-to-my-ears/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 13:35:00 +0000</pubDate>
		<dc:creator>jonny</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[computing]]></category>

		<guid isPermaLink="false">http://www.digitaldimsum.co.uk/?p=45</guid>
		<description><![CDATA[<p>Have you ever opened up a file of source code and flinched at the complexity that comes screaming out at you from the screen? Well I&#8217;m imagining an IDE plugin that could do the screaming for you.</p>
<p>There are many <a href="http://www.panopticode.org/">measures of code</a> that are objective and metrics driven, but there are others that are more subjective and taste based. I can&#8217;t tell you from a quick glance how many afferent couplings there are in a given piece of code, but I do have an almost immediate sense of how elegant the code is. In my mind elegance is all about solving complex problems with simple solutions. That&#8217;s the art rather than the science of computer programming.</p>
<p><!--more--></p>
<p>When I read some code and get that gut feeling that the solution isn&#8217;t elegant, one of the first pointers is often how long each method or function is and how deeply indented they get. If you open a class and it just contains a handful of methods that are short (no more than 2 to 4 lines in each) and reasonably named, I breath a natural sigh of relief and know that the class is going to be pretty easy to understand. If on the other hand, there&#8217;s some crazy-long Dostoevskian beast of a method that I can&#8217;t fully see without scrolling up and down, then I start quaking like an intellectual weakling knowing that I&#8217;m going to endure much pain trying to grok what was in that coding genius&#8217; mind when they wrote it. Then once I&#8217;ve worked out what they were <em>trying</em> to achieve I&#8217;ll have to go and figure out what they <em>actually</em> achieved &#8230; in long complicated methods the implementation often diverges from the intent!</p>
<p>Much of this complexity is immediately evident in how the code is nested and indented. Every indentation is the site of some kind of logical fork in the possible pathways through that method. Put in other terms there is a close correlation between the <a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity">cyclomatic complexity (CCN)</a> of a method and the amount of nesting and indentation. Or explaining this classic metric for complexity another way: each indentation is an invitation to extract a method into a beautiful, small, testable, readable and well-encapsulated unit.</p>
<p>When you&#8217;ve spent time living in a codebase where <a href="http://www.thoughtworks.com/">people</a> vigorously accept these invitations to <a href="http://www.extremeprogramming.org/rules/refactor.html">refactor</a> that are offered up by <a href="http://en.wikipedia.org/wiki/Whitespace_(programming_language)">our friend white-space</a> then you tend to have a <a href="http://www-306.ibm.com/software/lotus/">gut response of pain, horror and loathing</a> when you see a heavily indented chunk of code.</p>
<p>The differences between these two styles of coding is clearly visible in the profile of the first non-whitespace characters on each line. If you look at the code and blur your eyes a bit this profile can look rather like the little LEDs on a graphic equalizer. The profile of indentation within a given source file composes a revealing signature that can be interpreted as a sound wave. Imagine hooking up a music player that could read these patterns. The heavily refactored codebase would purr gently at you with soothing sussurations, while those deeply nested and psychotomatically complex methods would scream at you like a shrill and brain-scrambling siren on a police car.</p>
<p>So step up please you gurus of mashing up <a href="http://www.eclipseplugincentral.com/">Eclipse plugins</a> with Garageband and create me a little plugin that will <a href="http://www.youtube.com/watch?v=65I0HNvTDH4">sing a song of source code</a> whenever I open a file. But before you do that, maybe I should <a href="http://www.killerclips.com/clip.php?id=33&amp;qid=122">reach for the earmuffs</a>.</p>
]]></description>
		<wfw:commentRss>http://www.digitaldimsum.co.uk/2008/08/12/simple-code-is-music-to-my-ears/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Programming considered harmful</title>
		<link>http://www.digitaldimsum.co.uk/2008/02/10/programming-considered-harmful/</link>
		<comments>http://www.digitaldimsum.co.uk/2008/02/10/programming-considered-harmful/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 22:50:57 +0000</pubDate>
		<dc:creator>jonny</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://www.digitaldimsum.co.uk/2008/02/10/programming-considered-harmful/</guid>
		<description><![CDATA[<p>Discussions have been flying around the <a href="http://www.thoughtworks.com" title="ThoughtWorks">ThoughtWorks</a> communication channels on balancing the risk of dynamic languages against the pain of static languages. This got me thinking about the similarities between what makes teams work well and what makes for good code and object interactions.</p>
<p><!--more-->The mailing lists at <a href="http://www.thoughtworks.com" title="ThoughtWorks">ThoughtWorks</a> have been running hot since Jay Fields <a href="http://blog.jayfields.com/2008/02/static-typing-considered-harmful.html" title="Jay Fields: Static typing considered harmful">stoked the flames of the dynamic versus static language schism</a>. His basic point is summarized in the opening line:</p>
<blockquote><p><em>&#8220;Given a good test suite the return on investment simply does not justify the use of static typing&#8221;</em></p></blockquote>
<p>Basically he&#8217;s saying that statically typed languages have benefits, but there is an associated cost &#8211; anyone who&#8217;s seen object definitions disappear off the screen with <a href="http://weblogs.java.net/blog/arnold/archive/2005/06/generics_consid_1.html" title="Generics considered harmful">Java 5 generics</a> will understand this. The benefits definitely exist &#8211; modern IDEs (auto-complete, refactoring, etc), compiler optimizations, basic verification and clarity in communicating integration requirements &#8211; but there is also a cost incurred in terms of complexity and inflexibility. <a href="http://memeagora.blogspot.com/" title="Neal Ford">Neal Ford</a> has started calling this the &#8220;static type tax&#8221;. Jay&#8217;s solution is, rather than relying on static typing for partial protection, rely on tests for full protection.</p>
<h3>Work to rule</h3>
<p>This pain or tax associated with static types reminds me of the parody of union rules gone bad &#8211; &#8220;I can&#8217;t plug that in, I&#8217;m a carpenter, you need an electrician&#8221;. These rules start out having important uses (protecting workers against abuse and ensuring quality results), but can end up just causing pain and making the jobs they&#8217;re trying  to protect less secure by making the industry less responsive. There is an obvious correlation with the trade-offs between dynamic and statically typed languages: it&#8217;s nice to know from an integration and tooling perspective <em>exactly what type of object</em> a method requires; it&#8217;s also nice just to be able to give that same method  <em>any object that can respond to the messages</em> it will be sent.</p>
<p>In strong and statically typed languages, like Java, the method signature is a shorthand explicitly stating what type of object is required for the method to work. In a dynamic or weakly typed language, like Ruby or JavaScript, you have more flexibility about what you can pass into the method, but less visibility into whether it will work or not &#8211; you have to check (visually or through tests) that the object you pass in can respond sensibly to the instructions it&#8217;s given.</p>
<p>One of the pains of the statically typed method signature  is that various different requirements tend to get bundled up together. A method may well require a parameter to be of type (implement interface) X, where interface X defines 10 methods, even though the method will only call one of those declared methods. Ideally you would define a new interface for each combination of methods you want to call so you can keep the contract as simple to fulfill as possible, but this in itself would be a burden as the amount of interfaces would explode.</p>
<h3>Risk assessments</h3>
<p>The arrival of complexity and restriction in the name of preventing accidents (passing an object that can&#8217;t react to the messages sent to it) reminds me of how school trips have become harder and harder to organize because of the <a href="http://www.telegraph.co.uk/news/main.jhtml?xml=/news/2008/02/05/ncamping105.xml" title="Risk assessments on school trips">ever more stringent &#8220;risk assessments&#8221; required</a>:</p>
<blockquote><p><em>&#8220;Endless lengthy risk assessments and fears of being blamed if anything goes wrong have put teachers off taking children away on trips and led to youngsters being cooped in classrooms instead.&#8221;</em></p></blockquote>
<p>I remember loving some fairly wild school or youth club trips as a kid. Rock scrambling was one of my favorites, which involved climbing, jumping, swimming, hopping and whooping round sections of coastline like the beautiful <a href="http://news.bbc.co.uk/2/shared/spl/hi/pop_ups/05/sci_nat_britain0s_3d_geology/html/4.stm" title="Lulworth Cove">Lulworth Cove</a>. Sure there were risks involved, but learning to handle yourself in those risky situations lead to really important lessons and personal growth. Risk breeds responsibility.</p>
<p>I have similar feelings about using dynamic languages &#8211; with great power comes great responsibility. Programming itself is inherently risky (when was your last zero-defect release?) so programmers have to make decisions about how to act responsibly. One way is to impose risk assessment forms on every method call through static typing; another option is to force objects to <a href="http://docs.codehaus.org/display/PICO/Good+Citizen" title="Good citizens">act responsibly and be good citizens</a>. This is the route that interests me more. Testing definitely plays an important role in acting responsibly, but it&#8217;s not the end of the story.</p>
<h3>Team collaboration : object collaboration</h3>
<p>Coming back to the analogy of objects as workers on a job, rather than using strict role definitions in an attempt to control quality, I would much prefer to use the example of self-organizing Agile teams. On an Agile development team there is an expectation that people can work in a cross-functional manner with common ownership of the code-base. This means that team members should be interchangeable and comfortable in a variety of areas &#8211; just like in dynamic languages there is no type checking before picking up tasks (&#8220;sorry I only do JavaScript / Java / SQL&#8221;). This leads to highly flexible and productive teams, but there are a few techniques needed to make it work. Some of these techniques are conceptually transferable to working responsibly with dynamic languages:</p>
<ul>
<li>communication</li>
<li>simplicity</li>
<li>responsibility</li>
</ul>
<p>Explicit and clear communication is the biggest of these &#8211; the others can be derived from this principle. The importance of communication in teams is fairly obvious, but it can also be important at the code level in areas like explicit tests, clearly named methods and transparent intentionality.</p>
<p>Simplicity aids communication and also lowers risk. The simpler the routine is, the easier it is to understand, the easier it is to see what is required of collaborating objects and the less likely it is that bugs will creep in.</p>
<p>Responsibility underpins this all. In teams it means talk to people if you&#8217;re not sure, or tell people if you&#8217;re going to do something strange; in objects it means testing your interactions, handling errors appropriately and checking compatibility where necessary.</p>
]]></description>
		<wfw:commentRss>http://www.digitaldimsum.co.uk/2008/02/10/programming-considered-harmful/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ant Fu</title>
		<link>http://www.digitaldimsum.co.uk/2007/10/19/ant-fu/</link>
		<comments>http://www.digitaldimsum.co.uk/2007/10/19/ant-fu/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 15:03:06 +0000</pubDate>
		<dc:creator>jonny</dc:creator>
				<category><![CDATA[build]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://www.digitaldimsum.co.uk/2007/10/19/ant-fu/</guid>
		<description><![CDATA[<p>We&#8217;ve had some discussions recently about best practices when creating <a href="http://ant.apache.org/" target="_blank">Ant</a> scripts, so I thought I&#8217;d write up a few of my favourites.</p>
<h3>Managing Ant target dependencies</h3>
<p>&#8220;depends&#8221; are great, until your build file gets bigger than a couple of screenfuls. You can end up with a crazy spaghetti monster of dependencies very quickly. On a few builds I&#8217;ve worked on we&#8217;ve had a basic rule:</p>
<blockquote dir="ltr" style="margin-right: 0px"><p><em>Targets can either have depends or a body, but not both.</em></p></blockquote>
<p dir="ltr"><!--more-->So you end up having two types of targets:</p>
<ul dir="ltr">
<li>&#8220;<strong>functional targets</strong>&#8221; that actually do the work, carrying   out small individual tasks</li>
<li>&#8220;<strong>flow targets</strong>&#8221; that tie the functional targets   together</li>
</ul>
<blockquote><p>&lt;target name=&#8221;the.lot&#8221; depends=&#8221;compile,test,jar,report&#8221; /&gt;<br />
&lt;target name=&#8221;compile&#8221;&gt;<br />
&#8230;<br />
&lt;/target&gt;<br />
&lt;target name=&#8221;test&#8221;&gt;<br />
&#8230;<br />
&lt;/target&gt;</p></blockquote>
<h3>Public vs Private targets</h3>
<p>I&#8217;ve built build files using the <a href="http://www.martyandrews.net/blog/2004/07/maintainability_in_ant_build_s.html" target="_blank">public and private target idea</a> (affix a &#8220;-&#8221; to private targets so they can&#8217;t be called externally).</p>
<p>It can work in some situations and makes it reasonably clear what&#8217;s going on. It can also work in conjunction with the &#8220;functional and flow&#8221; targets described above. (Functional targets are private; flow targets are public).</p>
<p>My main issue with this approach is that as a build engineer you often want to call internal / private targets to run just a small step in the build (particularly while developing new features) &#8211; you can&#8217;t  do this if the targets are private. so you end up creating a second, public, target that calls the private target &#8230; and you end up doubling the size of your build files.</p>
<p>I prefer just to have the main entry point targets (your flow targets) at the top of the build file so it&#8217;s obvious to anyone who opens the build file what they can use.</p>
<p>You can also differentiate your public (API) targets by only allowing them to have description attributes. These will be the only targets listed when your run &#8220;ant -p&#8221;.</p>
<h3>Macrodefs with closures</h3>
<p><a href="http://ant.apache.org/manual/CoreTasks/macrodef.html">Macrodefs</a> are great and should be used to reduce duplication wherever possible.</p>
<p>An extra-powerful feature of macrodefs, which I only came to understand recently, is the ability to pass arbitrary ant elements into macrodefs &#8211; think closures / ruby blocks.</p>
<p>We now have expressive parts of our build scripts looking a bit like the following:</p>
<blockquote dir="ltr" style="margin-right: 0px"><p><font face="Default Monospace,Courier New,Courier,monospace">&lt;for-each-module&gt;<br />
&lt;compile module=&#8221;@{module}&#8221; /&gt;<br />
&lt;/for-each-module&gt;</font></p>
<p><font face="Default Monospace,Courier New,Courier,monospace">&lt;for-each-module&gt;<br />
&lt;test module=&#8221;@{module}&#8221;   /&gt;<br />
&lt;/for-each-module&gt;</font></p>
<p><font face="Default Monospace,Courier New,Courier,monospace">&lt;macrodef   name=&#8221;for-each-module&#8221;&gt;<br />
<strong><font color="#ff0000">&lt;element   name=&#8221;action&#8221;   /&gt;<br />
</font></strong>&lt;sequential&gt;<br />
&#8230;. do some   stuff &#8230;<br />
<strong><font color="#ff0000">&lt;action   /&gt;</font></strong><br />
&#8230;. do some more stuff   &#8230;<br />
&lt;/sequential&gt;<br />
&lt;/macrodef&gt;</font></p></blockquote>
<p>I&#8217;d be interested to hear if anyone has other suggestions for keeping Ant from spiraling out of control.</p>
]]></description>
		<wfw:commentRss>http://www.digitaldimsum.co.uk/2007/10/19/ant-fu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Blocks of Code</title>
		<link>http://www.digitaldimsum.co.uk/2007/05/16/blocks-of-code/</link>
		<comments>http://www.digitaldimsum.co.uk/2007/05/16/blocks-of-code/#comments</comments>
		<pubDate>Wed, 16 May 2007 20:11:07 +0000</pubDate>
		<dc:creator>jonny</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[visualisation]]></category>

		<guid isPermaLink="false">http://www.digitaldimsum.co.uk/2007/05/16/blocks-of-code/</guid>
		<description><![CDATA[<p>Coding really is become child&#8217;s play. This <a href="http://news.bbc.co.uk/2/hi/technology/6647011.stm" title="Free tool offers 'easy' coding" target="_blank">recent BBC news article</a> points to some of the ways kids are being introduced to programming.</p>
<p>The good people at MIT have put together <a href="http://scratch.mit.edu/" title="Scratch @ MIT" target="_blank">scratch</a>  a visual tool allowing kids to do drag-n-drop coding. The <a href="http://llk.media.mit.edu/projects/scratch/help/" title="Scratch help screens" target="_blank">help screens</a> give a good idea of how it works. Basically differently shaped blocks are put together (lego style) to form programs: a loop looks like a capital C and holds all the nested statements; booleans are pointy ended and only fit in pointy slots &#8211; likewise numbers are round and only fit in round slots &#8230; a nice simple introduction to strongly-typed languages. It actually fits pretty closely with how I visualise blocks of code, so it looks like a great way to introduce children to the coding mind-set. The welcoming colourful blocks are non-threatening and simple to understand.</p>
<p><!--more-->If that all seems too point-n-clicky then there are also <a href="http://hacketyhack.net/" title="HacketyHack" target="_blank">efforts to get kids using Ruby</a>. It&#8217;s a simple hosted and sandboxed service giving children the chance to write real programs &#8211; like a blog in just 6 lines.</p>
<p>This block caught my attention:</p>
<blockquote><p><strong>WHITHER ART THOU, BASIC??</strong></p>
<p>In the 1980s, a language called BASIC swept the countryside.  It was a language <strong>beginners          could use</strong> to make their computer speak, play music.  You could easily draw a big smiley face          or a panda or whatever you like!</p></blockquote>
<p>I&#8217;m interested in their choice of Ruby as the simple &#8220;gateway&#8221; language (the first one&#8217;s free, tell your mates), since there have been various discussions about whether Ruby is too complex or powerful for many inexperienced QA and dev teams to be *trusted* with.</p>
<p>It&#8217;ll be interesting to see how these kinds of tools are adopted. Either way I think some people at my current client could use a more pointy-clicky programming language &#8230;</p>
]]></description>
		<wfw:commentRss>http://www.digitaldimsum.co.uk/2007/05/16/blocks-of-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java is dead &#8211; long live the JVM</title>
		<link>http://www.digitaldimsum.co.uk/2007/05/09/java-is-dead-long-live-the-jvm/</link>
		<comments>http://www.digitaldimsum.co.uk/2007/05/09/java-is-dead-long-live-the-jvm/#comments</comments>
		<pubDate>Wed, 09 May 2007 18:29:32 +0000</pubDate>
		<dc:creator>jonny</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://www.digitaldimsum.co.uk/2007/05/09/java-is-dead-long-live-the-jvm/</guid>
		<description><![CDATA[<p>I had an interesting meal last night with the <a href="http://www.thoughtworks.com" title="ThoughtWorks" target="_blank">ThoughtWorks</a> delegation to JavaOne. They were in town in support of the <a href="http://studios.thoughtworks.com/2007/5/7/mingle-to-run-on-jruby" title="Mingle to run on JRuby" target="_blank">news</a> that <a href="http://studios.thoughtworks.com/mingle-project-intelligence" title="Mingle" target="_blank">Mingle</a> is going to be launched on <a href="http://jruby.codehaus.org/" title="JRuby" target="_blank">JRuby</a>.</p>
<p>I&#8217;ve seen some demos of <a href="http://studios.thoughtworks.com/mingle-project-intelligence" title="Mingle" target="_blank">Mingle</a> and it looks great, but of equal interest to me is the choice to release it on <a href="http://jruby.codehaus.org/" title="JRuby" target="_blank">JRuby</a>. This seems to be another step along the road of Java moving down the stack. Java was selected as the delivery platform because corporate IT understands how to deploy, integrate, support and optimize it; Ruby was chosen as the development language because of the productivity and expressiveness of the language.</p>
<p><!--more--></p>
<p>I don&#8217;t want to knock Java &#8211; it&#8217;s provided my bread and beer for 10 years, but there are many strong arguments for using more concise and expressive languages to encode business logic.</p>
<p>So it looks as though Java is moving more into the space of an OS rather than a language for building business logic. Our illustrious founder, <a href="http://www.thoughtworks.com/singham+roy.html" title="Roy Singham" target="_blank">Roy</a>, suggested that Java&#8217;s legacy will be the JVM &#8211; years have been spent optimizing it and making it run on many platforms. I would add to that the ecosystem of libraries integrating with a panoply of databases, messaging formats and middleware.</p>
<p><a href="http://jruby.codehaus.org/" title="JRuby" target="_blank">JRuby</a> allows Ruby to leverage this whole ecosystem. Operations teams are completely comfortable managing Java installations &#8211; they don&#8217;t tend to care too much what&#8217;s in your WAR or EAR as long as they can monitor and configure the JVM, datasources, queues and other resources.</p>
<p>One question that springs to mind is whether this is just a temporary stage while the Ruby deployment stack matures or whether it will be a lasting situation. It would seem odd to need all the extra infrastructure, but the current situation is that even though many apps are deployed on highly expensive Java containers (think IBM and BEA) most of them will still sit behind Apache. They do this because Apache is more trusted to manage security, redirection, static content delivery and various other web fundamentals.</p>
<p>So maybe the new stack will be:</p>
<ul>
<li><strong>Apache </strong>handling the HTTP piece</li>
<li>A <strong>Java container</strong> handling the Integration piece (with or without a captial E in front)</li>
<li><strong>Ruby </strong>(or other languages leveraging <a href="http://jcp.org/en/jsr/detail?id=223" title="JSR 223: Scripting for the JavaTM Platform" target="_blank">JSR 223</a>) to handle business logic</li>
</ul>
<p>It will be interesting to see where this goes, but I can&#8217;t help feeling there&#8217;s one too many pairs of hands in that stack.</p>
]]></description>
		<wfw:commentRss>http://www.digitaldimsum.co.uk/2007/05/09/java-is-dead-long-live-the-jvm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
