<?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>andrewmccall.com &#187; minimalism</title>
	<atom:link href="http://andrewmccall.com/tag/minimalism/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewmccall.com</link>
	<description>If you want to know what I think...</description>
	<lastBuildDate>Wed, 02 Jun 2010 20:24:23 +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>Spartan Programming</title>
		<link>http://andrewmccall.com/2008/07/spartan-programming/</link>
		<comments>http://andrewmccall.com/2008/07/spartan-programming/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 09:36:00 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[minimalism]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://andrewmccall.com/?p=12</guid>
		<description><![CDATA[Jeff Atwood was pleased to find that his coding conventions, the ones we all settle into, have been tending towards ...]]></description>
			<content:encoded><![CDATA[<p><a href="http://codinghorror.com">Jeff Atwood</a> was pleased to find that his coding conventions, the ones we all settle into, have been tending towards those of a style of programming called Spartan Programming. Which is minimalist programming, as in &#8220;a spartan lifestyle&#8221;. Check his <a href="http://www.codinghorror.com/blog/archives/001148.html">post</a> out for a more in depth explination but suffice to say the aim is to reduce complexity in any way possible. </p>
<p>I&#8217;ve got to agree that more and more I&#8217;ve tended in that direction too. I don&#8217;t remember the last time I had more than a handful of conditionals or loops in a method. My methods are terse and accomplish one thing, sub tasks are split out into other methods. It&#8217;s come very naturally, but it has taken time. I don&#8217;t think it&#8217;s something you can be taught, or learn. It&#8217;s definitely a practice thing. </p>
<p>One aspect of Spartan Programming where I disagree is with the terse variable names. I think they could end up introducing more accidental and avoidable errors. They lessen the utility of some key IDE features. And generally would just make my life harder, so I&#8217;ve gone the other way. Once upon a time I would happily create the following code: </p>
<pre>
public void sendMessage() {
    MimeMessage m = new MimeMessage();
    m.setBody("This is a test");
    m.send();
}
</pre>
<p>These days I try to avoid calling variables things like <em>m</em> and prefer to call them what they are: </p>
<pre>
public void sendMessage() {
    MimeMessage message = new MimeMessage();
    message.setBody("This is a test");
    message.send();
}
</pre>
<p>I know the arguments and logic: </p>
<ul>
<li>The method should be simple enough that the variable name <em>m</em> is clear enough. </li>
<li>The shorter name reduces complexity and therefore errors. </li>
<li>Less characters means lines don&#8217;t get too long</li>
</ul>
<p>Of these three the third is the only one I really buy though. Long variable names and too many characters on a line can push some stuff too far to the right potentially hiding errors or overly complex code; but it&#8217;s an edge case and there are other ways to solve the problem.</p>
<p>While true that in a short minimalist method a variable <em>m</em> would be clear enough, a variable called <em>message</em> is equally clear. The shortening doesn&#8217;t gain anything in clarity. The argument for less characters reducing errors in the era of modern IDEs doesn&#8217;t wash with me either &#8211; My IDE tells me of I mistype a variable and auto completes them furthermore by typing actual words I actually improve the accuracy even more. </p>
<p>Shorter names on the other hand can tend more towards a crowded namespace and can result in properly typing the wrong variable. This is especially a problem in a <a href="http://en.wikipedia.org/wiki/Programming_language#Weak_and_strong_typing">weakly typed language</a>.</p>
<p>Consider the following:</p>
<pre>
function sendInviteMessages(n)
    for i = 0 to n
        Set m = Server.CreateObject("MimeMessage)
        m.Body = "Welcome to our fancy new site!"
        m.Send
        Set n = Nothing
    next
end function
</pre>
<p>What you see here is something that wouldn&#8217;t happen, or not as often with a variable name like <em>number</em> instead of <em>n</em> and <em>message</em> instead of <em>m</em>. Worse still, depending on the language and how it treats null variables it might even pass a quick test with a single address and appear to be working!</p>
<p>The one place I totally disagree with the terse variable naming conventions though, is the method parameters. That actually makes life harder when working with code completion. Which is easier to follow?</p>
<p><img src="/images/blog/spartan-ex1.png"/><br />
<img src="/images/blog/spartan-ex2.png"/></p>
<p>There are plenty of other code completion and helpful shortcuts in a modern IDE where the parameter names are used to make our lives easier. All of which lost, with no real gain.</p>
<p>I&#8217;m not arguing that variable names shouldn&#8217;t be terse and sensible. Going back to the first example the following is just stupid and is far worse than using just <em>m</em>, it&#8217;s practically illegible and very difficult to just eyeball the code to see what is going on.</p>
<pre>
public void sendMessage() {
    MimeMessage theMessageToSend = new MimeMessage();
    theMessageToSend.setBody("This is a test");
    theMessageToSend.send();
}
</pre>
<p>Other times I go the opposite way and have adopted conventions for making some variables extremely terse. <em>InputStream</em> and <em>OutputStream</em> variables for example I always call <em>is</em> and <em>os</em>. So I do try and be as terse as possible, but never terseness at the expense of obviousness of intent.</p>
<p>While I agree with most of the practices and like Jeff was nodding along as I read about Spartan Programming, there are a few I don&#8217;t fully follow and some I&#8217;m against. In the end though I tend to agree with his assertion that <em>Minimalism isn&#8217;t always the right choice, but it&#8217;s rarely the <i>wrong</i> choice</em> as long as it&#8217;s not at the expense of clarity of intent.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmccall.com/2008/07/spartan-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
