<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: Coding Style - A Fine Line Between Clever and Stupid Part 2</title>
	<atom:link href="http://www.kebabShopBlues.co.uk/2007/05/10/coding-style-a-fine-line-between-clever-and-stupid-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kebabShopBlues.co.uk/2007/05/10/coding-style-a-fine-line-between-clever-and-stupid-part-2/</link>
	<description>a site about the stuff that keeps you busy</description>
	<pubDate>Sat, 19 May 2012 03:55:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Bob</title>
		<link>http://www.kebabShopBlues.co.uk/2007/05/10/coding-style-a-fine-line-between-clever-and-stupid-part-2/comment-page-1/#comment-10727</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Thu, 12 Jul 2007 17:21:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.kebabShopBlues.co.uk/2007/05/10/coding-style-a-fine-line-between-clever-and-stupid-part-2/#comment-10727</guid>
		<description>In my 20 years of coding I learned that there are "elegant" academic approaches and then there are practical ones. Having "exit as soon as you can" strategy is the latter. I didn't know people still debate this.

The way I see it, a good code strikes a balance between saying too much and being too abstract. When I'm looking at the code, I'm not reading a book -- I'm trying to understand what comes out given certain inputs, preferably in one pass. Having early exits helps to eliminate all dead branches early in the process and spear me a headache. In case of search-like function, it goes as follows.

1. If parameters are bad, who cares what the rest does? Out.
2. Now, that hands are clean, let's see what's for dinner. What is a default value that will be returned in all cases that I don't know or don't care about?
3. Do actual work. Return as soon as found, or set it as a return value possible post-processing and exit any loops. Forget about everything else.
4. Return whatever is set to be returned, because at this point if it's there, it must be correct and I don't remember how it got there.

The only thing that still bothers me is throwing exceptions vs. returning nulls and default values. But that's a different problem.</description>
		<content:encoded><![CDATA[<p>In my 20 years of coding I learned that there are &#8220;elegant&#8221; academic approaches and then there are practical ones. Having &#8220;exit as soon as you can&#8221; strategy is the latter. I didn&#8217;t know people still debate this.</p>
<p>The way I see it, a good code strikes a balance between saying too much and being too abstract. When I&#8217;m looking at the code, I&#8217;m not reading a book &#8212; I&#8217;m trying to understand what comes out given certain inputs, preferably in one pass. Having early exits helps to eliminate all dead branches early in the process and spear me a headache. In case of search-like function, it goes as follows.</p>
<p>1. If parameters are bad, who cares what the rest does? Out.<br />
2. Now, that hands are clean, let&#8217;s see what&#8217;s for dinner. What is a default value that will be returned in all cases that I don&#8217;t know or don&#8217;t care about?<br />
3. Do actual work. Return as soon as found, or set it as a return value possible post-processing and exit any loops. Forget about everything else.<br />
4. Return whatever is set to be returned, because at this point if it&#8217;s there, it must be correct and I don&#8217;t remember how it got there.</p>
<p>The only thing that still bothers me is throwing exceptions vs. returning nulls and default values. But that&#8217;s a different problem.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

