<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>notes from the bigfug &#187; Programming</title>
	<atom:link href="http://www.bigfug.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bigfug.com</link>
	<description>programming light and other strange tales</description>
	<lastBuildDate>Mon, 07 Jun 2010 13:47:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dan Pink on motivation; Nietzsche on bigfug</title>
		<link>http://www.bigfug.com/2010/06/07/dan-pink-on-motivation-nietzsche-on-bigfug/</link>
		<comments>http://www.bigfug.com/2010/06/07/dan-pink-on-motivation-nietzsche-on-bigfug/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 13:47:17 +0000</pubDate>
		<dc:creator>Alex May</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[art]]></category>
		<category><![CDATA[dan pink]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[ken robinson]]></category>
		<category><![CDATA[nietzsche]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[quadratura]]></category>
		<category><![CDATA[school]]></category>
		<category><![CDATA[ted]]></category>
		<guid isPermaLink="false">http://www.bigfug.com/?p=418</guid>
		<description><![CDATA[I was reading a recent article on Coding Horror that introduced me to Dan Pink and his ideas on what motivates people in their lives, and the surprising research carried out by a range of eminent economists that would seem to prove money as an incentive for work that requires even rudimentary cognitive skills actually acts as [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading <a title="Coding Horror: The Vast and Endless Sea" href="http://www.codinghorror.com/blog/2010/06/the-vast-and-endless-sea.html" target="_blank">a recent article on Coding Horror</a> that introduced me to Dan Pink and his ideas on what motivates people in their lives, and the surprising research carried out by a range of eminent economists that would seem to prove money as an incentive for work that requires even rudimentary cognitive skills actually acts as a hindrance.</p>
<p>His TED Talk is fast paced and amusing, though the white-board animated version of his RSA talk is just fantastic.</p>
<p>In the comments that followed the Coding Horror article somebody had posted up a long quote from Nietzsche, which, following on from my last post about how programming has been so intrinsically woven into my mind and life, would seem to describe this &#8216;character trait&#8217; with no small degree of accuracy:</p>
<p><em>For [almost all men in civilized countries] work is a means and not an end in itself. Hence they are not very refined in their choice of work, if only it pays well.</em></p>
<p><em>But there are, if only rarely, men who would rather perish than work without any pleasure in their work. They are choosy, hard to satisfy, and do not care for ample rewards, if the work itself is not the reward of rewards.</em></p>
<p><em>Artists and con-templative men of all kinds belong to this rare breed, but so do even those men of leisure who spend their lives hunting, traveling, or in love affairs and adventures. All of these desire work and misery if only it is associated with pleasure, and the hardest, most difficult work if necessary. Otherwise, their idleness is resolute, even if it spells impoverishment, dishonor, and danger to life and limb.</em></p>
<p><em>They do not fear boredom as much as work without pleasure; they actually require a lot of boredom if their work is to succeed. For thinkers and all sensitive spirits, boredom is that disagreeable &#8220;windless calm&#8221; of the soul that precedes a happy voyage and cheerful winds. They have to bear it and must wait for its effect on them. Precisely this is what lesser natures cannot achieve by any means. To ward off boredom at any cost is vulgar, no less than work without pleasure.</em></p>
<p>Voila!  C&#8217;est bigfug!</p>
<p>From a fairly early age I&#8217;ve grown to accept that my noggin just doesn&#8217;t seem to work in quite the same way as most other people I meet.  Not that I consider myself close to either sane or insane, or more or less intelligent; these being comparative terms that are of little use to me or others; rather my priorities in life seem a bit skewed from the normal axis.</p>
<p>People groan when you talk about being &#8216;normal&#8217;, as though it denotes being boring.  To me, normality is having the same common basic life priorities as everyone else.  In his TED Talk, <a title="Tony Robbins asks why we do what we do" href="http://www.ted.com/talks/lang/eng/tony_robbins_asks_why_we_do_what_we_do.html" target="_blank">Tony Robbins</a> (love or hate the dear chap) talks about this: that we all generally share a few needs that build on top of each other.  Once these are mostly covered we can start thinking about aspirations such as houses and children and careers, or if you&#8217;re like me, doing wild creative and challenging nonsense at the expense of just about everything else.</p>
<p>This, then, is my brain&#8217;s departure from &#8216;normality&#8217;.  When people discuss house prices and football and two weeks in the sun for their holiday, I find myself with nothing to add other than a stream of concious adjunct babble making light of the fact that I want to hit myself in the face with a hammer rather than listen any more.</p>
<p>This is probably why I don&#8217;t get invited to many dinner parties.</p>
<p>Additionally, I feel unable in these situations to talk about what I do.  When people ask, I politely mumble something about programming and art.  This isn&#8217;t actually polite or useful and it annoys my friends who know the scope of what I do and my passion for it.</p>
<p>Well, not so much unable &#8211; perhaps a telling choice of words there &#8211; rather I recognise a powerful signal of caution and fear that I think stems from school.  As I intimated in my last post, I didn&#8217;t get on with school very well.  I was doing just fine and then I had a really horrible teacher for two years in primary school who was incredibly controlling, scary as hell, and had thin, pointy anger  lines on her face from all the screeching she did (not only to her class, I imagined she&#8217;d be standing on the church roof during a full moon berating her dark gods for hours and chewing live bats).</p>
<p>Basically, you toed the line or suffered some serious wrath.  For a young lad such as myself who loved everything creative and joking and performing daft little plays he&#8217;d written with his friends in front of the whole school (can&#8217;t imagine doing that now!), she was a gorgon who had no interest for understanding and nurturing the needs of any particular child that might be even slightly outside of the strict regimen of the school syllabus.</p>
<p>In yet another TED Talk, the fantastic <a title="Ken Robinson says schools kill creativity" href="http://www.ted.com/talks/lang/eng/ken_robinson_says_schools_kill_creativity.html" target="_blank">Ken Robinson</a> talks about this in a more generalised terms, that even now our school systems are orientated around the needs defined in the industrial revolution, where maths and English are still considered far more important than art or dance.</p>
<p>Even then, at the age of six, it seems I had already started down my path.  I was not some totally malleable mind to be shaped into a good school product.  Then, as now, I have little choice than to follow my creative proclivities.  What ever form they manifest they emanate from a burning core that wails day and night and fires off blue lightning if I do not relent to its desire to be heard.</p>
<p>Aged eight, I rebelled, discarding any respect for school forever.  Shortly after my ZX81 arrived&#8230;</p>
<p>Despite my rebellion, I realised I was obviously legally still required to go to school, and I did love seeing all my friends so there was little reason to act so badly that I would be expelled, rather I set out to accomplish the bare minimum in all subjects that did not interest me, and put all my effort into things that did.</p>
<p>This tactic required a certain grim determination.  Detentions featured regularly, including the laborious process of writing out lines.  Fortunately, the teachers often got bored and went to go sit in the staff room, at which point I would stick ten pens together with blutac so I could fill a side of A4 per minute.</p>
<p>School then became a place where my mind was almost always whirring away on other matters than the ones at hand, and despite my enormous enthusiasm for art and computers and engineering I never talked about it, rather keeping quiet to avoid detection and further ritualistic punishment and humiliation.</p>
<p>It wasn&#8217;t until I reached college and A-Levels that I believed I might finally find a forum for my excitement but within two weeks I&#8217;d pompously hauled all the art tutors into one room at the end of the day for a discussion following my realisation that we were still being taught to syllabus, rather than yet allowed off the leash, and how could this possibly be true to Art?</p>
<p>Also I didn&#8217;t turn up for the first year of my computer science course: they were busy learning binary, I was busy learning 68000 assembler instructions and C.</p>
<p>Yes, perhaps somewhat naive and arrogant but my disillusion with education was sealed and my silence gilded.</p>
<p>I should probably point out, just to be clear and also in case any of them ever chance upon this screed, that the teachers themselves were never the object of my disdain (apart from you, witch-face).  On the whole they were kind, patient, intelligent people, working under difficult conditions, and I liked a lot of them.  I profusely apologise for being such a little upstart &#8211; especially to the ones that tried so hard to bring me into the fold.</p>
<p>I mention all this to serve as illustration and demonstration of just one story of one mind, the background of further writing to come for the purpose of tearing down these old silent walls and finding the voice to tell you all, clearly and with shining laughter, of the wonderful things, and the excitement of years, so when someone asks what I do (and, to me, this question is effectively &#8216;who are you&#8217;) I will be not be able to hold back my delight and joy.</p>
<p>Not that I expect it to be any more acceptable or less bamboozling to my fellow human, rather I don&#8217;t think I care so much about exposing myself to ridicule so much any more, and besides, excitement and curiosity are boundless and  internationally recognised regardless of their origin; sharing this commonality has to be a good thing, no?</p>
<p>Still, not quite there yet; will muddle through for now&#8230;</p>
<p>Rambling through all this reminds me of the two hour talk I did in Farnham a couple of months back at UCA.  I spent the first hour giving an illustrated history of how I got to be doing what I&#8217;m doing.  It all seems rather self indulgent, although I hope my writing style at least gives it an amusing slant that will encourage readers to press on at the very least with a grim fascination to see what literary holes I can dig myself into.</p>
<p>I suppose what I&#8217;m trying to achieve by this is to work towards putting my creative output into some kind of context.</p>
<p>Recently I&#8217;ve realised that having now lived on the Internet for something like fifteen years, I have gotten far to used to seeing art, video, and software from around the world that I absorb quickly and move on, rarely spending any time looking into the background of the work or the artists and programmers that have devised it.</p>
<p>Facebook and Twitter really don&#8217;t help in this regard as there&#8217;s an almost constant supply of interesting new content being shared.  Perhaps you, or others are more in-depth than I, but it would seem a common trend given the proclivities of the YouTube generation to spend their time on that one site, creating ever more dense levels of meta content rather than reaching beyond it.</p>
<p>These online services, and many others before them, are merely loud-hailers, allowing us to pass knowledge of the existence of this work around though completely devoid of context or history.  There seems to be a growing body of study suggesting that &#8216;hyperlinks&#8217; are evil (in terms of how they effect the brain&#8217;s ability to absorb information: linear text (hey, like this big post!) is better suited for understanding, sorry Wikipedia).</p>
<p>It is my desire then to reverse this trend in myself and look at less things and find out more about them.  Unfortunately this is not always easy.  It&#8217;s often been remarked upon that there is a lack of information and documentation on the <a title="Quadratura: Unique Video Projection and Sound Design" href="http://www.quadratura.info" target="_blank">Quadratura</a> site, and I have to agree.  Unfortunately we tend to rush onto the next project without properly mopping up the last one and creating a satisfying online experience of our work.  I&#8217;m trying to get better at this.</p>
<p>Here, on (or as) bigfug, where I can drawl on as long as I like about anything I like, I suppose I&#8217;m looking to explain the background to the work that I&#8217;m doing now, both the work itself but also the underlying processes, but realising that yes, it does stem from events in my life many years ago, so, gentle reader, I feel the need to inform you of these.</p>
<p>Fortunately, now this part is out of the way, the next post will hopefully revolve around the intended subject matter.  Probably exploring the psychedelic world of programming exceptions and just how small good ideas can turn into big bad ones that brandish knives and upset your mum.</p>
<p>I thank you for your indulgence and time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bigfug.com/2010/06/07/dan-pink-on-motivation-nietzsche-on-bigfug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Source Code Layout</title>
		<link>http://www.bigfug.com/2009/12/13/source-code-layout/</link>
		<comments>http://www.bigfug.com/2009/12/13/source-code-layout/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 15:25:40 +0000</pubDate>
		<dc:creator>Alex May</dc:creator>
				<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://www.bigfug.com/2009/12/13/source-code-layout/</guid>
		<description><![CDATA[There have been several attempts to standardise the layout of source code.&#160; This is a good thing ? if everyone used the same style we would spend less time trying to figure out what a slab of code actually does, free of layout inconsistencies and interpretations (and besides, everything would be clearly commented anyway, wouldn?t [...]]]></description>
			<content:encoded><![CDATA[<p>There have been several attempts to standardise the layout of source code.&#160; This is a good thing ? if everyone used the same style we would spend less time trying to figure out what a slab of code actually does, free of layout inconsistencies and interpretations (and besides, everything would be clearly commented anyway, wouldn?t it).</p>
<p>The fact that there are several styles to choose from is an immediate oxymoron.&#160; Some styles were introduced because of limitations of the programming environment, such as writing code in 80&#215;24 character screens ala DOS or Unix.&#160; Given such limited screen size, it would seem like a good idea to ensure the maximum amount of ?code? is on-screen, rather than ?wasting? lines with single brackets and the like.</p>
<p>An example in C of ?The One True Brace Style?, a variant of K&amp;R:</p>
<pre>if (x &lt; 0) {
    printf(&quot;Negative&quot;);
    negative(x);
} else {
    printf(&quot;Positive&quot;);
    positive(x);
}</pre>
<p>According to Wikipedia, <a href="http://en.wikipedia.org/wiki/Indent_style" target="_blank">where this example comes from</a>, both the Unix and Linux kernel are written in this style.</p>
<p>Now, I don?t have a problem with such styles per se, especially if they are born from visual limitations such as low resolution displays, but given that the majority of programmers these days, including myself, will be working with high-resolution monitors, such condensed styles seem visually anti-productive, as we shall explore.</p>
<p>It should be noted that other standards, such as K&amp;R, Allman, KNF, and Whitesmith?s, provide a subtle range of more readable variations, though it is this programmer?s belief that they all still somehow miss a deeper level of visual presentation that can make code even more understandable and can be an actual aid to debugging.</p>
<p>What follows is a (somewhat terse) description of my own style of code layout that I?ve developed over the years.&#160; It is very visually based, which tends to be how my brain works.&#160; It?s also somewhat rooted in speed-reading techniques, where one develops the ability to take in large amounts of information without the struggle of reading every line of text.</p>
<p>It is also not without it?s own problems, as discussed at the end.</p>
<p>The standards mentioned above have generally been born out of the C world, however the following can be applied across a wide range of languages such as C++, PHP, Java, JavaScript, LUA, etc.</p>
<h3>Indentation</h3>
<p>Taking the C example above, we can re-write it like so:</p>
<pre>if (x &lt; 0)
{
    printf(&quot;Negative&quot;);
    negative(x);
}
else
{
    printf(&quot;Positive&quot;);
    positive(x);
}</pre>
<p>As with Allman style, the curly braces are matched up with the control statements, which serves to provide a visual clue that there is going to be some kind of optional or repetitive action to be applied to the indented blocks of code.</p>
<p>We can see the two blocks are indented by the same amount and the ?else? statement is prominent between the two blocks, all clues as to the purpose of this code.</p>
<p>At a glance we can quickly summarise these lines like so:</p>
<pre>if ( ... some condition ... )
{
    ... do some stuff ...
}
else
{
    ... do some other stuff ...
}</pre>
<p>This trivial example introduces an important concept: if the control statements are obvious we can vertically scan the code quickly and get a feel for what it?s doing without needing to get bogged down in implementation details we don?t wish to concern ourselves with.</p>
<p>It is important then, to use braces even with single statements:</p>
<pre>for( int x = 0 ; x &lt; 10 ; x++ )
{
    printf( &quot;x = %d\n&quot;, x );
}</pre>
<p>rather than </p>
<pre>for( int x = 0 ; x &lt; 10 ; x++ )
    printf( &quot;x = %d\n&quot;, x );</pre>
<h3>Whitespace</h3>
<p>To further this concept, I tend to use whitespace very differently to any of the C standards.&#160; For example, I?d write the original example as:</p>
<pre>if( x &lt; 0 )
{
    printf( &quot;Negative&quot; );
    negative( x );
}
else
{
    printf( &quot;Positive&quot; );
    positive( x );
}</pre>
<p>If the control statements are can be scanned vertically, the actual statements should be able to be scanned horizontally.&#160; By ensuring there is whitespace around every variable or value you make it easier on your eyes to pick out the parts of interest.</p>
<p>It is now also clearer that we are using the variable ?x? in the negative/positive function calls.&#160; By introducing whitespace we can see what values look visually alike rather then necessarily having to read them.&#160; If I had accidentally typed ?negative( y );? instead, it would be much more obvious than if it had been all bunched up as in ?negative(y);?.</p>
<p>You may also notice I removed the whitespace after the ?if? statement, for me this ties the horizontal bracketed condition to the ?if? rather than leaving it floating unconnected.</p>
<h3>Changes in Language Style</h3>
<p>The above guidelines work well for most general code but these days I?ve been encountering some challenges to my carefully honed model, especially within PHP and JavaScript where anonymous functions or large arrays of information need to be passed to other functions or methods.</p>
<p>Take something like this, <a href="http://www.symfony-project.org/forms/1_2/en/02-Form-Validation" target="_blank">from Symfony?s form system</a>:</p>
<pre>$this-&gt;setValidators(array(
    'name'    =&gt; new sfValidatorString(array('required' =&gt; false)),
    'email'   =&gt; new sfValidatorEmail(array(), array('invalid' =&gt; 'Email address is invalid.')),
    'subject' =&gt; new sfValidatorChoice(array('choices' =&gt; array_keys(self::$subjects))),
    'message' =&gt; new sfValidatorString(array('min_length' =&gt; 4), array(
        'required'   =&gt; 'The message field is required',
        'min_length' =&gt; 'The message &quot;%value%&quot; is too short. It must be of %min_length% characters at least.',
    )),
));</pre>
<p>If we are to apply a similar layout as described above, it will end up as something like this monster:</p>
<pre>$this-&gt;setValidators
(
    array
    (
        'name' =&gt; new sfValidatorString
        (
            array
            (
                'required' =&gt; false
            )
        ),
        'email' =&gt; new sfValidatorEmail
        (
            array
            (
            ),
            array
            (
                'invalid' =&gt; 'Email address is invalid.'
            )
        ),
        'subject' =&gt; new sfValidatorChoice
        (
            array
            (
                'choices' =&gt; array_keys( self::$subjects )
            )
        ),
        'message' =&gt; new sfValidatorString
        (
            array
            (
                'min_length' =&gt; 4
            ),
            array
            (
                'required'   =&gt; 'The message field is required',
                'min_length' =&gt; 'The message &quot;%value%&quot; is too short. It must be of %min_length% characters at least.',
            )
        ),
    )
);</pre>
<p>This introduces are mildly unpleasant side-effect where functions, constructors, and arrays are being laid out like control statements.&#160; Also, nine lines of code now take up almost a whole page! Now I?ve come full circle, back to needing some hybrid condensed version to adjust the code to layout on-screen ratio.</p>
<p>Oh, what to do?&#160; Perhaps a bigger monitor?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bigfug.com/2009/12/13/source-code-layout/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
