<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Skeptical Methodologist</title>
	<atom:link href="http://skepticalmethodologist.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://skepticalmethodologist.wordpress.com</link>
	<description>Software, Rants and Philosophy</description>
	<lastBuildDate>Thu, 19 Nov 2009 20:54:24 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='skepticalmethodologist.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/136831a68a55090c35ca74ce6578a411?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>The Skeptical Methodologist</title>
		<link>http://skepticalmethodologist.wordpress.com</link>
	</image>
			<item>
		<title>To Spec or not to Spec</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/11/19/to-spec-or-not-to-spec/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/11/19/to-spec-or-not-to-spec/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 20:54:05 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=146</guid>
		<description><![CDATA[Like software patterns, there are many different software creative processes that tend to be re-invented over and over again.  Similar to the way that some software patterns are actually different versions of each other, or more importantly, weaknesses in the implementing language, I believe some processes only exist due to weaknesses in the chosen technology.  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=146&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Like software patterns, there are many different <a href="http://blogs.msdn.com/ericlippert/archive/2009/11/19/always-write-a-spec-part-one.aspx">software creative processes</a> that tend to be re-invented over and over again.  Similar to the way that some software patterns are actually different versions of each other, or more importantly, weaknesses in the implementing language, I believe some processes only exist due to weaknesses in the chosen technology.  An example of one of these processes is the &#8217;spec&#8217; or specification.</p>
<p>Specifically, I&#8217;m talking about the technical specifications described in the above link, not functional specifications.  I believe technical specifications are a signal of weakness due to the following thought process &#8211; a technical spec can be deemed &#8216;good&#8217; when it is unambiguous and has a relationship with actual implementation nearing 1-to-1.  If either of those two facts is untrue, then that means there is some element of interpretation in the spec, which further means that two coders may implement the spec in two different ways, making different assumptions, thus leading to defects.</p>
<p>So let&#8217;s assume we have a good spec, one in which we have a close to 1-to-1 mapping between specifications and implementation, and a lack of ambiguity.  There are two thoughts I have on this &#8211; one is, how did we get here?  The other is, how is this any different from code itself.  I&#8217;ll deal with the second first, just to spice things up.</p>
<p>A <em>good</em> spec really isn&#8217;t any different than <em>good</em> pseudocode, in fact you&#8217;ll find a lot of English descriptions of looping behavior, if statements, etc., primitives in most imperative languages.  These can be turned into implementation rather mechanically, so the question results, why didn&#8217;t you just implement the spec in the first place rather than writing the entire thing out in English?  What exactly does a spec get you that doing the exact same process except using actual implementation language doesn&#8217;t?</p>
<p>The other question is, how do you create a <em>good</em> spec?  Well, most likely you write a working draft, then send it out for reviews.  Various other designers look over it, read the spec, then send back some comments.  Maybe you missed a corner case, maybe you didn&#8217;t think of a certain interaction.  Over time, the spec is rewritten to be more and more specific and consistent.</p>
<p>Let me know if you disagree with any of the above logic so far, because now I&#8217;m going to add a twist.  Let&#8217;s say, instead of writing a spec, we actually wrote implementation code from the get go, except we used the same processes described above.  That is, we iteratively rewrote it, sought frequent feedback from humans or otherwise, and we stopped when there was a 1-to-1 mapping between the problem at hand and a complete lack of ambiguity (rather easier to do with a programming language).</p>
<p>We just re-invented rapid prototyping.  You see, spec writing is what people are forced to do when they work with languages or technologies that don&#8217;t allow rapid prototyping?  What exactly, when enumerated, would these technologies be?  I&#8217;d venture a guess that things like a REPL and high level &#8217;scripting&#8217; interface would be a good subset.  Languages like Ruby or Python, or heuristically, anything that doesn&#8217;t have a long &#8216;compilation&#8217; cycle.  There are many compiled languages, for example, that turn around quickly allowing rapid prototyping, so I&#8217;m not JUST saying scripting languages.  Languages with more boilerplate, more line noise, and a longer turn around cycle lend to writing specs over rapid prototyping (i.e., C/C++).</p>
<p>Rapid prototyping has many other benefits over spec writing.  For instance, during spec writing, human reviewers are not only finding high level logic errors, but also syntax problems, type problems, and the like.  These are all problems that a high level language will <em>automatically</em> find.  The enumeration of &#8216;what&#8217; could be passed into a specific function mentioned in the article linked to previously is a prime example of type checking that Haskell would let you know on the spot if you hadn&#8217;t fixed.</p>
<p>Moreover, spec writing and rapid prototyping <em>aren&#8217;t competitng ideas</em>.  In other words, a spec COULD be a rapid prototyped code base!  If we need to build an embedded system using a subset of C, for example, rapid prototyping would be a rather onerous process compared to our REPL and high level constructs.  But no one said the spec couldn&#8217;t be itself written in a high level language to be ported to low level C once it was deemed complete.  Therefore, rapid prototyping should be used even on projects where a spec is used, and the two should be practically substitutable.</p>
<p>Of course, all process patterns like these are just that, patterns, and there really should be no &#8216;make software using process x&#8217; rules since x may not always apply.  Sometimes you need some exploratory programming (very similar to rapid prototyping), or sometimes you may know how to express something in English but not in code (such as in technical fields).  Patterns, even process patterns, ought to be seen more as a &#8216;bag of tricks&#8217; similar to the skills mathematicians build up &#8211; tricks to simplify or restate problems in other domains.  Too often we&#8217;re convinced that our problems are like arithmetic, and there&#8217;s just one simple algorithm or process that needs to be exercised again and again, but instead they&#8217;re more like problems found in the higher echelons of math.  They require insight, tricks, squinting, hand waving, and eventually, a eureka.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/146/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=146&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/11/19/to-spec-or-not-to-spec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
		<item>
		<title>IoC without the fluff</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/10/10/ioc-without-the-fluff/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/10/10/ioc-without-the-fluff/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 18:56:41 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=139</guid>
		<description><![CDATA[Things like dependency injection and IoC are cool, and they do decouple your code and make it easier to extend at test.  But the problem is that the software community always tends to reinvent the same solutions to the same problems and then give them a totally different name.  I mean, what are the real [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=139&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Things like dependency injection and IoC <em>are</em> cool, and they <em>do</em> decouple your code and make it easier to extend at test.  But the problem is that the software community always tends to reinvent the same solutions to the same problems and then give them a totally different name.  I mean, what are the <em>real</em> differences between Haskell <a href="http://en.wikipedia.org/wiki/Type_class">Type Classes</a> and the now <a href="http://www.ddj.com/cpp/218600111">defunct C++1x &#8216;concept&#8217;</a>&#8230; er&#8230; concept.  (Seriously guys, we&#8217;re running out of different synonyms for &#8216;thing&#8217;.  We&#8217;ve got object, class, type, type class, structure&#8230;)  Here&#8217;s what IoC and DI are, how they interrelate, without using silly words like &#8216;container&#8217;, which is just another word for &#8216;thing&#8217; pretty much in this context.  We have a function, let&#8217;s say, and I&#8217;m going to use python notation since it&#8217;s short and sweet.</p>
<blockquote><p>x = 0</p>
<p style="padding-left:30px;">def func(y):</p>
<p style="padding-left:60px;">return x+y</p>
</blockquote>
<p>Everyone can figure out what that function does.  But how will it react in a large system?  Who the hell knows, it uses a global variable that can be modified at any time, from anywhere.  Our function &#8216;func&#8217; is now coupled to a global variable, as is, by associativity (or is it commutativity?) anyone who uses it.  So we change it to this far more elegant version:</p>
<blockquote><p>def func(x,y):</p>
<p style="padding-left:30px;">return x+y</p>
</blockquote>
<p>Voila!  In DI terms, we&#8217;ve &#8216;injected&#8217; the &#8216;dependency&#8217; of func on the variable x.  Now func is only dependent on two locally defined parameter variables, a far more elegant and simple way to do things.  Let&#8217;s fast forward to OO for a second.  Assume we have a class foo&#8230;</p>
<blockquote><p>class bar:</p>
<p style="padding-left:30px;">def __init__(self):</p>
<p style="padding-left:60px;">self.myFoo = foo()</p>
<p style="padding-left:30px;">def func(self, x):</p>
<p style="padding-left:60px;">return self.x + self.myFoo</p>
</blockquote>
<p>This is OO, so it&#8217;s nice and decoupled right?  Not really.  If you unroll the object, thinking of it basically as a <a href="http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html">poor man&#8217;s closure</a>, you realize that func is actually doing something like this (assuming no one changes self.myFoo)</p>
<blockquote><p>def func(x):</p>
<p style="padding-left:30px;">return foo() + x</p>
</blockquote>
<p>Global functions, when they&#8217;re pure, are nice to have.  But you can still see the problem of the coupling between func and foo, now.  If foo is not pure, then we have side effect issues, but moreover, we still have just plain maintainability/extensibility issues with the coupling between the two.  The number one use case pointed to by dependency-injection types is that of testing.  What if we want to test func, but we don&#8217;t want to test foo?  Maybe foo takes a long time.  Or maybe we <em>haven&#8217;t even written foo yet!</em> (Now you can see the connection between TDD, dependency injection, and why the two might change your style of design.  You can test top level objects without even implementing &#8216;low-level&#8217; ones yet..  But that&#8217;s tangential.)  We can do the same thing we did in the first case though to break that coupling:</p>
<blockquote><p>def func(x, foo_thing):</p>
<p style="padding-left:30px;">return x + foo_thing()</p>
</blockquote>
<p>Oh hey, higher order programming.  Who&#8217;d have thought that would show up here?  Let&#8217;s roll our stuff back into familiar OO terms:</p>
<blockquote><p>class bar:</p>
<p style="padding-left:30px;">def __init__(self, foo_thing):</p>
<p style="padding-left:60px;">self.myFoo = foo_thing()</p>
<p style="padding-left:30px;">def func(self, x):</p>
<p style="padding-left:60px;">return self.myFoo + x</p>
</blockquote>
<p>Dependency, consider yourself injected.  Ok, fine, what the hell is IoC then?  Why does it have to have such a crazy name, and what are these containers, and wah wah wah!  Well, let&#8217;s go back to our familiar func and make it a little more complex:</p>
<blockquote><p>x = 0</p>
<p>y = 0</p>
<p>z = 0</p>
<p>a = 0</p>
<p>b = 0</p>
<p>c = 0</p>
<p>def func(var):</p>
<p style="padding-left:30px;">return var + a + b + c + x + y + z</p>
</blockquote>
<p>Gross!  Global dependencies on like, a bajillion different things!  Let&#8217;s inject those dependencies!</p>
<blockquote><p>def func(var, x, y, z, a, b, c):</p>
<p style="padding-left:30px;">return var + a + b + c + x + y + z</p>
</blockquote>
<p>Ah, much better.  Er, wait&#8230; now my buddy, who had code like this:</p>
<blockquote><p>def func_2(var1, var2):</p>
<p style="padding-left:30px;">return func(var1) + func(var2)</p>
</blockquote>
<p>Has had his interface explode to:</p>
<blockquote><p>def func_2(var1, var2, a, b, c, x, y ,z):</p>
<p style="padding-left:30px;">return func(var1, a, b, c, x, y, z) + func(var2, a, b, c, x, y, z)</p>
</blockquote>
<p>And his callers have their interfaces explode, and their callers have theirs, etc&#8230;  But wait, any of you OO gurus notice that a,b,c and x,y,z never seem to make any sense without each other?  They always seem passed with each other, they seem semantically related, who knows what else.  Why, I&#8217;ll bet our design could be more&#8230; what&#8217;s that nice word elegant designs are described as?  Oh yes, <em>cohesive!</em></p>
<blockquote><p>class point:</p></blockquote>
<blockquote>
<p style="padding-left:30px;">def __init__(self, x, y, z):</p>
</blockquote>
<blockquote>
<p style="padding-left:60px;">self.x = x; self.y = y; self.z = z  #just leave them as plain-old-data and public</p>
</blockquote>
<p>Oh wait, and two points, well, we can call that a&#8230;</p>
<blockquote><p>class distance: #er, maybe not the best name&#8230;</p>
<p style="padding-left:30px;">def __init__(self, pt1, pt2):</p>
<p style="padding-left:60px;">self.pt1 = pt1; self.pt2 = pt2</p>
</blockquote>
<p>Now are interfaces shrink down, only needing one extra parameter, a &#8216;distance&#8217;, which I&#8217;m sure in our func, foo, bar whatever application we&#8217;re building, make good sense semantically and is drawn from our domain.  Likewise, let&#8217;s say that we&#8217;re using dependency injection to make our objects a lot less coupled.</p>
<blockquote><p>class bar:</p>
<p style="padding-left:30px;">def __init__(self, obj1, obj2, obj3, obj4, obj5):</p>
<p style="padding-left:60px;">self.obj1 = obj1; self.obj2 = obj2; self.obj3 = obj3; self.obj4 = obj4; self.obj5 = obj5</p>
</blockquote>
<p>Wow, those dependencies sure are injected all right.  But that class has been injected so much, it&#8217;s beginning to look like a heroine addict.  These objects all seem to have something to do with each other, <em>why don&#8217;t we bundle them up in a cohesive object?</em></p>
<blockquote><p>class bar:</p></blockquote>
<blockquote>
<p style="padding-left:30px;">def __init__(self, obj_builder_thingie): #TODO: think of a better name</p>
</blockquote>
<blockquote>
<p style="padding-left:60px;">self.obj1 = obj_builder_thingie.obj1(); &#8230;</p>
</blockquote>
<p>Ah, now our design is <em>decoupled</em> and <em>cohesive</em>.  Hallmarks of good design.  (Of course, simply bundling arbitrary objects together isn&#8217;t necessarily cohesive.  We&#8217;re assuming in this case, whenever we&#8217;ve bundled something together, those objects have had something to do with each other semantically or in the domain.)  For some reason, whenever we bundle these objects together, our Java buddies (and C# buddies) want to call this &#8216;Inversion of Control&#8217;, mostly because it&#8217;s now the caller/creator&#8217;s problem of figuring out how it wants to &#8216;configure&#8217; the innards of our bar class.  They sometimes will go even further and make obj_builder_thingie not just a normal object, but a framework for going out and reading XML files to dynamically figure out what obj1() and obj2() should return.  That way, instead of editing a nice clean python unit test file to configure and modify your tests, you can edit a huge ugly xml file with lots of angled brackets to configure and modify your tests.  Sounds much more enterprisey to me!  Job security here I come!</p>
<p>So, let&#8217;s recap.  Dependency injection is moving a &#8216;global&#8217; to a &#8216;parameter&#8217;, which insofar as primitive types and values, has always seemed like a good idea.  But for OO guys, moving global functions (or an object representing those functions) seems like a brand spankin&#8217; new idea, when really functional guys have been moving global functions to parameters for years.  C&#8217;est la vie, at least we&#8217;re learning something from each other.  The specific case bandied about is always how this makes testing easier because you can &#8216;inject&#8217; which objects you&#8217;d like to collaborate with in the constructor (or a setter, etc&#8230; but setter&#8217;s are evil.)  But this solution can be generalized to &#8216;inject&#8217; any configurable behavior you want in the form of variables, functions or classes themselves in a dynamic language like python.  The side effect is your parameter lists get huge, and while your code is decoupled, its decoupled kind of like a box of legos with no instructions on how to build your starship.  So you use your ole&#8217; object-oriented smarts to start grouping some of those parameters together into objects themselves, and now  your &#8216;injected class&#8217; begins looking through the objects that are passed into it to find what it needs, rather than everything being unrolled on the parameter list.  IoC is basically, then, dependency injection (or the voracious removal of anything global) on a large scale and must, then, solve the problems (explosive parameter lists) that come with that.</p>
<p>That&#8217;s it in a nutshell.  Hopefully I haven&#8217;t confused you further.  Dependency injection is just another step in the good practice of &#8220;make things as local as possible&#8221;, or decoupling.  Parameter lists are more local than global, even for functions like class constructors.  IoC is the counterbalance to massive decoupling, and that&#8217;s to make the program more &#8216;cohesive&#8217; again by grouping up many of these new things being passed in parameter lists into objects and hierarchies themselves.  Any questions?</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=139&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/10/10/ioc-without-the-fluff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
		<item>
		<title>Smart Pointers for Dumb Developers</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/09/01/smart-pointers-for-dumb-developers/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/09/01/smart-pointers-for-dumb-developers/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 03:09:50 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=137</guid>
		<description><![CDATA[Edouard in his post claims that smart pointers, like shared_ptr and auto_ptr, are overused.  While he actually makes quite a few legitimate critiques, I think he misses the fundamental problem that hits nearly all of the computer scientist&#8217;s beautiful abstractions &#8211; they&#8217;re all dangerous if they&#8217;re overused.  C++&#8217;s smart pointers are no exception.  I do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=137&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Edouard in his <a href="http://www.bureau14.fr/blogea/2009/08/smart-pointers-are-overused/">post </a>claims that smart pointers, like shared_ptr and auto_ptr, are overused.  While he actually makes quite a few legitimate critiques, I think he misses the fundamental problem that hits nearly all of the computer scientist&#8217;s beautiful abstractions &#8211; they&#8217;re <em>all </em>dangerous if they&#8217;re overused.  C++&#8217;s smart pointers are no exception.  I do wish to come to their defense, though, and some what might seem like obvious guidelines for their use.</p>
<p>Smart pointers are the poor man&#8217;s garbage collection.  Or, in better terms, they are the average C++ developer&#8217;s garbage collection.  C++ is a language that is a little bit too &#8216;expert friendly&#8217;, and dynamic allocation, similar to multithreaded programming, is hard(tm).  Smart pointers in many cases allow your average developer to turn a horrible bug &#8211; memory leaks or null dereferences &#8211; into a less heinous inefficiency.  That&#8217;s a win.  They are no complete replacement for object lifecycle analysis though, which is Edouard&#8217;s main point.  Of course, raw pointers that are intelligently managed will always outperform smart pointers.  But what if you don&#8217;t have the smartest developers in the world?  Or what if you don&#8217;t have the time/money to throw your smart developers at making sure you squeeze every last FLOP out of that processor, but instead need them to focus on implementing new features, etc?  It&#8217;s all economics.</p>
<p>I&#8217;d like to offer my own taxonomy to budding developers.  Kind of a road map to memory usage in C++ to find a good middle ground between performance and safety.</p>
<p>Your first rule of thumb, and the first place you should go to build any object, is the stack.  The stack is well understood, putting objects on the stack is usually pretty cheap, and a good chunk of the time, most objects you need are transient for a few statements and then aren&#8217;t needed any  more.  For awhile there, it was simply considered more &#8216;OO&#8217; to put things on the heap (thank you very much JAVA).  Thankfully, those days are gone.</p>
<p>What CAN&#8217;T be put on the stack?  Well, large objects run the risk of pushing the stack to its limits, since most of the time, the stack is smaller than the heap.  In addition, the stack requires a class to be concrete, which makes polymorphism a little more tricky.  Finally, again with large objects, is that passing these arguments to functions or methods can be expensive as their copy constructors are called.</p>
<p>For a large object that you want to put on the heap, enter the scoped pointer.  The scoped pointer acts like a stack variable in its construction and cleanup, but is created on the heap.  You should also question why you&#8217;re putting so many large objects on the heap.</p>
<p>To handle polymorphism, for the most part, you&#8217;re going to have to use pointers.  An abstract base class pointer can point to a derived class, so it&#8217;s a question of what kind of management you want wrapping that pointer.  Scoped pointers don&#8217;t really help any with polymorphism, but our two friends &#8211; one of which is disparaged by the Edouard &#8211; come to save us.  In the case of &#8216;factory&#8217; like functions, or functions that create an object on the heap and &#8216;pass off&#8217; ownership to the returnee, we&#8217;d like to use an auto_ptr, since this type of smart pointer enforces this pattern.  In the case where we&#8217;re getting a reference to an object, but the method called still wants to refer to a shared place in memory, then we usually want a shared_ptr.  The original poster is right, though, in many cases, through careful analysis, both of these pointer types can be done away with by simply studying the expected lifecycles of the object underneath.  But this is not always possible in the constraints of developing software.</p>
<p>Keep in mind the const reference trick, too.  Returning a reference to a stack variable is a bad idea, since the stack variable&#8217;s probably been deleted.  However, the standard states that getting a CONST REFERENCE extends the lifetime of whatever variable is being returned to the enclosing scope.  That actually opens up efficient usage of some uses of polymorphism, since the memory&#8217;s allocated on the stack yet we can still get a polymorphic reference to it.  I&#8217;d use this technique with care, though.</p>
<p>Ultimately, such low level control and the plethora of options available to the developer makes memory management in C++ tricky, yet powerful and abstract.  There&#8217;s different use cases for all the potential views of memory, and subtleties to each use.  Shared_ptrs can more or less cover almost all these uses, but there&#8217;s a cost associated with not doing any real analysis of your memory footprint.  For the average developer, though, if you want to make sure they don&#8217;t introduce any risks, giving them a poor man&#8217;s garbage collector is probably your best option.</p>
<p>(*Though you still need to peer review their code and check for cycles, the notorious corner case that shared_ptr will still leak with.)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/137/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=137&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/09/01/smart-pointers-for-dumb-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
		<item>
		<title>The Science of Science</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/08/08/the-science-of-science/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/08/08/the-science-of-science/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 18:50:02 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=135</guid>
		<description><![CDATA[&#8220;Metacognition&#8221; is a word that basically means, thinking about thinking.  You take part in metacognition when you actively try and spot patterns in your own behavior that are acting against your goals, and then trying to create solutions that work around these problems.  It&#8217;s self reflection, but also action that takes place due to that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=135&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>&#8220;Metacognition&#8221; is a word that basically means, thinking about thinking.  You take part in metacognition when you actively try and spot patterns in your own behavior that are acting against your goals, and then trying to create solutions that work around these problems.  It&#8217;s self reflection, but also action that takes place due to that reflection.  It might be uniquely human.</p>
<p>There is an analogue in society, though, when any sort of social movement begins to use it&#8217;s own doctrine to look back on itself.  This is generally restricted, though, and does not include  self reflective studies using other means, for example, a political movement using scientific evidence to rethink its position on things.  I&#8217;d suppose we could call that &#8216;iterative&#8217; progress.  But instead, its when you turn a social movement with an intrinsic ability for self reflection back on itself.  Say, let&#8217;s psychoanalyze Freud, for example.  Or, more importantly, let&#8217;s apply the <a href="http://www.badscience.net/2009/08/how-myths-are-made/">scientific method to science itself</a>.</p>
<p>In science, let&#8217;s say medical science, we have a hypothesis that X causes B.  Now, medical science is one of a few &#8217;special&#8217; branches of science who are motivated by more than just the search for truth itself.  Generally, if X causes B, B is a bad thing and we want to stop it.  Knowing that X causes it means that we can have more control over B and reduce suffering.  So when we do medical science, we more or less want to do it as &#8216;best&#8217; we can, to get to the bottom of various diseases and halt human suffering.</p>
<p>So we hypothesize that the current way we do medical science is the best, i.e., that it yields the most truth and that these truths are the most effective to reduce human suffering.  If, through that hypothesis, a researcher were to be able to find a pattern in medical science itself that yielded weakening evidence, that researcher would be doing science on science itself.</p>
<p>But like medical science, who&#8217;s treatments and drugs improve (by some small degree) by every paper published, does science not itself recursively improve through it&#8217;s own self analysis?  By applying the results of science and mathematics, in the case of the above link, network theory, to the processes that produced those results, science becomes STRONGER due to it.  The scientific method as we know it from the enlightenment is a sound way to find truth about our world, we must always remember that the evidence we produce from any one experiment is only as good as the assumptions that went into it.  And there are many assumptions in the scientific method itself, of which, we learn about more only through self reflection.</p>
<p>Medical science, not to pick on it, is rife with these enlightening moments.  From discovering that taking a sugar pill makes people feel better (the Placebo effect), to <a href="http://www.nytimes.com/2007/09/16/magazine/16epidemiology-t.html">realizing that people who follow doctor&#8217;s orders tend to be healthier than those who don&#8217;t, even if those doctor&#8217;s orders are non-sensical</a>.  We have invented the double blind placebo controlled trial to control for the scientists&#8217; own bias as well as human&#8217;s predilection for sugar pills.  We&#8217;ve invented meta-analysis to momentarily reflect on our own science to try and combine and better glean results from a group of studies.  We&#8217;ve invented the idea of conflict of interest, the open access journal as well as many other tools and techniques that were the result of turning the scientific method back on itself.</p>
<p>You can see the result of this recursive growth in transistors.  We&#8217;ve built computers, and then only months later, used those very computers to design the next generation.  This same recursive growth is possible in science too &#8211; the very results mentioned above shows that we CAN do science better.  Lives are at stake in many cases, and if not lives, then large sums of money.  We can only do so much good science, produce so many real results, in a year for a given dollar.  We should focus on making these dollars go as far as possible by applying the results of (and funding more of) these sorts of self reflective studies.  The more bias we remove from our scientific process, the cheaper science gets for any dollar put in.  The cheaper it gets, the more we can do.  The more we can do, the more we learn.  <em>The more we learn, the more lives we save and the more wealth we create</em>.</p>
<p>And the cycle continues towards singularity.  Kurzweil is right, but he never mentions culture.  Culture, and the products of human culture, are also capable of exponential growth, and I don&#8217;t think we&#8217;re anywhere near an inflection point.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/135/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=135&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/08/08/the-science-of-science/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
		<item>
		<title>Software Engineering Is Dead</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/07/19/software-engineering-is-dead/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/07/19/software-engineering-is-dead/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 15:57:53 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=131</guid>
		<description><![CDATA[Long live Software Engineering!
The exalted Father of many of the processes we know and lovehate, Tom Demarco, recently wrote an article describing his second thoughts on many of his prescriptions from his book, Controlling Software Projects: Management, Measurement and Estimation.
Much of what he says should ring true to most of us in the trenches.  Attempting [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=131&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Long live Software Engineering!</p>
<p>The exalted Father of many of the processes we know and <span style="text-decoration:line-through;">love</span>hate, Tom Demarco, recently <a href="http://www.itwire.com/content/view/26370/1141/1/0/">wrote an article describing his second thoughts </a>on many of his prescriptions from his book, <a href="http://www.amazon.com/gp/product/0131717111?ie=UTF8&amp;tag=davidmwilliat-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0131717111">Controlling Software Projects: Management, Measurement and Estimation</a>.</p>
<p>Much of what he says should ring true to most of us in the trenches.  Attempting to code directly to software metrics is a fools errand.  Not only do the current methods of collecting metrics frequently have relatively high costs to true value, but they also cause a game of metric cat and mouse where software increasingly fits what metrics say &#8216;looks good&#8217; but loses all qualities associated with those metrics when developers begin coding &#8216;to&#8217; the metric.  It&#8217;s basically teaching to the test!</p>
<p>It&#8217;s refreshing to see such an intellectual giant in our field so humbly admit his faults in the past &#8211; surely many more could learn from him.  We&#8217;ve had far too many methodologies come and go while their authors seem to continue to pretend that the few good ideas encased within those methodologies are worth all the cruft that&#8217;s built up over the years.  Just like in many cases what a software project needs is a complete gut-job or rewrite, some methodologies could use the same.</p>
<p>Let&#8217;s not throw out the baby with the bathwater though.  I&#8217;m convinced that nearly every &#8216;fad&#8217; that&#8217;s appeared in the field of software HAS had some valuable things to teach us.  It&#8217;s all about keeping the good and dismissing the bad, separating diamonds from the rough.  The Waterfall method as a whole has shown to create projects drastically over schedule and over budget, but it has shown that many of our most expensive errors come from misunderstanding requirements/use cases.  Likewise, coding to metrics in and of themselves is going to get us no where.  It&#8217;s like writing until Word&#8217;s language analyzer gives me back a high &#8216;reading level&#8217; for my paper.  Word can&#8217;t analyze the content or tell whether I used the English language correctly.  But, all other things being equal, these metrics &#8211; when combined with <em>sound human judgement</em>, can make our jobs easier.</p>
<p>If I&#8217;m brought on to a failing project as a firefighter, I want to know where the flames most likely are.  I can either slowly and methodically scan over the code with my own eyes &#8211; most likely spending weeks chasing false positives or style issues (even the most disciplined of &#8216;real&#8217; developer is going to confuse style with content every now and then), or I can use a host of automated metric gathering tools to give me hints on where to start.</p>
<p>A few object oriented metrics, like various definitions of coupling and cohesion, probably would give me a good clue on where to start refactoring for maintainability.  Some good old basic metrics like line count per function or cyclomatic complexity may give me some good hints on where I ought to start tearing apart some unreadable or stagnant code.  Simple metrics like test coverage and test count would give me an eyeball figure of how brittle I should expect this code to be.</p>
<p>The point is, metrics in and of themselves say nothing about software quality.  When interpreted by a skillfull developer, they make that developer <em>that</em> much more useful and productive.  Since, as I&#8217;ve mentioned before, <a href="http://en.wikipedia.org/wiki/Amdahl%27s_law">Amdahl&#8217;s law</a> says as much about software projects as it does about software itself (namely, that any particular &#8217;solution&#8217; a software product is to solved has an optimal number of different &#8216;threads&#8217; of production, and any developers working on the project in addition to that will actually slow it down due to communication overhead), assuming we have an optimal number of developers, the only way we can speed up projects is to actually increase the speed of each individual developer rather than adding more.</p>
<p>But this is the rub, isn&#8217;t it?  In fact, hasn&#8217;t this <em>always</em> been the rub?  No one ever said metrics were all you needed, but it was in fact a misinterpretation by PHB (pointy-haired bosses) that we could automate and more easily manage software development with these metrics.  A hammer will allow a craftsman to do a lot more work than his hands alone, but also allow someone unskilled to do a lot more damage.  While the point that software is a <em>people</em> problem, not an engineering problem, is beyond the scope of this blog post, perhaps DeMarco&#8217;s later focus on the people problem and now his disemphasis on the &#8216;engineering&#8217; problem will help the community lurch (ever so slowly) towards really understanding how to build software.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=131&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/07/19/software-engineering-is-dead/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
		<item>
		<title>When do I abstract?</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/07/03/when-do-i-abstract/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/07/03/when-do-i-abstract/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 21:07:51 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=129</guid>
		<description><![CDATA[&#8220;Premature Flexibilization is the Root of whatever evil is left&#8221; takes a look at what I&#8217;ve also heard called &#8216;premature abstraction&#8217;, and in today&#8217;s high level languages, probably is on par with premature optimization for which causes the most headaches in maintenance code.
It&#8217;s also a really funny title.
First, a note about culture.  I work mostly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=129&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>&#8220;<a href="http://dev.hubspot.com/bid/7271/Premature-Flexibilization-Is-The-Root-of-Whatever-Evil-Is-Left">Premature Flexibilization is the Root of whatever evil is left</a>&#8221; takes a look at what I&#8217;ve also heard called &#8216;premature abstraction&#8217;, and in today&#8217;s high level languages, probably is on par with premature optimization for which causes the most headaches in maintenance code.</p>
<p>It&#8217;s also a really funny title.</p>
<p>First, a note about culture.  I work mostly with EE&#8217;s (electrical engineers) who <span style="text-decoration:line-through;">cut their teeth on </span>after all these years still swear by Fortran.   I&#8217;ve mentioned the odd distrust between EE&#8217;s and computer science majors:  engineers think scientists don&#8217;t know how to get real work done, while the scientist don&#8217;t believe engineers understand any of the complexity of what they build.  Ever find code that attempts to match a string by going through each character one by one against a switch statement?  That&#8217;s an engineer at work.  Ever work with a AbstractBuilderFactoryObserver that&#8217;s templated on five types?  That&#8217;s a scientist at work.  So as not to confuse these &#8217;scientists&#8217; with real scientists, I&#8217;m going to call them designers.  Engineers thrive on seeing things work, designers thrive on building them.  A designer&#8217;s work is done when she&#8217;s figured out how it should work, there&#8217;s no thrill in actually building it.  An engineer&#8217;s work is done when it&#8217;s built and he can test it.  He wants to see the capabilities of the thing when he&#8217;s done.</p>
<p>You can see that each of the major sins discussed so far, premature optimization and premature abstraction, also tend to be committed more by one community than the other.  Code that&#8217;s prematurely optimized <em>tends</em> to come from the engineer&#8217;s world, while prematurely abstracted code <em>tends</em> to come from the designer.  They each find different reasons to defend what they should know to be wrong.  Frequently I&#8217;ll hear an engineer friend tell me that he has to code in such and such way because he&#8217;s targeting an embedded system.  I&#8217;ll ask him for profile evidence, or try and reason with him that he&#8217;s avoiding a temporary variable that doesn&#8217;t appear to be in a tight loop.  I&#8217;ll try and say that the compiler&#8217;s optimization will catch what he&#8217;s trying to do.  No avail.  For the most part, he doesn&#8217;t <em>trust</em> compiler optimizations.</p>
<p>The designer will claim that she&#8217;s building with maintainability in mind, and that the alternative is cowboy coding.  She&#8217;s being rigorous, planning for change.  You might ask, &#8220;What are the use cases for this abstraction?&#8221; which usually yield something like &#8220;well, maybe we want to target a completely different OS.&#8221;  That&#8217;s true, maybe we DO want to target a different OS, but that&#8217;s not a change most projects take lightly.  More often than not, some business rule is going to change.  It&#8217;s an abstraction that&#8217;s going to cost developer time and energy for everyone who touches it, and most likely never have any pay off.</p>
<p>We all know (or we should) when to optimize.  At the design phase, we should be considering and analyzing use cases, choosing efficient data structures and algorithms.  We should draw on our experience in the field to predict certain hot spots, but not rely on this experience too much (in our rapidly changing field, experience has a pretty short shelf life).  We should be aware of free optimizations, or those that don&#8217;t sacrifice readability, when coding.  We should design with performance in mind, but realize that performance mostly comes from reducing work, rather than working more cleverly than normal.  When we finally have something built, we should stress test it to find hot spots, and then we should begin working on our &#8216;clever&#8217; approaches.</p>
<p>But it&#8217;s not chiefly taught when to abstract.  This is because, for our go-lucky computer scientists coming out of their Java schools, abstraction is still pretty fresh in everyone&#8217;s mind.  It took us about fifty years of being burned by prematurely optimized code to realize we should code first for readability and optimize later.  It is only now, with our gigantic frameworks of frameworks and systems of systems that we&#8217;re realizing we&#8217;re creating huge  spider web messes of code.  Just look at the Eclipse framework &#8211; quite a marvel of design.  Anyone can write a plug in and it WILL work, and you CAN extend or change virtually any part of it, but I&#8217;d claim that 90% of the parts of code that CAN change DON&#8217;T in any extension.  Yet each part of code that is modifiable exacts a cost on the maintenance of the system.</p>
<p>So when should we abstract?  When should we decide to use polymorphism or some other means to put a &#8216;point of inflection&#8217; in our code, a point where we can extend it?  I suspect we can derive some simple rules (indeed, many already have such as KISS and YAGNI) based more or less on the lessons of premature optimization.</p>
<p>First, in the design phase, for optimization, we take two things into account &#8211; we pick good data structures and algorithms that fit the expected usage and we let experience be our guide (to an extent).  How would this apply to abstraction?  To me, it says that our first pass of abstraction, or that which takes place during the design phase, should attempt to model the points of inflection that exist in the domain model itself.  If the domain model actually contains the classic &#8216;animal&#8217; base class, with cats and dogs being subsets, then that polymorphism certainly belongs in the code as well.  How can experience guide us?  This is where patterns come in, and a designer who&#8217;s solved similar problems before may be able to offer some insight as to what he or she expects to change in the future.  BUT, just as experience has a short shelf life in optimization, it does as well in abstraction.  Design pattern Hell is the result of searching a little too hard for these, and ultimately, experience tells us how to build the <em>last</em> system, not the next one.</p>
<p>The second point to learn from optimization is the &#8220;free optimizations&#8221;.  These include compiler optimizations, and little tips like &#8220;pass big structures by reference&#8221; and what not.  These are the idioms in the language, in addition to being the more efficient way to do things.  What &#8220;free abstractions&#8221; can we expect from our languages?  Well, first and foremost, are the abstractions the languages can get us &#8211; these are things like libraries and frameworks that are already built.  Prefer these to home-rolled solutions, as they&#8217;ve already been abstracted in many useful ways without any work on your part.  Secondly are the &#8220;best practices&#8221; and idioms that improve abstraction with very little cost to readability or understandability.  This would include popular techniques like dependency injection and preferring to pass by interface rather than concrete type.</p>
<p>The third point is that we should design with performance in mind, but the best performance boost is work avoided rather than work done cleverly.  In abstraction terms, this means that small, elegant solutions tend to, ironically, be more extensible than large abstract ones.  The best example of this might be the object hierarchy mentioned above, our &#8216;animal&#8217; base class and &#8216;cat&#8217; and &#8216;dog&#8217; concrete classes.  Well, to be extensible, we might need to have a &#8216;multithreaded_cat&#8217; and &#8216;multithreaded_dog&#8217; class as well, or maybe even a &#8216;distributed_cat&#8217; and&#8230;  But all of this avoids the original point.  We can avoid all this work in the first place by ensuring neither cat nor dog make any assumptions on the threading scheme.  That way, one hierarchy describes threading and one describes our domain and they never need meet.  We&#8217;ve avoided a whole lot of abstraction (an exponential explosion of classes) by simply designing elegantly in the first place.</p>
<p>Finally, to optimize, we measure and begin offering up some more fine tuned &#8216;clever&#8217; code where we find our hot spots are.  Similarly, in abstract code, we must <em>refactor</em> at our points of repetition.  You can get some abstraction done at design time, but much of your abstraction is only going to become apparent as you code.  You should be on constant gaurd for repetitive code, as this is a sure sign that the code should be encapsulated elsewhere.  Similar to the optimizations that mostly sacrifice readability, the abstractions found purely by refactoring tend to be the ones that are most at risk for &#8216;leaking&#8217;, or, sacrificing understandability for a point of inflection.  But, so long as we have proof that the code is used in multiple places, it will save us work in the long run.  It is these sorts of abstractions that can only be &#8216;discovered&#8217;, rather than designed in, because we are so poor at predicting what code is going to repeat itself as we develop our system.</p>
<p>Optimization and abstraction both are important parts of performing, maintainable systems, but we poor humans have shown ourselves to be poor predictors of where the tools of optimization and abstraction best be leveraged.  But we needn&#8217;t take another 50 years to learn how to best abstract.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/129/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=129&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/07/03/when-do-i-abstract/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
		<item>
		<title>My Five Things</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/05/31/my-five-things/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/05/31/my-five-things/#comments</comments>
		<pubDate>Sun, 31 May 2009 17:10:23 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=126</guid>
		<description><![CDATA[It&#8217;s the cool thing to do, after all.
First, Jesse pointed out (actually, a friend of his pointed out) that if you can&#8217;t name five things you don&#8217;t like about your favorite language, then you still don&#8217;t understand it.  I think this is a little on the liberal side, though, as most reasonable people can figure [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=126&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>It&#8217;s the cool thing to do, after all.</p>
<p>First,<a href="http://jessenoller.com/2009/05/26/a-short-list-of-things-i-dont-like-about-python/"> Jesse pointed</a> out (actually, a friend of his pointed out) that if you can&#8217;t name five things you don&#8217;t like about your favorite language, then you still don&#8217;t understand it.  I think this is a little on the liberal side, though, as most reasonable people can figure out five things they don&#8217;t like about C++ before they understand even half of it.  Of course, in that case, understanding even half of C++ is about as far as most people get <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Then was<a href="http://zedshaw.com/blog/2009-05-29.html"> Zed&#8217;s own</a> contribution to the list.  Both of these guys are very active in their communities and contribute a lot of code via libraries and projects they work on.  Neither of them is a &#8216;<a href="http://skepticalmethodologist.wordpress.com/2009/05/20/dirty-little-schemers/">dirty little schemer</a>&#8216;.  Yet now that they&#8217;ve been seen disagreeing with the politburo, the wagons have been circled and they must be torn apart with ad hominem attacks until everyone&#8217;s convinced Python&#8217;s perfect again.</p>
<p>As Jesse and Zed both tried to explain, I will as well.  I <em>love</em> the Python programming language.  It reads like pseudo-code, and is incredibly expressive.  It&#8217;s ease of incorporating C or C++ makes nearly any performance complaint moot, and the vast number of libraries out there gives it a gigantic code base to work from.</p>
<p>But, again, as Jesse said, if I thought Python was <em>perfect</em>, I&#8217;d be fooling myself.  In fact, I think it&#8217;d be an interesting challenge to hear Guido&#8217;s own list of five things he wish he could fix in Python.  GVR is hard to read, sometimes he&#8217;s incredibly reasonable, sometimes he&#8217;s a little irrational.</p>
<p>But this post is not about politics, on with the list!</p>
<p><strong>1. Static Default Args</strong></p>
<p>This gets brought up time and time again.  The arguments that you provide as defaults to functions are done at &#8216;compile-time&#8217;, and are not re-evaluated during runtime.  This means you get funny behavior like this:</p>
<pre>  &gt;&gt; def func(arg=[]):
  ::   arg.append(1)
  ::   return arg
  &gt;&gt; func()
  [1]
  &gt;&gt; func()
  [1,1]</pre>
<p>I&#8217;ve got two problems with this.  First of all, as is the classic way to shoot down ideas the community has already &#8216;decided&#8217; upon (other than the &#8216;code it yourself&#8217; comment), what exactly is the use case for this behavior?  What idioms does it allow that I&#8217;ve yet to see?  Indeed, &#8216;idiomatic&#8217; python seems to be to work around it, by using &#8216;none&#8217; as the only real default argument.  First you check for &#8216;none&#8217;, then if the arg is in fact &#8216;none&#8217;, you set it to its real default.  This is added boilerplate and, quite honestly, seems to be the default (forgive the pun) rather than the exception.</p>
<p>Another argument for the status quo is that it&#8217;s &#8216;more efficient&#8217;.  I don&#8217;t get this line of reasoning at all.  Virtually 99% of debates between &#8216;efficiency&#8217; and &#8216;readability&#8217; in Python always end up on the side of readability.  That&#8217;s why Python is Python!  Why efficiency gets a free ride in this most awkward of cases is beyond me.  Moreover, it&#8217;s not at all more efficient, as far as I can tell.  The replacement, checking for &#8216;none&#8217; and then recomputing the value at runtime is exactly the same efficiency hit as the proposed dynamic default args!  Most people are already taking the efficiency hit.</p>
<p>Indeed, it looks like this is the rare case where Python has <em>optimized for efficiency of a niche use of the language</em>, which to be blunt, is not at all Pythonic.</p>
<p><strong>2.  String Concatenation<br />
</strong></p>
<p>Most people new to a programming language are going to get a feel for the way to do things.  When you want to put two lists together, they experiment in the Python shell, try simply +&#8217;ing them together, and hey, it works.  Doing the same thing to two strings also has the same effect.  So obviously, if you need to add many strings together, you add them together like you&#8217;d add many other things together.  Wrong.</p>
<p>Instead, the &#8220;Pythonic&#8221; way to do things is to put all of your strings in a list and do the following:</p>
<pre>  &gt;&gt; "".join(myStringList)</pre>
<p>Does that at all seem obvious at first?  The joining of many strings is a method on another string?  In its defense, the string being &#8216;joined&#8217; on is the separator string.  But even that seems odd, since the separator really isn&#8217;t the &#8216;object&#8217;, in object-oriented terms, I&#8217;m worried about here.  The object is a list of strings!  The reason given by the Python community is that &#8220;&#8221;.join() is faster, and therefor preferable for large scale string processing.  While I might balk a bit at again optimizing for efficiency in Python, where everything else is optimized for consistency and readability, at least with string processing there&#8217;s a major use case for it.  Python is used for string crunching a lot, and the &#8220;&#8221;.join() construct has some specialized C routines to do it fast.</p>
<p>This brings me to a slightly tangential point, but one that really applies here.  Python is a notoriously &#8217;smart language, dumb compiler&#8217; compared to languages like C++, where it&#8217;s a &#8216;dumb language, smart compiler&#8217;.  That codifies, in other words, the constant strive for readability and intelligence in language design.  But it also implies that there&#8217;s no major drive to optimize the Python compiler.  Scripting languages are slow, and are going to continue to be slow for awhile.  Besides, Python is mostly used for things that aren&#8217;t processor bound anyway, and the FFI is good enough to drop into C whenever you need.  Why optimize?</p>
<p>But there is a particular kind of optimization that <em>enhances</em> readability as well as speeding up the execution time, called <a href="http://en.wikipedia.org/wiki/Strength_reduction">Strength Reduction</a>.  The idea is, when the compiler detects a construct that can be stated in an equivalent yet more efficient way, it replaces it behind the scenes.  That way you can still divide by two, because that&#8217;s how a human would read your algorithm, yet the compiler will go ahead and turn that into a much faster bit shift.</p>
<p>Similarly, appending multiple strings together is a pretty common operation in Python.  I still believe that the most obvious way to do this is to just repeatedly add them together.  Strength Reduction optimizations would detect this repeated addition and change it to the more efficient C routine &#8211; or hell, even an assembly routine.  GVR has been skeptical of optimizations in the past because he&#8217;s afraid they will change behavior from what the user&#8217;s expect, but in this case, behavior is entirely conserved.  Only the runtime changes.  In fact, from an optimization standpoint, Strength Reduction is <em>more</em> Pythonic since there&#8217;s far too much anecdotal evidence that the user&#8217;s original expectations is to use repeated addition rather than some special method on an empty string.  The &#8216;optimized&#8217; approach to use a library function to drop into C is not expected and is actually pretty difficult to find the first time.</p>
<p><strong>3. Non-recursive Reload</strong></p>
<p>Working with the interactive shell is awesome for someone coming from mostly compiled languages.  Getting immediate feedback allows for easy exploratory development.  At first, I was entranced by the idea of having a large code file, making incremental changes in an IDE, then reloading it in the shell and testing various procedures on it.  That is, until I realized reload does not do what one expects it do.  When you<strong> import</strong> a file, it reads the module, and imports all the things that file imports, as well as defining things in that module&#8217;s namespace, and so on.  But when you <strong>reload</strong> a file, the imports &#8211; since they&#8217;ve already taken place and are in the global namespace &#8211; are skipped.  You <em>only</em> reload the things defined in that file.  If I&#8217;ve imported Module X, and it&#8217;s imported Module Y, and I change Module Y, simply reloading X won&#8217;t do me a bit of good.  X will still point to the old version of Y.  Instead, I need to reload Y&#8230; oops, no, that doesn&#8217;t work either.  First I need to <em>import Y, and then reload it</em>.  That doesn&#8217;t make any sense at all.  How come reloading tells me it&#8217;s not loaded, yet import assumes it is.  Importing a module that has already been imported by some other module just copies the namespaces over, I&#8217;d imagine, and reload seems to absolutely depend on those namespaces.  Either way, it&#8217;s a lot more complicated than it seems at first.</p>
<p>Upon reloading a file, imports need to behave differently, and files really ought to be re-imported.  I&#8217;m sorry if this is a performance hit to you, but you really shouldn&#8217;t be using reload in a library anyway.  Reload should only be used in interactive development, in my opinion.  Python&#8217;s reload and import process is similar to other languages Make process.  Make is highly recursive, indeed, that&#8217;s often a problem since you have to nest things so oddly in esoteric Make files.  But Python&#8217;s reload doesn&#8217;t even have the functionality to go out and see whether or not it needs to re-import libraries that might have changed.  The quick fix is to always re-import libraries, the good fix would be to check their load times and their current file modification dates like a Makefile would to look for changes.</p>
<p><strong>4. Love/Hate relationship with Functional Programming</strong></p>
<p>GVR seems to maintain that Python is <em>not</em> a Functional Programming language, and that Functional Programming is not Pythonic.  This is despite the &#8216;Pythonic&#8217; list and generator comprehensions (generators are a form of &#8216;lazy evaluation&#8217;), closures, first class functions and currying.  <em>What</em>, pray tell, would make Python a Functional Programming language if not these things?</p>
<p>But this odd schizophrenia doesn&#8217;t really bother me.  It&#8217;s the casualties that get to me, namely, and yes, this one is debated again and again, neutered lambdas.  Why aren&#8217;t lambdas allowed closures like normal functions?  <em>Because Python isn&#8217;t a functional programming language</em>.  This seems like an odd excuse given all the other support for FP Python has, and it seems altogether too convenient to use whenever the Python community wants to.  Closures are ok, because those are &#8216;Pythonic&#8217;.  Lambdas, no, because Python isn&#8217;t an FP language.  I feel like I&#8217;m stuck in 1984.</p>
<p>GVR has made <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=98196">some valuable</a>, and<a href="http://neopythonic.blogspot.com/2009/04/final-words-on-tail-calls.html"> some less valuable</a>, critiques of FP.  One of the places where FP seems to muck up &#8216;Pythonicness&#8217; was in &#8216;reduce&#8217;, which is still in the language, it&#8217;s just not built-in anymore.  Folds are a major part of many FP languages, but it appears for now they&#8217;re a little too terse for most people to understand.</p>
<p>One of the criticisms of lambdas, or anonymous functions in general, is that they get abused and grow to a size in which they should be a named function to add some level of self-documentation to them.  This is fine, and I agree with it.  Lambdas in Python probably ought to remain one-liners.  But why they don&#8217;t support closures doesn&#8217;t seem at all to be covered by this line of reasoning, and indeed, they really ought to support closures or just be taken out of the language altogether.  I&#8217;ve refrained from using them because I&#8217;ve been bitten too many times by odd errors.  Why would such and odd construct be allowed &#8211; in fact, lambdas DO capture variables, they just don&#8217;t close over them.  It&#8217;s one of the weirdest scoping errors I&#8217;ve seen in a modern language.</p>
<p><strong>5. No Encapsulation</strong></p>
<p>There are obviously many differences between the way Python does OO and other languages.  It&#8217;s incredibly unpythonic, for example, to write getters and setters.  Hell, that&#8217;s just bad OO altogether.  Python provides properties for those sorts of operations.  But one thing that Python could sorely use is some explicit encapsulation protection like private, public and protected.</p>
<p>I can hear the Politburo now harping away at how such things are not at all Pythonic, how a person should be able to modify and change whatever he or she wants whenever he or she wants it.  <em>I agree</em>.</p>
<p>But private, protected and public, as well as any other encapsulation protection mechanisms  you&#8217;d like to add, add a large level of self-documentation to an API.  It is one more layer of encoding designer intent.  The best case I can give you is using the dir() command on any sufficiently large object you get from a library, or even a module.  You get a few screen fulls of non-sense and implementation defined stuff that doesn&#8217;t concern  you, and then  you have to go hunting through this giant list of operations for the one you want.  How would Python incorporate encapsulation?  Could be nothing less than a keyword.  Pass in &#8216;SeeImplementation=True&#8217; to the dir() command and you get everything, leave it off, and you get only that which the designer said was public.  When I&#8217;m doing exploratory programming, I really don&#8217;t want to explore implementation minutia which wasn&#8217;t meant for the user anyway.  I want to see what tools were explicitly given to me.  It helps with the information overload that becomes all too common when working with large API&#8217;s.</p>
<p>Much like FP, Python implicitly agrees with this statement, that a to define and communicate whether or not something is implementation or interface is important, via the _underscoreFirst coding convention.  But, in a language that strictly enforces a white space coding convention, at least compared to languages like C, it seems odd to suddenly fall back on just a &#8216;general and friendly agreement between the whole of Python programmers&#8217; that putting a _inFront of your variable or function means its implementation details and not to be trifled with.  If it&#8217;s conventional enough, why not enforce it?  Why not allow some explicit introspection rather than hand coding some hack to look for a &#8216;_&#8217; in the front of a variable to provide your own dir and other functions?</p>
<p><strong>Things that are not broken, and I agree with. </strong>(In which I try and gain the forgiveness of the Politburo for my heresies before I&#8217;m to be shot)</p>
<p>Explicit self.  I actually love this, and it&#8217;s changed the way I code in C++ to scope everything with a this-&gt; pointer to be clear.  It also makes methods and normal functions nearly the same thing, allowing you to more easily pass around methods just like you would functions (but this is NOT FP, remember, it&#8217;s Pythonic <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Not allowing implicit TCO.  TCO, despite its name, is way more than an optimization.  As said <a href="http://funcall.blogspot.com/2009/04/you-knew-id-say-something-part-ii.html">before</a>, it opens up an entirely new model of computation.  That&#8217;s hardly something I&#8217;d like to happen behind the scenes from a sufficiently smart compiler.  This is why I was an advocate of an explicit <a href="http://skepticalmethodologist.wordpress.com/2009/04/29/resolving-the-python-tco-problem/">TCO via a keyword</a>, although since I got branded a dirty little schemer (despite not knowing the language!), that idea got shot down by our good friends at the Kremlin.</p>
<p>Whitespacing.  You know how to get rid of all arguments about coding conventions?  By choosing one arbitrarily and enforcing it as apart of the language.  This and this alone has focused the Python community&#8217;s effort on much more useful things.  It also allows almost anyone to read any python code and be able to figure out it&#8217;s structure without getting a headache.  Readability <strong>does</strong> count.</p>
<p>No brackets.  Same as above &#8211; you don&#8217;t need explicit brackets if your white space shows the structure for you.</p>
<p>No doubt none of this will go anywhere.  But I thought, given the, er&#8230; &#8216;open-mindedness&#8217; of my favorite programming language&#8217;s designer community, a little extra jabbing couldn&#8217;t hurt.  For my sake, let&#8217;s hope not <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/126/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=126&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/05/31/my-five-things/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
		<item>
		<title>The Essence Of Design</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/05/29/the-essence-of-design/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/05/29/the-essence-of-design/#comments</comments>
		<pubDate>Fri, 29 May 2009 21:54:50 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=124</guid>
		<description><![CDATA[Just some notes for today.
Despite all the methodologies over the years, there are a few key topics that always re-present themselves.

Iterative Development / Rapid Prototyping

The faster you can take a solution to a problem from just someone&#8217;s vague idea to actually testing it against requirements and customer expectations, the faster you can narrow in on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=124&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Just some notes for today.</p>
<p>Despite all the methodologies over the years, there are a few key topics that always re-present themselves.</p>
<ul>
<li>Iterative Development / Rapid Prototyping</li>
</ul>
<p>The faster you can take a solution to a problem from just someone&#8217;s vague idea to actually testing it against requirements and customer expectations, the faster you can narrow in on a satisfactory system.</p>
<ul>
<li>Conceptual Integrity</li>
</ul>
<p>The more clearly it is that a solution has come from one unified idea or mind, the easier it is to extend and maintain that solution so long as extensions and maintenence don&#8217;t interfere with the unified conceptual integrity that allowed their existance in the first place.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/124/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=124&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/05/29/the-essence-of-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
		<item>
		<title>Dirty Little Schemers</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/05/20/dirty-little-schemers/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/05/20/dirty-little-schemers/#comments</comments>
		<pubDate>Wed, 20 May 2009 11:45:50 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=122</guid>
		<description><![CDATA[A post or two ago, I advocated a potential solution to adding explicit tail-call optimization(TCO) to Python.  In this forum, it seemed like a reasonably popular idea.  Hell, even reddit seemed to think it was somewhat useful, barring some grumpy old men who, to their credit, learned me a thing or two about TCO and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=122&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A post or two ago, I advocated a potential solution to adding explicit tail-call optimization(TCO) to Python.  In this forum, it seemed like a reasonably popular idea.  Hell, even reddit seemed to think it was somewhat useful, barring some grumpy old men who, to their credit, learned me a thing or two about TCO and continuations.  I proposed this to the Python ideas forum and it died.  I didn&#8217;t see why it could be so popular outside of Python, yet so dull inside.  Who was reading my blog, Schemers?</p>
<p>Really, the entire debate was a culture clash between Schemers and Pythonistas which I walked into blindly.</p>
<p>After reading the <a href="http://neopythonic.blogspot.com/2009/04/final-words-on-tail-calls.html">BDFL&#8217;s posts</a>, and the <a href="http://funcall.blogspot.com/2009/04/you-knew-id-say-something-part-ii.html">counterposts</a>, it seemed that it was a forgone solution that TCO was &#8216;useful&#8217;, just that it had problems being &#8216;pythonic&#8217;.  That is, easy to learn and consistent with the rest of the Python mental model (Ha!  Take that all of you who want a definition of Pythonic! (What&#8217;s that, you say, I&#8217;ve just moved the goal posts?  What&#8217;s the Python mental model?  Why, anything that&#8217;s Pythonic of course!)).  In a stroke of <span style="text-decoration:line-through;">genius</span>luck, and idea occurred to me that many of Guido&#8217;s criticisms could be side stepped if we just made TCO not so much of an &#8216;optimization&#8217; as an explicit part of the language.  I proposed an overloaded use of the &#8216;continue&#8217; keyword, which, after having many debates on the color of the bike shed, would probably be better stated as &#8216;return from&#8217; (to mimic yield from).  By making the syntax explicit, and checked, many of the perceived drawbacks would disappear.  The community offered solutions to the traceback problem and other details.</p>
<p>After submitting this idea to the Python ideas forum,  I was confronted with a new argument &#8211; that TCO is simply not a useful thing to have.  &#8220;There is absolutely no use case for it in Python.&#8221;  I mentioned the litany, that I had learned from others, of message passing, true unbounded recursion, state machines, even navigating websites.</p>
<p>First though, an admission.  In the practicality versus academic political leaning of languages,  I lean academic.  Whenever I see a new idea in programming, I want to try it and understand it even if I don&#8217;t have any use for it.  I have a love and passion for the stuff.  Thus, I came at the TCO debate assuming that if it could be put in the language cleanly, and there was at least SOME use for it, then the proposal should be taken seriously.  I mean, I still haven&#8217;t found a common use for coroutine generators, but that doesn&#8217;t mean there isn&#8217;t one.</p>
<p>In my opinion, there are three ways to solve problems in software.  There is breaking a problem down into smaller pieces (<em>componentization</em>), there is identifying similar patterns in the pieces and building them back up into a single construct (<em>abstraction</em>).  There is also a third way, one which is less practiced and closer to the &#8216;refactoring&#8217; ideal, and is derived from how mathematicians solve problems.  You transform the problem you have into an equivalent one in which you already know the solution.  I felt like TCO was an example, at least in Python, of the final sort of approach.  The transform/refactor approach to problem solving requires you have a large &#8216;bag of tricks&#8217; to work, since it is limited by the methods of transformation you know and the solutions you already have.  TCO was one of these solutions looking for a problem, I thought, and in time we&#8217;d forget how we got along without it all along.</p>
<p>I now want to talk about culture.  I gave a pretty bad defense of TCO because, to be quite honest, I don&#8217;t know much about it.  It&#8217;s a new idea to me, I thought I could add something to the community as an outsider to the debate via the simple explicit keyword solution.  I didn&#8217;t realize at the time that it wasn&#8217;t a debate over whether TCO should be in Python, rather it was, as frequently breaks out in our community, a religious war between programmers.  When I approached the Python community with my idea, some were skeptical, some were interested, but some were downright hostile.  To them, I was yet another dirty little Schemer in their midst trying to ruin their &#8216;perfect&#8217; programming language.  I was to be told I didn&#8217;t understand the Python way of doing things, that in Python, you didn&#8217;t need the solutions TCO provided.  And after the BDFL advocated the use of the &#8216;elegant&#8217; trampoline solution in his blog, that became dogma.  The trampoline was now to be the standard &#8216;Pythonic&#8217; solution to the problems solved by TCO.</p>
<p>There was only one problem &#8211; I don&#8217;t know Scheme.  Not a bit of it.  I&#8217;m only loosely familiar with Lisp-like languages in the first place.  I understood the basics of TCO, and understood the arguments of those who argued for it, but they were not themselves Pythonistas, but Schemers.  I listened at the table of the Schemers, and brought back what I had learn to my <em>home</em>, Python, and was treated like a Leper.  There is a large underlying hostility here that I suppose I was too naive to believe existed.</p>
<p>Fast-forward (or rewind) to the recent <a href="http://martinfowler.com/bliki/SmutOnRails.html">Ruby</a> on<a href="http://railsconf.blip.tv/file/2089545/"> Rails</a> uproar.  Two separate incidents that cause a bit of a question of just how &#8216;mature&#8217; the Rails community is.  Take everything I say with a grain of salt (read the disclaimer on the right!) as I&#8217;m very likely talking about something I&#8217;m completely ignorant of.</p>
<p>But if we didn&#8217;t do that, very few people would say anything.</p>
<p>Anyway, first there was the porn thing, then Robert C. Martin using terminology like &#8220;masculine&#8221; to describe C++ languages (&#8220;a man&#8217;s language&#8221;) and &#8220;feminine&#8221; or, worse, &#8220;insipid&#8221; to describe languages like Java.  Ironically, and hilariously to his counterpoint, he was claiming to bring professionalism to software.  Here&#8217;s a hint, Uncle Bob, if you want developers to be a profession, perhaps we should stop insulting entire genders like a bunch of cigar smoking misogynists from the 40&#8217;s.  But that&#8217;s beside the point.  (I need another snifter of brandy, damnit!  And a sammich!)</p>
<p>After critiques of these sorts of talks took place, the Ruby community for the most part reacted like a ten year old child, claiming that it was really the people who were offended&#8217;s fault for complaining in the first place.  Good way to take constructive criticism.  This was all a microcosm and a side show for what really bugged me, and what has bugged me about many of the isolated programmer cultures that develop.   The rails community continued to more or less believe they had invented programming.  This was the underlying theme of the entire debate.  When outside criticism erupted, of anything, the knee jerk reaction was to distrust outsiders, circle the wagons, and shoot first.  After all, they don&#8217;t really <em>know</em> programming like we do.  There was no openness to criticism, which is indicative that there is little sharing of information at all.  When a new idea hits Ruby on Rails, it is assumed to have been invented there by those in the community (Read: Test Driven Development).  For the most part, they are the youngest members of our overarching programmer community, and should be expected to lash out like this.  The problem is, it isn&#8217;t just them and never was.  As I showed above, even more established communities like the Schemers and the Pythonistas can jealously guard their ideas and distrust anything new.</p>
<p>In the case of the Schemers and the Pythonistas, it was the old saw that Scheme is an &#8216;academic&#8217; language and Python is a &#8216;pragmatic&#8217; language.  Which would be untrue, if it even meant anything.  What the advocates of the language are actually saying is that &#8216;only academics&#8217; use Scheme, but real programmers (pragmatic types, we) use Python.  Real programmers don&#8217;t have time to debate theory and angels on the heads of pins.  We&#8217;ve got deadlines and customers.  What could a &#8220;schemer&#8221; possibly teach us?  I believe this debate originally started, and is perpetuated primarily by the amateur programmer versus computer science major, basically the two ways to get into our field.</p>
<p>There is no &#8216;real&#8217; split here, though.  For example, take Haskell, one of the most &#8216;academic&#8217; languages and C++, never a more &#8216;pragmatic&#8217; language (although, pragmatic in another sense, i.e., runtime efficiency).  Haskell has an idea called Type Classes that, oddly enough, do the exact same thing C++ &#8216;concepts&#8217; do.  I doubt either of these two communities openly talk about how similar such &#8216;academic&#8217; and &#8216;pragmatic&#8217; languages are, because both secretly want to take credit for a structural typing idea that is sure to have been around since the 60&#8217;s (citation needed).  The point is, I can&#8217;t imagine a larger divide between communities, and yet there really is no large divide there.  The devil, quite literally as a force of hate pulling us apart, is in the details.</p>
<p>Let me finish by clearing up a few things, to anyone who will listen.  Just because you haven&#8217;t read SICP, you aren&#8217;t an idiot.  But just because you have read SICP, you aren&#8217;t necessarily a genius.  There are a whole bunch of good ideas and concepts in that book, like many of the books in our shared &#8216;cannon&#8217; (I&#8217;m working through TAOCP, I swear!).  While I disagree with Uncle Bob that we might all one day be &#8216;professionals&#8217; (or that we should be), we can certainly all be friends.  We are united by the fact that we all love and have a passion for this stuff, we should not let that passion for our particular solution, implementation or language divide us.  We have too much to learn from each other.  Python isn&#8217;t a child&#8217;s language (or, perhaps it is, but in a sense that even a child can learn it).  Haskell isn&#8217;t too dense (because, ironically, it has been taught pretty easily to children too!).  Scheme isn&#8217;t just academic, C++ isn&#8217;t THAT ugly.  And rubyists aren&#8217;t that immature.  Ok, well, some of them are, but we love them anyway <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   When it comes to programming, when it comes to what we do, what we&#8217;ve chosen to create, I&#8217;d rather have a friend by my side than a &#8216;professional&#8217; any day, even if that friend is a dirty little schemer.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=122&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/05/20/dirty-little-schemers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
		<item>
		<title>The Essense of Complexity</title>
		<link>http://skepticalmethodologist.wordpress.com/2009/05/01/the-essense-of-complexity/</link>
		<comments>http://skepticalmethodologist.wordpress.com/2009/05/01/the-essense-of-complexity/#comments</comments>
		<pubDate>Sat, 02 May 2009 01:56:32 +0000</pubDate>
		<dc:creator>austinwiltshire</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://skepticalmethodologist.wordpress.com/?p=120</guid>
		<description><![CDATA[
You&#8217;re reviewing source code.  It is a relatively small &#8216;for&#8217; loop in a procedural language, and it uses the &#8216;continue&#8217; and &#8216;break&#8217; statements.  Suddenly one of your colleagues makes a critique &#8211; “Continue and break are tantamount to gotos, and therefore are hard to understand.  You can simplify this loop by adding [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=120&subd=skepticalmethodologist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } --></p>
<p style="margin-bottom:0;font-style:normal;">You&#8217;re reviewing source code.  It is a relatively small &#8216;for&#8217; loop in a procedural language, and it uses the &#8216;continue&#8217; and &#8216;break&#8217; statements.  Suddenly one of your colleagues makes a critique &#8211; “Continue and break are tantamount to gotos, and therefore are hard to understand.  You can simplify this loop by adding a few flags and only returning in once place.”</p>
<p style="margin-bottom:0;font-style:normal;">The author is notably flustered, “Adding in those variables will make this loop less efficient!  Plus it will add needless lines of code and could introduce errors if we don&#8217;t check the flags right.” he responds.</p>
<p style="margin-bottom:0;font-style:normal;">“Your solution is too complex!” The original critic might say.</p>
<p style="margin-bottom:0;font-style:normal;">“But it&#8217;s elegant!” The author defends.</p>
<p style="margin-bottom:0;font-style:normal;">
<p style="margin-bottom:0;font-style:normal;">What is complexity?  When is a solution complex, and when is it simple?  When is it understandable?  In the context of yesterday&#8217;s conversation, when is a language feature – continuations – make a language too complex?</p>
<p style="margin-bottom:0;font-style:normal;">By complex, we usually mean &#8216;hard to understand&#8217;.  But as we&#8217;ll see, this is hardly an objective measure.  We&#8217;ve seen one example of two different ideas of complexity in the argument above, but there are others.  Some of these have been settled, so we&#8217;ll look at what Python has considered complex.</p>
<p style="margin-bottom:0;font-style:normal;">Nowadays, if you code up a huge for loop that operates on each item in a collection and builds a new collection, it&#8217;s generally recognized that a list comprehension is less complex.  Why?  A comprehension is also less complex if you&#8217;re building a new collection from an old one, but removing some members based on some predicate.</p>
<p style="margin-bottom:0;font-style:normal;">On the other hand, using another functional construct, &#8216;reduce&#8217;(fold), is considered MORE complex than the equivalent for loop that operates over the collection, except in certain cases.</p>
<p style="margin-bottom:0;font-style:normal;">Another example would be the general notion that simple logic and shallow nesting is almost always less complex than intricate logic and heavy nesting.  Should you find these things in your code, you&#8217;re supposed to break them up into smaller chunks.  Why would breaking something up somehow make it less complex – you still have to check all your flags and do all your loops?  In fact, isn&#8217;t it even more complex now that everything is spread out all over the place?</p>
<p style="margin-bottom:0;font-style:normal;">So breaking things down, even pulling things away from their context is, counter-intuitively, a way to make a program LESS complex.  What gives?  You&#8217;re giving a person LESS information about the problem, yet they understand the whole problem better?</p>
<p style="margin-bottom:0;font-style:normal;">The fewer things we have to think about, the less complex they are!  The less we have to keep in our head, the less complex it all is!</p>
<p style="margin-bottom:0;font-style:normal;">Think of your mind as having, like a computer, RAM and a hard drive.  What happens when you fill up RAM?  The OS steps in, carves out a place on the hard drive, and switches out some virtual memory.  We, like computers, only have so much RAM we can use as our working memory.  The more we have to hit our hard drive, the longer it takes us to do something.  Plus, unlike computers, we&#8217;re not all that infallible when it comes to remembering things.  We may do a look up of a certain problem on our hard drives today and come up with one answer, and then tomorrow come up with another.  Uh oh, programming bug!</p>
<p style="margin-bottom:0;font-style:normal;">How do things like list comprehensions and loop control statements help us not hit our hard drives when we&#8217;re thinking about a problem?  How does breaking a problem up keep things all in working memory?</p>
<p style="margin-bottom:0;font-style:normal;">The second statement should be obvious – the smaller our focus, the fewer things we have to keep in our heads.  We divide one large problem up into multiple small ones, plus one more.  The small ones are the modules we use to decompose the problem, while the plus one problem is the far simpler &#8216;big picture&#8217; of how these small modules work together to solve our original problem.</p>
<p style="margin-bottom:0;"><span style="font-style:normal;"> The first statement, though, reduces complexity in another way.  Think of breaking a problem up as &#8216;optimizing&#8217; the problem for our mind&#8217;s cache.  We think much quicker that way, and can keep everything in fast, working memory.  There is another option we can take when we try and shrink a problem to fit in memory and that&#8217;s </span><em>compression</em><span style="font-style:normal;">. </span></p>
<p style="margin-bottom:0;font-style:normal;">We like to zip up files because transmitting over the Internet is slow, so we want to transmit as little information as possible to the other side.  Compression takes data and eliminates as much redundancy as possible to shrink it to its smallest &#8216;essential&#8217; size.  This identification of &#8216;essential&#8217; also applies to our problem solving and programming.  We can compress ideas by identifying them by their &#8216;essential&#8217; structure, and ignoring all the extra details.  This is the process of &#8216;abstraction&#8217;.</p>
<p style="margin-bottom:0;font-style:normal;">You see, &#8216;continue&#8217; and &#8216;break&#8217; abstract away a very common loop control structure.  That means they allow a more complex loop to be stated in a simpler way.  Instead of keeping the details of exactly how the loop will continue or break in our heads, we &#8216;compress&#8217; that information away and simply mark those facts with the smaller, &#8216;essential&#8217; nature of the problem.</p>
<p style="margin-bottom:0;font-style:normal;">List comprehensions do the same thing, they boil a big problem – a loop over a collection – into a smaller one that only consists of the &#8216;essential&#8217; complexity of the problem.</p>
<p style="margin-bottom:0;font-style:normal;">But what about the critic in our example?  Surely he knows that continues and breaks reduce complexity via abstraction.  Er, don&#8217;t they?</p>
<p style="margin-bottom:0;font-style:normal;">Not necessarily.  Compression in your mind, just like on a computer, takes time.  It&#8217;s called &#8216;learning&#8217;.  We see patterns, over and over again, and only after awhile do we begin to replace the pattern with it&#8217;s &#8216;essential&#8217; nature (the parts that change).  Only after we&#8217;ve seen something many times do we begin to think about that thing as an object in itself, and then begin to try and shrink that object into its most compact form.</p>
<p style="margin-bottom:0;font-style:normal;">The critic probably was not familiar with the use of continue and break, and thus saw the continue and break solution as inherently more complex.  To him, continue and break didn&#8217;t boil down to small complex problems, but instead made the original problem even bigger.  Now, in addition to understanding what the loop DOES, the reader has to understand these esoteric control flow keywords.  That&#8217;s even more stuff to keep in your head!</p>
<p style="margin-bottom:0;"><span style="font-style:normal;"> And now comes the rub.  I call this the Teacher&#8217;s Fallacy: You tend to project your level of competence onto other people.  In other words, if you understand a subject, you frequently over-estimate how much others know.  Indeed, we&#8217;ve all been in talking to a professor or local guru, asking a question and they start answering with jargon about three levels above the question we asked.  They don&#8217;t realize they&#8217;re being incomprehensible.  They don&#8217;t know what patterns you have or have not abstracted, and the problem is, once you&#8217;ve abstracted a pattern, </span><em>you become blind to it. </em><span style="font-style:normal;"> After all, how else is your mind going to keep all that information from clouding your RAM?</span></p>
<p style="margin-bottom:0;font-style:normal;">Similarly, if you do not understand something, you tend to project that level of misunderstanding on to others.  The developer skeptical of &#8216;continue&#8217; and &#8216;break&#8217; sincerely believed that everyone else in the room also found their use as complex as he(or she) did.  He( or she) most likely believed that the author of the code was simply trying to be &#8216;clever&#8217;, and obfuscate things in an effort to show how smart they were.</p>
<p style="margin-bottom:0;font-style:normal;">So, when is a potential language feature too complex to add to the language?  People who aren&#8217;t familiar with the feature, but ARE familiar with the language, are likely to greatly over-estimate the complexity of the proposed feature.  After all, we all get complacent with our level of mastery over things.  Too often, we often see all knowledge as a single vast mountain, rather than a mountain range.  In other words, we think “Well, I understand so much about programming, and this concept is complex to even me, therefor, it must be VERY complex to someone new to the language!”  In actuality, you&#8217;re not looking at a new steep cliff near the top of your own mountain of knowledge, but rather a rather shallow grade at the bottom of someone else&#8217;s.  You&#8217;re on equal footing with many beginners, but are so used to the thin air solving your own advanced problems that you don&#8217;t recognize where you are.</p>
<p style="margin-bottom:0;"><span style="font-style:normal;"> Indeed, if continuations and functional programming were, in fact, more difficult to understand than imperative or procedural programming, you&#8217;d see a trend of students taking far longer to master the former than they do the latter.  But we don&#8217;t.  There have been projects to teach Haskell, generally conceived to be one of the more obtuse academic languages out there, to high schoolers.  And they were successful.</span></p>
<p style="margin-bottom:0;font-style:normal;">Functional programming seems hard because we&#8217;re already imperative programmers.  Good ones too!  We forgot how hard it originally was to wrap our minds around objects, around function calls, around variables and references versus values.  When we approach functional programming, we generally do so at the level of an amateur (at least, those of us new to it), but we still believe ourselves to be experts.  It will take your average smart imperative programmer about as much time as it would someone completely new to programming to &#8216;get&#8217; Lisp, Scheme or Haskell.  It&#8217;s starting all over again.</p>
<p style="margin-bottom:0;font-style:normal;">So, we&#8217;ve established that it&#8217;s very hard to judge the complexity of a new idea, because we&#8217;re so used to &#8216;getting&#8217; it so quickly.  We tend to over-estimate how hard it might be for someone else to grasp, since it&#8217;s so hard for us, and we&#8217;re, after all, the experts.</p>
<p style="margin-bottom:0;font-style:normal;">For someone arguing that continuations are too complex to put in a learning language like Python, really, the onus is on them to show that learning a stack-based function call mechanism is somehow intrinsically simpler for a person completely new to programming than a simple continuation based flow.  Until then, I&#8217;d argue that it is simple enough for anyone to grasp.  Even we expert imperative programmers <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="margin-bottom:0;"><span style="font-style:normal;"> Another major question looms, though, and that is – whatever the complexity is, is a feature or solution </span><em>useful</em><span style="font-style:normal;"> enough to justify it.  If, in our original story, we lived in an alternate dimension where loops were written so differently that really, &#8216;continue&#8217; and &#8216;break&#8217; only made sense in one or two cases throughout all code, then it would not be worth introducing those control flow mechanisms.</span></p>
<p style="margin-bottom:0;"><span style="font-style:normal;"> Learning is hard, recognizing new patterns takes time.  I don&#8217;t want to learn a new language construct if I&#8217;m never going to use it.  Then, even if it only adds a little complexity, it&#8217;s entirely </span><em>needless</em><span style="font-style:normal;"> complexity.  Even easy things should be justified.</span></p>
<p style="margin-bottom:0;font-style:normal;">There are two kinds of abstractions, though.  The first kind of abstraction is &#8216;evolved&#8217;.  It comes from repeated exposure to a pattern until we shrink that pattern into its essential form.  Once we have shrunk a few patterns, there emerge new patterns – patterns of patterns, and we continue to shrink entire systems of patterns down into their essential form.  This process continues, and these abstractions build off of each other.</p>
<p style="margin-bottom:0;font-style:normal;">The second kind of abstraction is different.  It comes out of the blue at us, from something completely unrelated.  A flash of insight, maybe.  These abstractions are &#8216;orthogonal&#8217;.  They come at us from right angles, and are usually taught rather than learned through our environment.  They are also used in a different way.  As you recall, evolved abstractions come from obvious patterns – in other words, the use of them precedes their existence.  We have a problem, and we find a solution, and now we can solve that problem again and again.  Orthogonal abstractions go the other way, presenting us with a solution.  We frequently see the problem they solve as contrived or unrelated to what we need.</p>
<p style="margin-bottom:0;"><span style="font-style:normal;"> This type of abstraction arises frequently in mathematics.  We frequently prove theorems well before we find applications for those theorems.  Math is in constant supply of solutions looking for problems, and the most frequent way to apply these new solutions is the </span><em>transformation</em><span style="font-style:normal;">.  Instead of seeing a pattern in our world and reducing it to its essential form, we see instead raw data.  No patterns.  But we can </span><em>transform</em><span style="font-style:normal;"> this raw data, this accidental complexity, into a form of which we already have a solution to.  Mathematicians frequently make progress by stepping back an </span><em>restating the problem</em><span style="font-style:normal;">. </span></p>
<p style="margin-bottom:0;font-style:normal;">We take a problem we don&#8217;t know how to solve, or one that has a messy solution, and we turn it into another problem that has an easy solution.  But the only way we can do this is if we steadily expand our solutions, our &#8216;bag of tricks&#8217;, through other means than evolution alone.  Evolution is never going to give you a solution you don&#8217;t already need, and such, your problems will always grow linearly with your solutions.  Orthogonal abstractions are the only way to really grow your bag of tricks.</p>
<p style="margin-bottom:0;"><span style="font-style:normal;"> Continuations have a few uses that have been stated multiple times.  But they still may seem like they solve a problem that&#8217;s almost as easily solved in some other way.  Are we just tacking on something to the language that doesn&#8217;t NEED to be there?  The Zen of Python is that there should be preferably one way, and only one way, to do things.  This helps the learner of the language, because when they discover a new feature, they should immediately be able to find applications.  If there is one way to do something, and a feature is in the language, then it&#8217;s abilities aren&#8217;t replicated by any other, and when you run into a problem it solves, then you&#8217;ll need it and only it.</span></p>
<p style="margin-bottom:0;font-style:normal;">But just as we said the imperative expert will misjudge the complexity of learning functional style for the newcomer, I think we&#8217;ve shown that we all are going to underestimate the usefulness of orthogonal abstractions.  They&#8217;re solutions looking for problems – why should we tack that on to the language?  In fact, such things may even be risky.  A solution today with no problem, but tomorrow we may find it solves the same problem as something we already have.  It could only be needless today, but tomorrow it could be downright redundant.  That is not Pythonic.</p>
<p style="margin-bottom:0;font-style:normal;">There is a debate in economics over whether demand drives the economy or supply.  Demand siders say we should give people what they want.  They are clearly indicating what problems they&#8217;d like solved, and we evolve solutions to those problems from stuff we already have.  Supply siders say that if you build it, they will come.  People frequently don&#8217;t know what they&#8217;re missing, or what they need.  Take the introduction of the personal computer, for example, the archetype for a completely orthogonal solution.  No one demanded a computer, no one even knew what they were.  Many were skeptical of their usefulness, yet today, obviously, they are ubiquitous.</p>
<p style="margin-bottom:0;font-style:normal;">In terms of continuations, an extended continue syntax, as an orthogonal abstraction, could very well solve problems we don&#8217;t even know we have.  Stackless Python has shown the potential of a Python with no stack, while continuations may be able to work that power into a language with the safety of a stack.  Native thread advocates constantly bemoan the GIL, yet continuations may have the potential to make efficient, expressive green threads a reality in Python, with very little legwork.  We will learn to solve many problems today by transforming them into problems continuations solve far more simply.  They are coming at us at right angles, and we never know where that will lead.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticalmethodologist.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticalmethodologist.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticalmethodologist.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticalmethodologist.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticalmethodologist.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticalmethodologist.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticalmethodologist.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticalmethodologist.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticalmethodologist.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticalmethodologist.wordpress.com/120/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=skepticalmethodologist.wordpress.com&blog=3431244&post=120&subd=skepticalmethodologist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://skepticalmethodologist.wordpress.com/2009/05/01/the-essense-of-complexity/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">austinwiltshire</media:title>
		</media:content>
	</item>
	</channel>
</rss>