<?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>www.hackification.com</title>
	<atom:link href="http://www.hackification.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hackification.com</link>
	<description></description>
	<lastBuildDate>Sat, 05 Jun 2010 11:16:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Back Up And Running</title>
		<link>http://www.hackification.com/2010/06/05/back-up-and-running/</link>
		<comments>http://www.hackification.com/2010/06/05/back-up-and-running/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 11:16:35 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[cpanel]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=515</guid>
		<description><![CDATA[Following about three days of downtime, I&#8217;ve finally got my blog back up and running. I originally created hackification.com as an addon domain and WordPress installation to an existing cpanel account, which was hosting a different site. The original domain was coming up for renewal, and I decided to let it expire, since it wasn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Following about three days of downtime, I&#8217;ve finally got my blog back up and running.</p>
<p><span id="more-515"></span>I originally created hackification.com as an addon domain and WordPress installation to an existing cpanel account, which was hosting a different site. The original domain was coming up for renewal, and I decided to let it expire, since it wasn&#8217;t really doing anything much.</p>
<p>Unfortunately I&#8217;ve since found out that cpanel really doesn&#8217;t like having its primary domain changed &#8211; Fantastico basically stopped working correctly and would leave me with files with permissions set to &#8217;0000&#8242; &#8211; unmodifiable by me.</p>
<p>In the end I decided just to start again: I asked my hosting company to completely trash and recreate my hosting. I&#8217;ve now restored from backups, which is a bit of a hassle:</p>
<ol>
<li>Recreate the WordPress installation as closely as possible;</li>
<li>Import a previously exported WordPress XML file (which restores all the posts and comments);</li>
<li>Restore my &#8220;uploads&#8221; directory (which contains all the images referenced in my posts);</li>
<li>Restore various downloads directories (which contain various assets and demos);</li>
<li>Restore the custom theme I designed (the blue/orange one you can hopefully see);</li>
<li>Finally, try to remember my various WordPress and WordPress plug-in settings (particularly Akismet, since as soon as the blog went live the spam started appearing).</li>
</ol>
<p>If I had to provide advice, it would be:</p>
<ul>
<li>Backup everything, in various ways (eg WordPress export, plus entire directory dumps, plus even screenshots of settings);</li>
<li>If you&#8217;re planning to use a single cpanel to host multiple domains, make sure the primary domain is one you want to keep forever &#8211; it could even be a cheap-as-possible domain that no-one but you ever sees.</li>
</ul>
<p>I was also very lucky with my hosting company, <a href="http://www.webhosting.uk.com/" target="_blank">webhosting.uk.com</a>: I&#8217;m not paying very much (£60 per year), but they were very quick getting me back up and running, and provide good service in the evenings (which is the only time I get to work on my blog), so thanks guys.</p>
<p>As coincidence would have it, I noticed a SitePoint article regarding WordPress backups: <a href="http://articles.sitepoint.com/article/backup-your-wordpress-site" target="_blank">Keep Your Blog Safe: Back Up Your WordPress Installation</a>. Hopefully that might be of use to anyone else with a cpanel blog to manage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/06/05/back-up-and-running/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hosting Difficulties</title>
		<link>http://www.hackification.com/2010/06/04/hosting-difficulties/</link>
		<comments>http://www.hackification.com/2010/06/04/hosting-difficulties/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 14:20:27 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hackification.com/?p=4</guid>
		<description><![CDATA[I&#8217;m currently experiencing (self-inflicted) hosting difficulties. Thanks to the very helpful people at webhosting.uk.com I now have a fresh cpanel installation. I&#8217;m currently restoring from backups&#8230; hopefully the site will be back up soon.]]></description>
			<content:encoded><![CDATA[<p><strong>I&#8217;m currently experiencing (self-inflicted) hosting difficulties.</strong></p>
<p>Thanks to the very helpful people at <a href="http://www.webhosting.uk.com/" target="_blank">webhosting.uk.com</a> I now have a fresh cpanel installation.</p>
<p>I&#8217;m currently restoring from backups&#8230; hopefully the site will be back up soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/06/04/hosting-difficulties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing a VS2010 Color Scheme &#8211; Consistency, Consistency, Consistency</title>
		<link>http://www.hackification.com/2010/05/16/designing-a-vs2010-color-scheme-consistency-consistency-consistency/</link>
		<comments>http://www.hackification.com/2010/05/16/designing-a-vs2010-color-scheme-consistency-consistency-consistency/#comments</comments>
		<pubDate>Sun, 16 May 2010 19:05:53 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[colors]]></category>
		<category><![CDATA[highlighting]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=481</guid>
		<description><![CDATA[I recently found StudioStyles, a collection of Visual Studio 2010 color schemes, and it inspired me to create my own. I&#8217;ve never bothered customizing my editor colors before, but since VS2010 has an overall darker look, I thought I&#8217;d have a bash at creating a matching dark editor scheme. Looking through some of the submissions [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-503" style="margin-right: 10px;" title="Colors" src="http://www.hackification.com/wp-content/uploads/2010/05/Colors.png" alt="" width="160" height="110" />I recently found <strong><a href="http://studiostyles.info/" target="_blank">StudioStyles</a>, a collection of Visual Studio 2010 color schemes</strong>, and it inspired me to create my own. I&#8217;ve never bothered customizing my editor colors before, but since VS2010 has an overall darker look, I thought I&#8217;d have a bash at creating a matching dark editor scheme.</p>
<p><span id="more-481"></span>Looking through some of the submissions on the site, I was struck by how&#8230; well&#8230; random most of them are. Without meaning to be rude, they just look like someone went through the list, randomly assigning colors. Many many programmers believe coding and graphic design are polar opposites &#8211; that if you&#8217;re a coder, you must necessarily suffer from &#8220;programmer art&#8221;, and hence that it&#8217;s pointless to ever try to learn better design skills. <strong>I completely disagree with this diagnosis.</strong></p>
<p>I&#8217;m going to use only one design rule for this color scheme &#8211; consistency: <strong>keep similar things similar, and make different things different</strong>.</p>
<h3>Basics</h3>
<p>I&#8217;ve already decided to create a &#8220;dark&#8221; theme, so the background will be black. I also want to highlight important or dangerous elements of the source, and downplay incidental aspects. This idea will modify each of the colors chosen, and help suggest colors where there is no clear choice. Each choice will be reflected as far as is possible across many file types &#8211; for example, a C# comment should probably be the same color as an XML one, a JavaScript one, etc.</p>
<p>I&#8217;m also going to make use of color shades. I know Visual Studio has to cater for people using low-color displays, remote desktop, and those with reduced vision, but its use of primary colors leaves it looking a little dated. Color shades can be used to bring the look a little more up-to-date, and to group related elements, while still being able to distinguish between them.</p>
<h3>Comments &#8211; Green</h3>
<p>Comments have always been green in Visual Studio, and I&#8217;m going to keep them that way &#8211; a vibrant green, made bold, to catch the eye. (If comments aren&#8217;t important, then why are you writing them?) Comment hyperlinks and the text in #region blocks also match.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-483" style="border: 8px solid #000000;" title="Comments" src="http://www.hackification.com/wp-content/uploads/2010/05/Comments.png" alt="" width="400" height="128" /></p>
<h3>Literals &#8211; Blue</h3>
<p>String literals are red in the standard Visual Studio color scheme, but I wanted to reserve that color for errors and the like. In my mind strings are blue (don&#8217;t ask me why) so I&#8217;ve chosen a light blue for strings.</p>
<p>With consistency in mind, what else should match this?</p>
<ul>
<li>String literals are blue, so why not other literals, such as integers? The common color will highlight &#8220;magic values&#8221; in code.</li>
<li>We&#8217;ll need to colorize XML and HTML, so we can make attribute values blue too.</li>
<li>JavaScript and SQL obviously have literals.</li>
<li>I&#8217;ve also chosen to see CSS values as literals &#8211; they go blue too. (You could easily argue the toss about that though).</li>
</ul>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-485" style="border: solid 8px #000;" title="Code Literals" src="http://www.hackification.com/wp-content/uploads/2010/05/Literals1.png" alt="" width="400" height="66" /></p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-486" style="border: 8px solid #000000;" title="CSS Literals" src="http://www.hackification.com/wp-content/uploads/2010/05/Literals2.png" alt="" width="400" height="34" /></p>
<h3>Keywords &#8211; Gray</h3>
<p>Since the background is black, &#8216;unadorned&#8217; text will be white &#8211; a nice easy choice. How about keywords?</p>
<p>I want to make them a different color &#8211; so I can tell when I&#8217;ve typed &#8216;retrun&#8217; for the billionth time &#8211; but I don&#8217;t consider them to be &#8220;core&#8221; code. I think of them as scaffolding around my identifiers. (Perhaps I&#8217;m a LISPer at heart). I&#8217;ve chosen to keep them a neutral color, but a dimmer shade, so they fade out &#8211; hence gray.</p>
<h3>Types &#8211; Yellow/Orange</h3>
<p>Colorizing types is handy as it again allows me to see when I&#8217;ve mis-typed something. I want them to stand out (so a dim color is out), and I don&#8217;t want them confused with anything else &#8211; so reds, greens, and blues are gone. Yellows and light oranges seem a good choice &#8211; close enough to the normal white text, but sufficiently different to catch the eye. I&#8217;ve chosen a light orange for types, and highlighted interface types as yellow. (I figure that looking at how interfaces are defined and used is often a good way to understand the structure of a body of code &#8211; hence the slightly more eye-catching color).</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-493" style="border: 8px solid #000000;" title="Types" src="http://www.hackification.com/wp-content/uploads/2010/05/Types.png" alt="" width="400" height="104" /></p>
<p>(Oddly enough, this doesn&#8217;t seem to work for types in C++ &#8211; they always seem to come out white. Not sure why.)</p>
<h3>Errors, Warnings, and Oddities &#8211; Red</h3>
<p>This was an easy color to choose &#8211; red (for me) means stop and think. There are a few code constructs that I wanted to highlight as either dangerous or needing attention:</p>
<ul>
<li>Compiler errors and warnings;</li>
<li>Preprocessor directives;</li>
<li>Breakpoints.</li>
</ul>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-495" style="border: 8px solid #000000;" title="Errors" src="http://www.hackification.com/wp-content/uploads/2010/05/Errors.png" alt="" width="400" height="271" /></p>
<h3>Editor Overlays &#8211; Purple/Dark Blue</h3>
<p>Visual Studio now highlights parts of the source depending on where youyr cursor is &#8211; it highlights matching braces, and will also display all usages of the symbol at the caret. These display can change rapidly, so shouldn&#8217;t be too distracting. I&#8217;ve chosen a dark purple, which is subtly visible, but which blends in with the black background.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-498" style="border: 8px solid #000000;" title="Overlays" src="http://www.hackification.com/wp-content/uploads/2010/05/Overlays.png" alt="" width="400" height="113" /></p>
<p>We need a related color for the selection too, so I&#8217;ve chosen dark blue.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-510" style="border: 8px solid #000000;" title="Selection" src="http://www.hackification.com/wp-content/uploads/2010/05/Selection.png" alt="" width="400" height="71" /></p>
<h3>Omissions</h3>
<p>There&#8217;s still quite a few entries in the colors list I haven&#8217;t filled out &#8211; the main areas being:</p>
<ul>
<li>VB.NET;</li>
<li>XSLT</li>
<li>IntelliTrace</li>
<li>Test Coverage</li>
</ul>
<p>If you fancy addressing these omissions and sending me back an updated settings file, I&#8217;ll be happy to credit you.</p>
<h3>Conclusion &amp; Download</h3>
<p>So there you go. Obviously color schemes are very personal (and contentious). I think I&#8217;ve done a pretty good job; you might well think otherwise. Even if you don&#8217;t like this particular scheme, I hope you&#8217;ll agree that setting a few design principles in place before assigning colors can help you choose (and use) the colors effectively.</p>
<p>Sadly there&#8217;s no way to upload my settings to StudioStyles, and I&#8217;m too lazy to re-do all the work by hand. Until they allow that option, I&#8217;ll host the settings from here:</p>
<blockquote><p><strong>Download <a href="http://www.hackification.com/downloads/hackification.vssettings" target="_blank">hackification.vssettings</a></strong></p></blockquote>
<p>Save this file somewhere, then use Tools -&gt; Import and Export Settings&#8230; to merge them in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/05/16/designing-a-vs2010-color-scheme-consistency-consistency-consistency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Occasional Links &#8211; Programming Mistakes, Fixing Them, C, Pointers, and more</title>
		<link>http://www.hackification.com/2010/05/08/occasional-links-programming-mistakes-fixing-them-c-pointers-and-more/</link>
		<comments>http://www.hackification.com/2010/05/08/occasional-links-programming-mistakes-fixing-them-c-pointers-and-more/#comments</comments>
		<pubDate>Sat, 08 May 2010 19:44:53 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[humour]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=460</guid>
		<description><![CDATA[The gaps between these link articles get longer and longer. I&#8217;ve just renewed the hosting for this site, so hopefully that will encourage me to write a proper article soon. In the meantime, another collection of the best coding articles from the past month. Top 25 Most Dangerous Programming Mistakes http://www.codinghorror.com/blog/2009/01/top-25-most-dangerous-programming-mistakes.html Summary article listing the [...]]]></description>
			<content:encoded><![CDATA[<p>The gaps between these link articles get longer and longer. I&#8217;ve just renewed the hosting for this site, so hopefully that will encourage me to write a proper article soon. In the meantime, another collection of the best coding articles from the past month.</p>
<p><span id="more-460"></span></p>
<h3>Top 25 Most Dangerous Programming Mistakes</h3>
<p><a href="http://www.codinghorror.com/blog/2009/01/top-25-most-dangerous-programming-mistakes.html" target="_blank">http://www.codinghorror.com/blog/2009/01/top-25-most-dangerous-programming-mistakes.html</a></p>
<p>Summary article listing the 25 most dangerous (in terms of security impact) programming mistakes. Even if you&#8217;re aware of all of these, it&#8217;s worth re-familiarizing yourself (and your co-workers) with them.</p>
<h3>Microsoft runs fuzzing botnet, finds 1,800 Office bugs</h3>
<p><a href="http://www.computerworld.com/s/article/9174539/Microsoft_runs_fuzzing_botnet_finds_1_800_Office_bugs" target="_blank">http://www.computerworld.com/s/article/9174539/Microsoft_runs_fuzzing_botnet_finds_1_800_Office_bugs</a></p>
<p>No, not that sort of botnet. Microsoft are using a distributed computer system to generate random changes to Office files, in an attempt to discover buffer overruns and other vulnerabilities in the file format parser.</p>
<h3>Much ado about NULL: An introduction to virtual memory</h3>
<p><a href="http://blog.ksplice.com/2010/03/null-pointers-part-i/" target="_blank">http://blog.ksplice.com/2010/03/null-pointers-part-i/</a></p>
<p>Down-to-the-metal article explaining pointers, memory mapping, and virtual memory. Worth reading as it covers the basics that we rarely think about.</p>
<h3>Amazing feats of Clang Error Recovery</h3>
<p><a href="http://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.html" target="_blank">http://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.html</a></p>
<p>Clang is the new up-and-coming C/C++ open-source compiler. If you&#8217;ve ever worked with C++, you&#8217;ll know how cryptic and downright useless the error messages emitted by most compilers are. Clang is attempting to address that weakness.</p>
<h3>Good Math, Bad Pointer Math / C Is Not Assembly</h3>
<p><a href="http://james-iry.blogspot.com/2010/04/good-math-bad-pointer-math.html" target="_blank">http://james-iry.blogspot.com/2010/04/good-math-bad-pointer-math.html</a><br />
<a href="http://james-iry.blogspot.com/2010/04/c-is-not-assembly.html" target="_blank">http://james-iry.blogspot.com/2010/04/c-is-not-assembly.html</a></p>
<p>A deep-dive into the intricacies of C pointers, and how they relate to the C standard. If you&#8217;re interested in writing portable and correct C code, this is worth a read.</p>
<h3>Underscore.js</h3>
<p><a href="http://documentcloud.github.com/underscore/" target="_blank">http://documentcloud.github.com/underscore/</a></p>
<p>Not so much an article as a useful download &#8211; Underscore.js (named after the identifier used to access the functions) provides a suite of functional programming constructs for JavaScript.</p>
<h3>What’s wrong with extending the DOM</h3>
<p><a href="http://perfectionkills.com/whats-wrong-with-extending-the-dom/" target="_blank">http://perfectionkills.com/whats-wrong-with-extending-the-dom/</a></p>
<p>JavaScript allows any objects to be extended, either on a per-object or per-type basis. The popular Prototype library used this mechanism &#8211; and subsequently found it to be a bad idea. Prototype 2.0 is moving away from  this technique &#8211; read this article for a clear explanation why.</p>
<h3>The ASP.NET Web Development Horror</h3>
<p><a href="http://www.codingthewheel.com/archives/asp-net-web-development-horror" target="_blank">http://www.codingthewheel.com/archives/asp-net-web-development-horror</a></p>
<p>I&#8217;ve recently started (belatedly) playing with ASP.NET MVC 2, and it&#8217;s a breath of fresh air compared to &#8220;classic&#8221; ASP.NET. (Presumably &#8220;classic&#8221; ASP is now &#8220;classic classic ASP&#8221;). If you&#8217;ve not been able to articulate why ASP.NET wasn&#8217;t up to scratch, this well-written and funny article will help. How can you not read an article containing the phrase &#8220;tricksy little hobbits doing obscene things in the cupboards&#8221;?</p>
<h3>Use C# dynamic typing to conveniently access internals of an object</h3>
<p><a href="http://igoro.com/archive/use-c-dynamic-typing-to-conveniently-access-internals-of-an-object/" target="_blank">http://igoro.com/archive/use-c-dynamic-typing-to-conveniently-access-internals-of-an-object/</a></p>
<p>I&#8217;ve linked to Igor&#8217;s blog before &#8211; the articles are clear, well-written, and well-laid-out. This article suggests a new use for one of .NET 4.0&#8242;s new features, dynamic types.</p>
<h3>A Brief, Incomplete, and Mostly Wrong History of Programming Languages</h3>
<p><a href="http://www.cvaieee.org/html/humor/programming_history.html" target="_blank">http://www.cvaieee.org/html/humor/programming_history.html</a></p>
<p>I like to end on a light note, so here&#8217;s a couple of funnies. If you&#8217;ve ever wondered about this history of various programming languages, this article is completely incorrect.</p>
<h3>First among SQLs</h3>
<p><a href="http://www.theregister.co.uk/2010/04/20/verity_stob_sql/" target="_blank">http://www.theregister.co.uk/2010/04/20/verity_stob_sql/</a></p>
<p>If you&#8217;re ever bored at work, you can do far worse that read Verity Stob&#8217;s collection of articles. They&#8217;re tongue-in-cheek, deadpan, and scarily accurate.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/05/08/occasional-links-programming-mistakes-fixing-them-c-pointers-and-more/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Weekly Links &#8211; Microsoft, Windows Phone 7, General Coding, and a bit of humour</title>
		<link>http://www.hackification.com/2010/03/29/weekly-links-microsoft-windows-phone-7-general-coding-and-a-bit-of-humour/</link>
		<comments>http://www.hackification.com/2010/03/29/weekly-links-microsoft-windows-phone-7-general-coding-and-a-bit-of-humour/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 20:23:38 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[humour]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[windows phone 7]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=444</guid>
		<description><![CDATA[Well, technically it&#8217;s been two weeks since the last collection of links &#8211; but hey, who&#8217;s counting? Microsoft turns 35: Best, worst and most notable moments http://www.computerworld.com/s/article/print/9173238/Microsoft_turns_35_Best_worst_and_most_notable_moments An interesting look back at Microsoft&#8217;s history. Love &#8216;em or hate &#8216;em, you have to acknowledge the mark they&#8217;ve made on the IT industry. You&#8217;ll almost certainly know [...]]]></description>
			<content:encoded><![CDATA[<p>Well, technically it&#8217;s been two weeks since the last collection of links &#8211; but hey, who&#8217;s counting?</p>
<p><span id="more-444"></span></p>
<h3>Microsoft turns 35: Best, worst and most notable moments</h3>
<p><a href="http://www.computerworld.com/s/article/print/9173238/Microsoft_turns_35_Best_worst_and_most_notable_moments" target="_blank">http://www.computerworld.com/s/article/print/9173238/Microsoft_turns_35_Best_worst_and_most_notable_moments</a></p>
<p>An interesting look back at Microsoft&#8217;s history. Love &#8216;em or hate &#8216;em, you have to acknowledge the mark they&#8217;ve made on the IT industry. You&#8217;ll almost certainly know everything in this article, but it&#8217;s a nice summary all the same.</p>
<h3>Windows Phone 7 Series: the complete guide</h3>
<p><a href="http://www.engadget.com/2010/03/18/windows-phone-7-series-the-complete-guide/" target="_blank">http://www.engadget.com/2010/03/18/windows-phone-7-series-the-complete-guide/</a></p>
<p>The details of Microsoft&#8217;s upcoming mobile OS were released recently, and this is a nice summary article. The graphical appearance of the OS looks very fresh and modern &#8211; could Microsoft have turned a corner, design-wise?</p>
<h3>Building a Windows Phone 7 Twitter Application using Silverlight</h3>
<p><a href="http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone-7-twitter-application-using-silverlight.aspx" target="_blank">http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone-7-twitter-application-using-silverlight.aspx</a></p>
<p>Given the familiarity of the coding environment for Windows Phone 7, I could be tempted to wish for one, instead of wishing for an iPhone.</p>
<h3>Programming Windows Phone 7 Series</h3>
<p><a href="http://www.charlespetzold.com/phone/" target="_blank">http://www.charlespetzold.com/phone/</a></p>
<p>If like me you like to read an old-fashioned book in the bath instead of reading articles on-line, Charles Petzold is preparing one. Here&#8217;s a sneaky preview in PDF format.</p>
<h3>New, But Not So Obvious, Features in .NET 4.0</h3>
<p><a href="http://galilyou.blogspot.com/2010/03/new-but-not-so-obvious-features-in-net.html" target="_blank">http://galilyou.blogspot.com/2010/03/new-but-not-so-obvious-features-in-net.html</a></p>
<p>.NET 4 is with us, and there are plenty of new, headline features. Here&#8217;s a few that barely get a footnote &#8211; but which are interesting nonetheless.</p>
<h3>Hello from a libc-free world! (Part 1)</h3>
<p><a href="http://blog.ksplice.com/2010/03/libc-free-world/" target="_blank">http://blog.ksplice.com/2010/03/libc-free-world/</a></p>
<p>Why would a single-line program produce a larger-than-expected executable? Where does that excess baggage come from? And if you wanted to ditch the standard core libraries, how would you go about it?</p>
<h3>Visualizing Usage of the Firefox Menu Bar</h3>
<p><a href="http://blog.mozilla.com/faaborg/2010/03/23/visualizing-usage-of-the-firefox-menu-bar/" target="_blank">http://blog.mozilla.com/faaborg/2010/03/23/visualizing-usage-of-the-firefox-menu-bar/</a></p>
<h3>Interviews with Average Programmers</h3>
<p><a href="http://blogs.citytechinc.com/sanderson/?p=290" target="_blank">http://blogs.citytechinc.com/sanderson/?p=290</a></p>
<p>I&#8217;ve been reading &#8220;Coders at Work&#8221; recently, a collection of interviews with great programmers. What would an interview with a coder like you or me be like?</p>
<h3>5 Stages of Programmer Incompetence</h3>
<p><a href="http://coderoom.wordpress.com/2010/03/19/5-stages-of-programmer-incompetence/" target="_blank">http://coderoom.wordpress.com/2010/03/19/5-stages-of-programmer-incompetence/</a></p>
<p>Tongue-in-cheek article (mostly) about how we progress in the craft of coding. I can recognise aspects of myself in all of these.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/03/29/weekly-links-microsoft-windows-phone-7-general-coding-and-a-bit-of-humour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weekly Links &#8211; Static analysis, Hacking, Graphics, and Concurrency</title>
		<link>http://www.hackification.com/2010/03/15/weekly-links-static-analysis-hacking-graphics-and-concurrency/</link>
		<comments>http://www.hackification.com/2010/03/15/weekly-links-static-analysis-hacking-graphics-and-concurrency/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 19:55:38 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[mecurial]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[static analysis]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=428</guid>
		<description><![CDATA[My plan of posting links weekly hasn&#8217;t quite worked out recently &#8211; my wife gave birth to a little baby boy, Adam, a month ago, so I&#8217;ve been pretty busy. Since he&#8217;s sleeping now I figured I might be able to get a quick article in. A Few Billion Lines of Code Later: Using Static [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.hackification.com/wp-content/uploads/2010/03/adam.jpg"><img class="alignleft size-full wp-image-435" style="margin-right: 10px;" title="Adam" src="http://www.hackification.com/wp-content/uploads/2010/03/adam.jpg" alt="" width="100" height="89" /></a>My plan of posting links weekly hasn&#8217;t quite worked out recently &#8211; my wife gave birth to a little baby boy, Adam, a month ago, so I&#8217;ve been pretty busy. Since he&#8217;s sleeping now I figured I might be able to get a quick article in.</p>
<p><span id="more-428"></span></p>
<h3>A Few Billion Lines of Code Later: Using Static Analysis to Find Bugs in the Real World</h3>
<p><a href="http://cacm.acm.org/magazines/2010/2/69354-a-few-billion-lines-of-code-later/fulltext" target="_blank">http://cacm.acm.org/magazines/2010/2/69354-a-few-billion-lines-of-code-later/fulltext</a></p>
<p>This article is kind of an advert for Coverity, but it&#8217;s interesting all the same. It&#8217;s partly about their static code-analysis tool, but mainly about the social aspects of selling the software.</p>
<h3>A Big Case of &#8230;OOPS&#8230;</h3>
<p><a href="http://www.communities.hp.com/securitysoftware/blogs/rafal/archive/2010/02/25/a-big-case-of-oops.aspx" target="_blank">http://www.communities.hp.com/securitysoftware/blogs/rafal/archive/2010/02/25/a-big-case-of-oops.aspx</a></p>
<p>Is defense against SQL injection attacks important? Absolutely, but for a middle manager it&#8217;s probably an academic issue&#8230; until you see your site has been hacked, right in front of your eyes.</p>
<h3>Hg Init: a Mercurial tutorial</h3>
<p><a href="http://hginit.com/" target="_blank">http://hginit.com/</a></p>
<p>Joel Spolsky might have stopped blogging, but he&#8217;s still writing other kinds of articles. This is an excellent introduction to Mercurial, a distributed version-tracking system. OK, so you might be stuck using Visual SourceSafe at work, but a coder can dream.</p>
<h3>Processing.js</h3>
<p><a href="http://processingjs.org/" target="_blank">http://processingjs.org/</a></p>
<p>I&#8217;ve always fancied playing with Processing, the Java-based graphical environment, but the Java aspect always put me off. This is a JavaScript version, so anyone can view your creations.</p>
<h3>Home-baked graphics</h3>
<p><a href="http://bit-player.org/2010/home-baked-graphics" target="_blank">http://bit-player.org/2010/home-baked-graphics</a></p>
<p>In these days of pre-packaged charting libraries, it&#8217;s refreshing to see someone getting down to the metal (LISP and PostScript, in this case) to generate custom graphs. Why does the author bother? And where to go from there? Read for a discussion.</p>
<h3>Prefer Futures to Baked-In &#8220;Async APIs&#8221;</h3>
<p><a href="http://www.drdobbs.com/go-parallel/article/showArticle.jhtml?articleID=222301165" target="_blank">http://www.drdobbs.com/go-parallel/article/showArticle.jhtml?articleID=222301165</a></p>
<p>Very useful, very specific, and practical article about a better technique for writing APIs that expose concurrency. Recommended reading despite Dr Dobb&#8217;s in-your-face adverts and pagination.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/03/15/weekly-links-static-analysis-hacking-graphics-and-concurrency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weekly Links &#8211; node.js, Processors, Microsoft, and more</title>
		<link>http://www.hackification.com/2010/02/07/weekly-links/</link>
		<comments>http://www.hackification.com/2010/02/07/weekly-links/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 12:24:33 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=422</guid>
		<description><![CDATA[Since I&#8217;m having trouble producing full-length articles at the moment, I thought I&#8217;d try a different track to at least get some value out of my blog hosting costs. I&#8217;ll try to post a handful of links that have caught my attention each week. Comet with node.js and V8 http://amix.dk/blog/post/19484 A presentation (slideshow, no audio [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;m having trouble producing full-length articles at the moment, I thought I&#8217;d try a different track to at least get <em>some </em>value out of my blog hosting costs. I&#8217;ll try to post a handful of links that have caught my attention each week.</p>
<p><span id="more-424"></span></p>
<h3>Comet with node.js and V8</h3>
<p><a href="http://amix.dk/blog/post/19484" target="_blank">http://amix.dk/blog/post/19484</a></p>
<p>A presentation (slideshow, no audio or video) on node.js, a JavaScript web-server running on Google&#8217;s V8 engine. Very interesting concept &#8211; using an event-based system vastly simplifies the code needed to serve data. There&#8217;s plenty of discussion about node.js on the interwebs at the moment &#8211; hopefully it will grow and become more than just a curiosity.</p>
<h3>Gallery  of Processor Cache Effects</h3>
<p><a href="http://igoro.com/archive/gallery-of-processor-cache-effects/" target="_blank">http://igoro.com/archive/gallery-of-processor-cache-effects/</a></p>
<p>Interesting blog post about the effects that processor caches may have on performance. Examples are in C#, but really apply to any language.</p>
<h3>Microsoft’s Creative Destruction</h3>
<p><a href="http://www.nytimes.com/2010/02/04/opinion/04brass.html?pagewanted=1&amp;ref=opinion" target="_blank">http://www.nytimes.com/2010/02/04/opinion/04brass.html?pagewanted=1&amp;ref=opinion</a></p>
<p>Opinion piece from the NYTimes regarding Microsoft&#8217;s recent lack of innovation (at least, in the area of shiny gadgets). Written by an ex-vice-president of Microsoft.</p>
<h3>How Many Passes?</h3>
<p><a href="http://blogs.msdn.com/ericlippert/archive/2010/02/04/how-many-passes.aspx" target="_blank">http://blogs.msdn.com/ericlippert/archive/2010/02/04/how-many-passes.aspx</a></p>
<p>Summary article from Eric Lippert describing the differences between the C# compiler and a &#8220;traditional&#8221; compiler, and listing the various passes made over the symbol tree.</p>
<h3>A Deadlock Holiday</h3>
<p><a href="http://www.theregister.co.uk/2009/12/10/verity_stob/" target="_blank">http://www.theregister.co.uk/2009/12/10/verity_stob/</a></p>
<p>Very funny tongue-in-cheek article about the current state of parallel / multicore coding techniques, from Verity Stob of The Register.</p>
<h3>A Maturity Model for Source Control</h3>
<p><a href="http://lucas-ward.blogspot.com/2010/02/maturity-model-for-source-control-scmm.html" target="_blank">http://lucas-ward.blogspot.com/2010/02/maturity-model-for-source-control-scmm.html</a></p>
<p>Semi-opinion piece assigning levels to types of source-control systems &#8211; from &#8220;No SCM&#8221; through &#8220;Clunky&#8221; to &#8220;Speedy,  Invisible, and Highly Capable&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/02/07/weekly-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.less &#8211; Dot Less Dynamic CSS Processor for .NET</title>
		<link>http://www.hackification.com/2010/01/17/less-dot-less-dynamic-css-processor-for-net/</link>
		<comments>http://www.hackification.com/2010/01/17/less-dot-less-dynamic-css-processor-for-net/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 18:49:26 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[less]]></category>
		<category><![CDATA[stylesheets]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=377</guid>
		<description><![CDATA[Of the three textual formats that make up the main pillars of web development (HTML, CSS, and JavaScript), CSS has had the least attention in terms of server-side processing. HTML is obviously well covered, with frameworks such as ASP.NET. JavaScript is starting to be covered with compilers such as Google&#8217;s Closure Tools. Until now however [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-379" style="margin-right: 10px;" title=".less" src="http://www.hackification.com/wp-content/uploads/2010/01/dotless.jpg" alt=".less logo" width="131" height="69" />Of the three textual formats that make up the main pillars of web development (HTML, CSS, and JavaScript), CSS has had the least attention in terms of server-side processing. HTML is obviously well covered, with frameworks such as ASP.NET. JavaScript is starting to be covered with compilers such as <a title="Closure Tools - Google Code" href="http://code.google.com/closure/" target="_blank">Google&#8217;s Closure Tools</a>. Until now however (in the .NET world at least), there haven&#8217;t really been any CSS processors.</p>
<p><span id="more-377"></span>Luckily, that is now changing with the recent release of <a title="Less Css for .NET" href="http://www.dotlesscss.com/" target="_blank">.less (Dot Less)</a>. This is a port of the Ruby LESS library to .NET. It&#8217;s still in beta, so be warned that the API is still in a certain amount of flux. (That&#8217;s a good thing however &#8211; I&#8217;d rather have a bit of pain in the beta stage, in return for a well-thought-out API later on). The authors are very responsive &#8211; there&#8217;s a friendly <a title="DotLess (Less Css for .NET) | Google Groups" href="http://groups.google.com/group/dotless" target="_blank">discussion group</a> &#8211; and the couple of bugs I&#8217;ve reported have been fixed within a very short time frame. This project seems to be in very active development, and I&#8217;m extremely impressed with it. It&#8217;s so simple to use, and gives CSS development a much-needed shot in the arm, that using this library seems a no-brainer decision to me.</p>
<p>So what benefits does this library give you? (Examples are taken from the .less homepage).</p>
<h3>1. Minification</h3>
<p>The final output from .less is a compacted (or minified) version. This means you can write your CSS with as many comments and whitespace as you like, without worrying that the client-side download will be huge. This might seem like a &#8220;meh&#8221; feature, but it&#8217;s free and will have immediate beneficial effects on your bandwidth.</p>
<h3>2. Variables</h3>
<p>CSS doesn&#8217;t support any form of variables or macros, so constants (the worst culprit being colours) get copied around the CSS file. That&#8217;s fine until you decide that the pink-on-orange colour scheme isn&#8217;t working, and you need to make a change. .less allows you to define variables using the syntax &#8220;@name: value&#8221;, and then reference them anywhere a value would otherwise be used.</p>
<p>Example:</p>
<pre>@brand_color: #4D926F;

#header {
  color: @brand_color;
}

h2 {
  color: @brand_color;
}</pre>
<h3>3. Mixins</h3>
<p>We&#8217;re now in a second round of &#8220;browser wars&#8221;, with modern browsers providing useful features such as border-radius via non-standard extensions. We also have to cope with Internet Explorer still making use of odd syntax for features such as opacity (via filter). The upshot of this is that to define certain CSS effects, we have to provide three or four CSS style properties, to cover various browsers. Mixins allow this bloat to be ameliorated by defining a class with the desired properties, and then &#8220;mixing&#8221; them into another class.</p>
<p>Example:</p>
<pre>.rounded_corners {
  -moz-border-radius: 8px;
  -webkit-border-radius: 8px;
  border-radius: 8px;
}

#header {
  .rounded_corners;
}

#footer {
  .rounded_corners;
}</pre>
<h3>4. Nested Rules</h3>
<p>This feature is probably of least interest to me, since I favour single-line rule formatting, however if you write multi-line rules, then this could be a very useful feature. Nested rules allow &#8220;inheritance&#8221; of CSS rules, such that more specific rules may be nested within a less-specific parent rule.</p>
<p>Example:</p>
<pre>#header {
  color: red;
  a {
       font-weight: bold;
       text-decoration: none;
    }
}</pre>
<p>I could possibly see myself using it for :hover rules and the like.</p>
<h3>5. Operations</h3>
<p>Since I&#8217;m merging .less into an existing codebase, I haven&#8217;t yet refactored my CSS to make use of this feature. Operations allow arithmetic to be performed on expressions involving variables. For example, instead of defining variables for a colour and its lighter equivalent, you can instead just define a variable for the colour, and then computer the lighter colour.</p>
<p>Example:</p>
<pre>@the-border: 1px;
@base-color: #111;

#header {
  color: @base-color * 3;
  border-left: @the-border;
  border-right: @the-border * 2;
}

#footer {
  color: (@base-color + #111) * 1.5;
}</pre>
<h3>Alternative Usage</h3>
<p>The homepage gives instructions for a quick-up-and-running scenario, however I already had code to handle caching and combining of stylesheets, so I wanted to hook into that. It&#8217;s easily possible to process CSS as strings if desired:</p>
<pre>// .less format CSS as string in 'input'.
var dotLessEngine = new dotless.Core.engine.ExtensibleEngineImpl( input );

// Transformed CSS now in 'css'.
var css = dotLessEngine.Css;

// Now minify...
var dotlessMinifier = new dotless.Core.minifier.Processor( css );

// Output CSS suitable for sending to client in 'output'.
var output = new string( dotlessMinifier.Output );</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/01/17/less-dot-less-dynamic-css-processor-for-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#039;Smart and Gets Things Done&#039; vs &#039;Done and Gets Things Smart&#039;</title>
		<link>http://www.hackification.com/2010/01/10/smart-and-gets-things-done-vs-done-and-gets-things-smart/</link>
		<comments>http://www.hackification.com/2010/01/10/smart-and-gets-things-done-vs-done-and-gets-things-smart/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 19:10:47 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[articles]]></category>
		<category><![CDATA[hiring]]></category>
		<category><![CDATA[recruitment]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=351</guid>
		<description><![CDATA[In this article I link to two excellent articles on the subject of hiring coders. They&#8217;re not new by any means, but if you haven&#8217;t read one or both of them, I thoroughly recommend them. (If you&#8217;re familiar with both these writers, then skip this article.) Smart, and Gets Things Done Joel Spolsky&#8217;s 2006 article [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I link to two excellent articles on the subject of hiring coders. They&#8217;re not new by any means, but if you haven&#8217;t read one or both of them, I thoroughly recommend them. (If you&#8217;re familiar with both these writers, then skip this article.)</p>
<p><span id="more-351"></span></p>
<h3>Smart, and Gets Things Done</h3>
<p><a href="http://www.hackification.com/wp-content/uploads/2010/01/spolsky.jpg"><img class="alignleft size-full wp-image-363" style="margin-right: 10px;" title="Joel Spolsky" src="http://www.hackification.com/wp-content/uploads/2010/01/spolsky.jpg" alt="" width="130" height="87" /></a>Joel Spolsky&#8217;s 2006 article &#8220;The Guerrilla Guide to Interviewing&#8221; is a real classic that&#8217;s since been made into a book. He argues that there are two things to look for when interviewing, and that a candidate needs to have both attributes &#8211; having just one is as bad as having neither.</p>
<blockquote><p>&#8220;Everybody gives lip service to the idea that people are the most important part of a software project, but nobody is quite sure what you can <em>do</em> about it. The very first thing you have to do right if you want to have good programmers is to <em>hire</em> the right programmers, and that means you have to be able to figure out who the right programmers <em>are</em>, and this is usually done in the interview process.&#8221;</p></blockquote>
<p>Read Joel&#8217;s Article: <strong><a title="The Guerrilla Guide to Interviewing (version 3.0)" href="http://www.joelonsoftware.com/articles/GuerrillaInterviewing3.html" target="_blank">The Guerrilla Guide to Interviewing (version 3.0)</a></strong></p>
<h3>Done, and Gets Things Smart</h3>
<p><a href="http://www.hackification.com/wp-content/uploads/2010/01/yegge.jpg"><img class="alignleft size-full wp-image-364" style="margin-right: 10px;" title="Steve Yegge" src="http://www.hackification.com/wp-content/uploads/2010/01/yegge.jpg" alt="" width="130" height="87" /></a>Steve Yegge&#8217;s 2008 response article reminds us that recognising smarts (in ourselves and others) isn&#8217;t even necessarily possible. He suggests that the best approach to hiring is finding &#8220;seed&#8221; employees (although obviously being able to identify them is a Catch-22 situation). To find them you either need to be lucky, or perhaps home in on them via word of mouth.</p>
<blockquote><p>&#8220;How do you hire someone who&#8217;s smarter than you?  How do you <em>tell</em> if someone&#8217;s smarter than you? This is a problem I&#8217;ve thought about, over nearly twenty years of interviewing, and it appears that the answer is: you can&#8217;t. You just have to get lucky.&#8221;</p></blockquote>
<p>Read Steve&#8217;s Article: <strong><a title="Done, and Gets Things Smart" href="http://steve-yegge.blogspot.com/2008/06/done-and-gets-things-smart.html" target="_blank">Done, and Gets Things Smart</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/01/10/smart-and-gets-things-done-vs-done-and-gets-things-smart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Avoid Enums If Possible</title>
		<link>http://www.hackification.com/2009/12/01/quick-tip-avoid-enums-if-possible/</link>
		<comments>http://www.hackification.com/2009/12/01/quick-tip-avoid-enums-if-possible/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 18:16:43 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[enums]]></category>
		<category><![CDATA[oo]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=330</guid>
		<description><![CDATA[One of the &#8220;anti-patterns&#8221; I come across from time to time is over-use of enumerations for control flow. This article describes why I consider it an anti-pattern, and how to counteract it. Let&#8217;s suppose we want to represent an arithmetic operation on two numbers &#8211; such as plus, minus, multiply, etc. We could represent that [...]]]></description>
			<content:encoded><![CDATA[<p>One of the &#8220;anti-patterns&#8221; I come across from time to time is over-use of enumerations for control flow. This article describes why I consider it an anti-pattern, and how to counteract it.</p>
<p><span id="more-330"></span>Let&#8217;s suppose we want to represent an arithmetic operation on two numbers &#8211; such as plus, minus, multiply, etc. We could represent that operation as an enum (although to be clear &#8211; I don&#8217;t think you should):</p>
<pre>enum ArithmeticOperation
{
  Add,
  Subtract,
  Multiply,
  Divide
}</pre>
<p>We could then define a function to apply this operation to two numbers (highlighting will be explained later):</p>
<pre>int ApplyOperation(ArithmeticOperation op, int x, int y)
{
  switch(op)
  {
    <span style="color: #ffff00;">case ArithmeticOperation.Add: return x + y;</span>
    case ArithmeticOperation.Subtract: return x - y;
    case ArithmeticOperation.Multiply: return x * y;
    case ArithmeticOperation.Divide: return x / y;
    default: throw new InvalidOperationException();
  }
}</pre>
<p>That&#8217;s&#8230; sort of fine &#8211; but what happens when we want to extend it?</p>
<p><strong>Adding Operators: No Compile-Time Checking</strong></p>
<p>Let&#8217;s consider what happens if we want to add another operator &#8211; say exponentiation. If we add the enum value but forget to implement the switch case value, everything compiles fine. It&#8217;s only once we come to run the code, and actually hit that code path, that we discover the mistake, giving a run-time exception.</p>
<p><strong>Adding Methods: Bad Code Organisation</strong></p>
<p>Next, imagine what happens if we need to add more methods that switch on this enum. We might need a method returning the operator symbol, and another returning the operator precedence.</p>
<pre>string GetOperatorSymbol(ArithmeticOperation op)
{
  switch(op)
  {
    <span style="color: #ffff00;">case ArithmeticOperation.Add: return "+";</span>
    case ArithmeticOperation.Subtract: return "-";
    case ArithmeticOperation.Multiply: return "*";
    case ArithmeticOperation.Divide: return "/";
    default: throw new InvalidOperationException();
  }
}

int GetOperatorPrecedence(ArithmeticOperation op)
{
  switch(op)
  {
    <span style="color: #ffff00;">case ArithmeticOperation.Add: return 10;</span>
    case ArithmeticOperation.Subtract: return 10;
    case ArithmeticOperation.Multiply: return 20;
    case ArithmeticOperation.Divide: return 20;
    default: throw new InvalidOperationException();
  }
}</pre>
<p>I&#8217;ve highighted the relevant code for the &#8220;add&#8221; operator. Notice how it&#8217;s spread all over the place. Switch statements might group by operation, but they split by concept &#8211; and that&#8217;s the exact opposite of what&#8217;s usually intended with OO coding.</p>
<p><strong>A Better Way</strong></p>
<p>I&#8217;d suggest a better way of approaching this problem is to use an abstract class.</p>
<pre>abstract class ArithmeticOperation
{
  abstract int ApplyOperation(int x, int y);
  abstract string GetSymbol();
  abstract int GetPrecendence();
}

class AddArithmeticOperation : ArithmeticOperation
{
  override int ApplyOperation(int x, int y)
  {
    return x + y;
  }

  override string GetSymbol()
  {
    return "+";
  }

  override int GetPrecedence()
  {
    return 10;
  }
}

// ...and so forth for the other operators.</pre>
<p>That way, all the code for each operator sits in the same place, and adding any new methods for an operator requires all operators to be implemented before the code will even compile.</p>
<p><strong>When to Use Enums</strong></p>
<p>So if enums should be avoided, why do most languages include them? Personally I&#8217;d be happy without them,  but I can think of one possible reason you might want to use an enum. If you&#8217;re defining a public interface designed for consumption by other coders, you could argue that simplifying the interface at the expense of the code inside is a valid trade-off.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2009/12/01/quick-tip-avoid-enums-if-possible/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
