<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Hackification.com</title>
	
	<link>http://www.hackification.com</link>
	<description>Rediscover the joy of coding</description>
	<lastBuildDate>Thu, 29 Sep 2011 19:11:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Hackification" /><feedburner:info uri="hackification" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Project Euler</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/Yj1qELP3Wkw/</link>
		<comments>http://www.hackification.com/2011/09/29/project-euler/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 19:11:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[euler]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=562</guid>
		<description><![CDATA[Since they&#8217;ve just revamped their website, I thought it was probably about time I mentioned Project Euler. Project Euler is a collection of maths-based puzzles which can be solved programmatically, ranging in difficulty from easy to &#8220;very&#8221;. I&#8217;ve been using them to teach myself Haskell. For example, problem 1 (a very easy problem) involves summing [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" style="margin-right: 10px;" src="http://projecteuler.net/profile/stusmith.png" alt="" width="200" height="60" /> Since they&#8217;ve just revamped their website, I thought it was probably about time I mentioned <a title="Project Euler" href="http://projecteuler.net/" target="_blank">Project Euler</a>.</p>
<p><span id="more-562"></span>Project Euler is a collection of maths-based puzzles which can be solved programmatically, ranging in difficulty from easy to &#8220;very&#8221;. I&#8217;ve been using them to teach myself Haskell.</p>
<p>For example, <a href="http://projecteuler.net/problem=1" target="_blank">problem 1</a> (a very easy problem) involves summing all the multiples of 3 and 5 below 1000:</p>
<pre>main = print $ sum $ filter match [1..999]
  where match x = x `mod` 3 == 0
               || x `mod` 5 == 0</pre>
<p>All problems have a &#8220;one minute rule&#8221; &#8211; all solutions should be computable using less than one minute of a standard PC&#8217;s time. Each solution results in an integer value, which is used to determine whether your solution is correct or not.</p>
<p>Many of the problems seem simple, but turn out to be too large to solve with a &#8220;brute-force&#8221; approach &#8211; a clever algorithm is required &#8211; and that &#8220;aha&#8221; moment when you finally figure it out is very satisfying.</p>
<p>In summary: if you enjoy problem-solving, or want a series of puzzles with which to learn a new language, I thoroughly recommend <a href="http://projecteuler.net/" target="_blank">Project Euler</a>.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/0cdJsLxYbhhdaJlU7sKQZQk6IMQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/0cdJsLxYbhhdaJlU7sKQZQk6IMQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/0cdJsLxYbhhdaJlU7sKQZQk6IMQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/0cdJsLxYbhhdaJlU7sKQZQk6IMQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/Yj1qELP3Wkw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2011/09/29/project-euler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.hackification.com/2011/09/29/project-euler/</feedburner:origLink></item>
		<item>
		<title>Hacked</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/7L62AtSxPHE/</link>
		<comments>http://www.hackification.com/2011/02/15/hacked/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 20:01:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=512</guid>
		<description><![CDATA[Well, this site got hacked, and all content deleted. Bizarrely they didn&#8217;t do anything with it once they had trashed it, just moved on to the next target. Seems like a rather nerdy trainspotting approach to hacking, but there you go &#8211; there&#8217;s no accounting for imbeciles. Perhaps they objected to me trying to share [...]]]></description>
			<content:encoded><![CDATA[<p>Well, this site got hacked, and all content deleted. Bizarrely they didn&#8217;t do anything with it once they had trashed it, just moved on to the next target. Seems like a rather nerdy trainspotting approach to hacking, but there you go &#8211; there&#8217;s no accounting for imbeciles. Perhaps they objected to me trying to share my interests, or perhaps the £20 I&#8217;ve made from adverts in the last year is just gross profiteering.</p>
<p><span id="more-512"></span>Sadly I don&#8217;t have backups any newer than May 2010, so a few articles and comments are gone. It&#8217;s been a busy year. A new baby doesn&#8217;t leave much time for anything, and maintaining a blog that I didn&#8217;t think was even worth hacking wasn&#8217;t high on my list.</p>
<p>So&#8230;. don&#8217;t expect any posts for a while. Blogging takes enthusiasm, and I&#8217;ve none left.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/N6NaOLPOcYKL_A2qGCq2U4dptnk/0/da"><img src="http://feedads.g.doubleclick.net/~a/N6NaOLPOcYKL_A2qGCq2U4dptnk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/N6NaOLPOcYKL_A2qGCq2U4dptnk/1/da"><img src="http://feedads.g.doubleclick.net/~a/N6NaOLPOcYKL_A2qGCq2U4dptnk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/7L62AtSxPHE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2011/02/15/hacked/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.hackification.com/2011/02/15/hacked/</feedburner:origLink></item>
		<item>
		<title>Rendering the Mandelbrot Set using Haskell and wxWidgets</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/tKl8ljlj2X8/</link>
		<comments>http://www.hackification.com/2010/12/27/rendering-the-mandelbrot-set-using-haskell-and-wxwidgets/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 12:11:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=526</guid>
		<description><![CDATA[In this article I’ll show how to render the Mandelbrot set using Haskell, displayed in a window using wxWidgets / wxHaskell. Note: The code I’ve written here makes no attempt to be fast. In fact, the code I present here is a lot slower than the version I originally wrote, because I’ve decided to go [...]]]></description>
			<content:encoded><![CDATA[<div>
<a href="http://www.hackification.com/wp-content/uploads/2010/12/Screenshot-1.png"><img class="alignleft size-thumbnail wp-image-609" style="margin-right: 10px;" title="Mandelbrot Set" src="http://www.hackification.com/wp-content/uploads/2010/12/Screenshot-1-150x150.png" alt="" width="160" height="160" /></a><br />
In this article I’ll show how to render the Mandelbrot set using Haskell, displayed in a window using wxWidgets / wxHaskell.<br />
<span id="more-526"></span></p>
<blockquote><p><strong><em>Note: </em></strong><em>The code I’ve  written here makes no attempt to be fast. In fact, the code I present  here is a lot slower than the version I originally wrote, because I’ve  decided to go for code simplicity. I’ll note any particularly slow bits  of the code as I go along, but please don’t think the lack of  performance is due to the language used.</em></p></blockquote>
<p>I’m going to present this code backwards – starting from the bottom-most function, and working my way towards main.</p>
<p>The <a href="http://en.wikipedia.org/wiki/Mandelbrot_set" target="_blank">Mandelbrot Set</a> is (in simplified terms) a way of categorizing points in the  two-dimensional complex plane: some points are in the set, and some  points are not. In the image above, the black pixels are in the  Mandelbrot set.</p>
<p>The algorithm I’ve chosen to render the Mandelbrot set is the escape  algorithm, which is probabilistic – it determines that points are likely  to be in the set (or not), but it cannot say for certain. We must pick a  trade-off between performance and accuracy.</p>
<pre>import Data.Complex

mandelbrot c
    = iterate 0 0
  where iterate z i
            | i &gt; maxIterations = Nothing
            | magnitude z &gt; 2   = Just (i / maxIterations)
            | otherwise         = iterate (z^2 + c) (i+1)
        maxIterations = 100</pre>
<p>Given a point <strong>c</strong> on the complex plain, we keep  iterating until its distance from the origin is greater than two, or  until we reach a set limit. If we reach the limit of <strong>maxIterations</strong>, we mark the point as being in the set, and return <strong>Nothing</strong>. If we escape, we return <strong>Just N</strong>, where <strong>N</strong> is a scaled value indicating the number of iterations required to escape. Strictly speaking, that number <strong>N</strong> is irrelevant to the set, but it allows us to draw pretty colors around the set. On each iteration, we set <strong>z’</strong> to be <strong>z<sup>2</sup> + c</strong>.</p>
<blockquote><p><em>Performance Note: Taking the magnitude of the current  complex value is a very slow way of working out whether we’ve escaped  or not – a much better way would be to escape if the absolute value of  either the real or imaginary parts of the value exceed two.</em></p></blockquote>
<p>Now that we can compute a value for any point on the complex plain, we’ll need to convert it to an RGB value.</p>
<pre>import Graphics.UI.WX

toColor Nothing
    = rgb 0 0 0
toColor (Just i)
    = rgb r g b
  where r        = toByte (i * i)
        g        = toByte (i * i)
        b        = toByte (sqrt i)
        toByte d = floor  (d * 255)</pre>
<p>Points in the set (Nothing) are colored black, while points not in  the set are given a color ranging from white to blue, by squaring or  square-rooting the scaled iteration count for each of the red, green,  and blue components.</p>
<blockquote><p><em>Performance Note: Again, using a square-root function  here is very slow. It would be far better to use some form of  lookup-table to assign colors.</em></p></blockquote>
<p>When I wrote the original version of this program, the output  appeared very pixellated. I decided to add 4x anti-aliasing to smooth  things out a bit. Essentially, for each point in the image, I pick four  sub-pixel points, get the color for each, then average them.</p>
<pre>colorMandelbrot aa (x,y)
    = averageColors $ map color aa
  where color (ax,ay) = toColor $ mandelbrot ((x + ax) :+ (y + ay))

averageColors cs
    = rgb (tx colorRed  )
          (tx colorGreen)
          (tx colorBlue )
  where tx f = (sum $ map f cs) `div` length cs</pre>
<p>The <strong>colorMandelbrot</strong> function takes a list of offsets  for anti-aliasing, as well as an x-y point in the complex plane. That  gets converted to a complex number using the ‘<strong>:+</strong>‘ constructor.</p>
<p>Picking anti-alias offsets makes use of the scaling function. It  picks arbitrary neighbour pixels, and scales them to find the actual  distance between them. I’ve hard-coded the zoom and translation  parameters here to show the whole set, but you could tweak them to  display different parts off the set.</p>
<pre>import Control.Applicative

antialias w h
    = (,) &lt;$&gt; [-xo,xo] &lt;*&gt; [-yo,yo]
  where (x0,y0) = scale 0 0 w h
        (x1,y1) = scale 1 1 w h
        xo      = (x1-x0) / 3
        yo      = (y1-y0) / 3

scale x y w h
    = ( dbl (x - w `div` 2) / 100.0 / zoom + offsetX
      , dbl (y - h `div` 2) / 100.0 / zoom + offsetY )
  where dbl v   = fromIntegral v
        zoom    =  1.8
        offsetX = -0.5
        offsetY =  0.0
</pre>
<p>The operators ‘<strong>&lt;$&gt;</strong>‘ and ‘<strong>&lt;*&gt;</strong>‘  are just being used here to produce combinations of coordinates – a  list comprehension or ‘do’ block would have worked just as well.</p>
<p>As we move up the code, we move away from the mathematical  description of the set, towards the messy realities of actually drawing  it in a window. I’m going to render the set as a bitmap, and to create  that bitmap, I need to create a stream of color data. I’ll create the  color data from a stream of coordinate data.</p>
<pre>bitmapOrderCoordinates w h
    = map ( \(y,x) -&gt; scale x y w h) $ (,) &lt;$&gt; [1..h] &lt;*&gt; [1..w]</pre>
<p>For a given bitmap width and height, this function gives a list of the actual complex plane coordinates to color. The <strong>x</strong> and <strong>y</strong> values might seem like they’re the wrong way around, but that’s necessary to get the data stream order correct.</p>
<p>Finally, I can actually create the bitmap:</p>
<pre>createImage sz
    = imageCreateFromPixels sz $ map (colorMandelbrot aa) coords
  where coords = bitmapOrderCoordinates w h
        aa     = antialias w h
        w      = sizeW sz
        h      = sizeH sz</pre>
<p>So I now have a bitmap ready to be drawn. For simplicity, I’m just going to draw it to a fixed-size window.</p>
<pre>main
    = start mainWindow

mainWindow
    = do f &lt;- frameFixed [text     := "Mandelbrot Set"]
         p &lt;- panel f    [on paint := onPaint]
         set f           [layout   := minsize (sz 600 500)
                                            $ widget p]

onPaint dc rect
    = do img &lt;- createImage $ rectSize rect
         drawImage dc img pointZero []</pre>
<p>So there we go. Fancy improving my code? Here’s a few ideas:</p>
<ul>
<li>See just how fast you can make this code.</li>
<li>Allow the user to resize the main window.</li>
<li>Allow the user to zoom in/out and pan around – possibly add some controls to allow this.</li>
<li>Fix the application not responding while rendering the set.</li>
<li>Experiment with variations on the Mandelbrot set – try different powers or variations on the iteration <strong>z’</strong> &lt;- <strong>z<sup>2</sup> + c<strong>.</strong></strong></li>
</ul>
</div>

<p><a href="http://feedads.g.doubleclick.net/~a/-7zZ7nh2iP_ccE6D_RhuWOZTth4/0/da"><img src="http://feedads.g.doubleclick.net/~a/-7zZ7nh2iP_ccE6D_RhuWOZTth4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-7zZ7nh2iP_ccE6D_RhuWOZTth4/1/da"><img src="http://feedads.g.doubleclick.net/~a/-7zZ7nh2iP_ccE6D_RhuWOZTth4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/tKl8ljlj2X8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/12/27/rendering-the-mandelbrot-set-using-haskell-and-wxwidgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.hackification.com/2010/12/27/rendering-the-mandelbrot-set-using-haskell-and-wxwidgets/</feedburner:origLink></item>
		<item>
		<title>Reading Haskell – Part 4</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/YpQehoj8v64/</link>
		<comments>http://www.hackification.com/2010/11/30/reading-haskell-part-4/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 12:09:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=524</guid>
		<description><![CDATA[In the last three articles I covered the overall structure, lexer, and parser of a simple expression evaluator. This articles concludes by presenting the evaluator and main loop. At this stage we are able to take a string, tokenize it, and then build a tree representing the expression. We now need to be able to [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="../2010/11/20/reading-haskell-part-3/">last</a> <a href="../2010/11/13/reading-haskell-part-2/">three</a> <a href="../2010/11/08/reading-haskell-part-1/">articles</a> I covered the overall structure, lexer, and parser of a simple  expression evaluator. This articles concludes by presenting the  evaluator and main loop.</p>
<p>At this stage we are able to take a  string, tokenize it, and then build a tree representing the expression.  We now need to be able to reduce the tree down to a single value (or  error).</p>
<h3>Expression Reduction</h3>
<pre>reduce :: (MonadError ExprError m) =&gt; ExpressionTree -&gt; m Int
</pre>
<p>We’re returning an Int, but as before, the context for this return value is an error state.</p>
<p>The reducer is a really simple recursive function. Leaf values in the tree (numbers) are their own value:</p>
<pre>reduce (Node (NNumber _ v) _)
    = return v
</pre>
<p>Operator nodes recursively reduce their left and right child nodes, then apply the operator:</p>
<pre>reduce (Node (NOperator p _ op) (lhs:rhs:[]))
    = do x &lt;- reduce lhs
         y &lt;- reduce rhs
         case op x y of
             Right v -&gt; return v
             Left m  -&gt; throwError $ ExprErrorAt m p
</pre>
<p>At this point we’re “collapsing” the error context. Previously we just defined it as any type that satisfied the ‘<strong>MonadError</strong>‘ interface. In this function, we force it to be the ‘<strong>Either</strong>‘ type by expecting the return value to be either ‘<strong>Right</strong>‘ (success) or ‘<strong>Left</strong>‘ (failure). Type inference sorts everything out nicely here.</p>
<h3>Main Loop</h3>
<p>Everything I’ve presented here has been ‘pure’ – free of side  effects. That’s all well and good, and it lets us reason about the  program, but ultimately we have to deal with the computer and the user,  and that’s all about side-effects. The <strong>main</strong> function is the only bit of impure code in this whole example:</p>
<pre>main = interact $ unlines . map (unlines . formatResult) . lines
</pre>
<p>The period operator is the function composition operator, so we read from right to left.</p>
<p>In other words: convert the input to a list of lines, process each one through ‘<strong>formatResult</strong>‘  (our function), concatenate our multi-line output, and concatenate  again to produce a single string for output. The standard function ‘<strong>interact</strong>‘ handles all the messy business of reading and writing from the console streams.</p>
<h3>Examples</h3>
<pre>2 + 3 * 4
14

(12+34)*(56+78)
6164

123 / (4 - 4)
** Error in expression:
**   123 / (4 - 4)
**       ^
** Reason: division by zero

123 +
** Error in expression:
**   123 +
**        ^
** Reason: expected a value
</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/rKnYNOqMqkb005_ttcE8zliCJ3Q/0/da"><img src="http://feedads.g.doubleclick.net/~a/rKnYNOqMqkb005_ttcE8zliCJ3Q/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/rKnYNOqMqkb005_ttcE8zliCJ3Q/1/da"><img src="http://feedads.g.doubleclick.net/~a/rKnYNOqMqkb005_ttcE8zliCJ3Q/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/YpQehoj8v64" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/11/30/reading-haskell-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.hackification.com/2010/11/30/reading-haskell-part-4/</feedburner:origLink></item>
		<item>
		<title>Reading Haskell – Part 3</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/scQGK9OIClE/</link>
		<comments>http://www.hackification.com/2010/11/20/reading-haskell-part-3/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 12:07:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=522</guid>
		<description><![CDATA[Previously I covered the top-level structure and lexical analysis parts of my simple expression evaluator in Haskell. In this article I’ll cover the parser: converting a stream of tokens into an expression tree. I’m going to rush through this section because frankly it’s rather dull, and also because my code seems to be rather stodgy [...]]]></description>
			<content:encoded><![CDATA[<p><a href="../2010/11/13/reading-haskell-part-2/">Previously</a> I covered the top-level structure and lexical analysis parts of my  simple expression evaluator in Haskell. In this article I’ll cover the  parser: converting a stream of tokens into an expression tree. <span id="more-522"></span></p>
<p>I’m going to rush through this section because frankly it’s rather  dull, and also because my code seems to be rather stodgy and ugly.  Hopefully I’ll get some more comments about how to improve it.</p>
<p>Firstly we need to define various types: for the nodes of the tree, and for various intermediate stages:</p>
<pre>data ExpressionNode
    = NNumber Int Int
    | NOperator Int String (Int -&gt; Int -&gt; Either String Int)

type ExpressionTree = Tree ExpressionNode
type ParseResult = (ExpressionTree, [Token])
type NodeResult = (ExpressionNode, [Token])</pre>
<p>The top-level parse routine attempts to parse an expression, and complains if there’s anything left over at the end:</p>
<pre>parse :: (MonadError ExprError m) =&gt; [Token] -&gt; m ExpressionTree
parse ts = do (et, lo) &lt;- parseExpression ts
              case lo of
                  []        -&gt; return et
                  otherwise -&gt; throwExprError lo "unexpected token"</pre>
<p>By “expression” I mean a sequence of sums (plus or minus), since they are the lowest precendence:</p>
<pre>parseExpression ts = parseSum ts</pre>
<p>Next in precedence are products (multiply or divide):</p>
<pre>parseSum     ts = parseInfix parseProduct isSumOperator     ts
parseProduct ts = parseInfix parseValue   isProductOperator ts</pre>
<p>We can share the code for these since they’re all infix operators:</p>
<pre>parseInfix parse pred ts = do (lhs, ts1) &lt;- parse ts
                              parseInfix' lhs ts1 parse pred

parseInfix' lhs ts parse pred
    | pred ts   = do (op, ts1)  &lt;- parseOperator ts
                     (rhs, ts2) &lt;- parse ts1
                     parseInfix' (Node op [lhs, rhs])
                                 ts2 parse pred
    | otherwise = return (lhs, ts)</pre>
<p>Values are either a number, or an entire sub-expression in parentheses:</p>
<pre>parseValue (TNumber p x : ts) = return (Node (NNumber p x) [], ts)
parseValue (TOpenBracket p : ts)
    = do (exp, ts1) &lt;- parseExpression ts
          case ts1 of
             (TCloseBracket _ : ts2) -&gt; return (exp, ts2)
             otherwise               -&gt; throwExprError ts1 msg
      where msg = "expected a closing bracket"
parseValue ts = throwExprError ts "expected a value"</pre>
<p>We need to be able to identify operators. I’ve cheated a little and hard-coded the precedence levels:</p>
<pre>parseOperator ts
    = do case ts of
             (TOperator p op : ts1) -&gt;
                 return (NOperator p op (oper op), ts1)
             otherwise              -&gt;
                 throwExprError ts "expected an operator"
      where oper s = snd $ fromJust $ find (\n -&gt; fst n == s) operators

isProductOperator ts = isOperator ts ["*", "/"]
isSumOperator     ts = isOperator ts ["+", "-"]

isOperator (TOperator _ op : ts) ops = op `elem` ops
isOperator _                     _   = False</pre>
<p>I also have a utility function to handle errors in the token stream:</p>
<pre>throwExprError (t:ts) s
    = throwError $ ExprErrorAt  s (position t)
throwExprError []     s
    = throwError $ ExprErrorEOL s</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/H5yRlUmSg3JhCAhANYdAKlEp-mc/0/da"><img src="http://feedads.g.doubleclick.net/~a/H5yRlUmSg3JhCAhANYdAKlEp-mc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/H5yRlUmSg3JhCAhANYdAKlEp-mc/1/da"><img src="http://feedads.g.doubleclick.net/~a/H5yRlUmSg3JhCAhANYdAKlEp-mc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/scQGK9OIClE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/11/20/reading-haskell-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.hackification.com/2010/11/20/reading-haskell-part-3/</feedburner:origLink></item>
		<item>
		<title>Reading Haskell – Part 2</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/KBzsSxbaR1g/</link>
		<comments>http://www.hackification.com/2010/11/13/reading-haskell-part-2/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 11:59:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=519</guid>
		<description><![CDATA[Last article I started presenting a simple expression evaluator written in Haskell, a strongly-typed, functional, compiled language. In this article I’ll cover lexical analysis of the expression we want to evaluate. Lexing Lexical analysis converts a string into a stream of tokens. We need to define the kinds of tokens that can be present, and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="../2010/11/08/reading-haskell-part-1/">Last article</a> I started presenting a simple expression evaluator written in Haskell, a  strongly-typed, functional, compiled language. In this article I’ll  cover lexical analysis of the expression we want to evaluate. <span id="more-519"></span></p>
<h3>Lexing</h3>
<p>Lexical analysis converts a string into a stream of tokens. We need  to define the kinds of tokens that can be present, and their values.</p>
<pre>data Token = Tx
           | TOpenBracket  { position :: Int }
           | TCloseBracket { position :: Int }
           | TOperator     { position :: Int, operator :: String }
           | TNumber       { position :: Int, int :: Int }
           deriving (Show)
</pre>
<p>The first one, <strong>Tx</strong>, is a special token used to reset  the lexer’s state machine when a space is encountered – to enable us to  distinguish between “23″ (a single number token) and “2 3″ (two number  tokens).</p>
<p>Our expression syntax is so simple we can figure out the token type from a single character:</p>
<pre>createToken x p
    | isDigit x    = return $ TNumber       p $ read [x]
    | x == '('     = return $ TOpenBracket  p
    | x == ')'     = return $ TCloseBracket p
    | x `elem` ops = return $ TOperator     p [x]
    | otherwise    = throwError $ ExprErrorAt "unknown token" p
    where ops = concat $ map fst operators
</pre>
<p>The dollar functions being used are the right-associate operator: <strong>return $ TNumber p $ read [x]</strong> is equivalent to <strong>return (TNumber       p ( read [x]))</strong>. It’s another readability thing.</p>
<p>Note that we’re storing the string position at each stage of tokenization – this is so that we can report errors later on.</p>
<p>Since tokens can span multiple characters, I need to be able to combine them:</p>
<pre>combineTokens (TNumber   p x) (TNumber   _ y)
    = [TNumber p (x * 10 + y)]
combineTokens (TOperator p x) (TOperator _ y)
    = [TOperator p (x ++ y)]
combineTokens x               y
    = [x, y]
</pre>
<p>Only numbers and operators combine in a special way. Everything else (the third line) simply becomes a list of two tokens.</p>
<p>Haskell makes heavy use of pattern matching: you can define a  function several times, with each definition matching a different  pattern. This avoids provides extremely strong typing, avoids ‘if’  statements, and enhances readability. The underscores in the above  function are unused matches – they match anything, and indicate the  value matched isn’t used.</p>
<p>Finally, we can put all of this together: <strong>lexer’</strong> is a recursive function which handles characters one-by-one, and <strong>lexer</strong> simply calls that with an appropriate starting state.</p>
<pre>lexer :: (MonadError ExprError m) =&gt; String -&gt; m [Token]
lexer s = lexer' s 0 Tx []

lexer' []       _ _  ts = return ts
lexer' (' ':xs) p _  ts = lexer' xs (p + 1) Tx ts
lexer' (x:xs)   p Tx ts = do tok &lt;- createToken x p
                             lexer' xs (p + 1) tok (ts ++ [tok])
lexer' (x:xs)   p s  ts = do tok &lt;- createToken x p
                             ctok &lt;- return
                                      $ combineTokens (last ts) tok
                             more &lt;- if null ts
                                       then return [tok]
                                       else return
                                                  (init ts ++ ctok)
                             lexer' xs (p + 1) tok more
</pre>
<p>That first line (beginning “<strong>lexer ::</strong>” introduces so many new concepts I don’t know where to start. Let’s give it a bash:</p>
<ul>
<li>The double colon introduces a type signature. Until now I’ve been  lazy and let the compiler figure out the types of the various functions,  but for this one I needed to define it explicitly.</li>
<li>The single arrows separate arguments and return types – so the C function “<strong>int foo( char a, double b)</strong>” would have a Haskell equivalent of “<strong>foo :: Char -&gt; Double -&gt; Int</strong>“.</li>
<li>Monads… think of them as a context to a computation. I want to return a list of Tokens (i.e. <strong>[Token]</strong>),  but there could be an error along the way, so the context of that  return value is in terms of an error state, which I have specified to be  of type <strong>ExprError</strong>. So I define a type variable ‘<strong>m</strong>‘ (defined before the arrow ‘<strong>=&gt;</strong>‘), and use it to specify the context for my return value.</li>
</ul>
<p><a title="Reading Haskell – Part 3" href="../2010/11/20/reading-haskell-part-3/">Next post</a>: parsing the token stream into an expression tree.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/eAY0AOllw6tDzC-VlFa1TCMguKc/0/da"><img src="http://feedads.g.doubleclick.net/~a/eAY0AOllw6tDzC-VlFa1TCMguKc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/eAY0AOllw6tDzC-VlFa1TCMguKc/1/da"><img src="http://feedads.g.doubleclick.net/~a/eAY0AOllw6tDzC-VlFa1TCMguKc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/KBzsSxbaR1g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/11/13/reading-haskell-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.hackification.com/2010/11/13/reading-haskell-part-2/</feedburner:origLink></item>
		<item>
		<title>Reading Haskell – Part 1</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/y_zlbvt46Dc/</link>
		<comments>http://www.hackification.com/2010/11/08/reading-haskell-part-1/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 11:55:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=514</guid>
		<description><![CDATA[I’ve been playing around with Haskell recently, following the recent web publication of the excellent guide “Learn You a Haskell for Great Good!“. Rather than try to attempt to explain the language in detail, I thought I’d give a thousand-foot view – not a tutorial, but a general overview of what Haskell is like to [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-525" style="margin-right: 10px;" title="Learn You a Haskell for Great Good!" src="http://www.hackification.com/wp-content/uploads/2010/10/LearnYou.png" alt="" width="160" height="124" /><br />
I’ve been playing around with Haskell recently, following the recent web publication of the excellent guide “<a title="Learn You a Haskell for Great Good!" href="http://learnyouahaskell.com/" target="_blank">Learn You a Haskell for Great Good!</a>“.  Rather than try to attempt to explain the language in detail, I thought  I’d give a thousand-foot view – not a tutorial, but a general overview  of what Haskell is like to code in.</p>
<p><span id="more-514"></span></p>
<h3>Getting Started</h3>
<p>I’ve picked a really simple task – an interactive expression  evaluator. I’ll be able to type expressions such as “(1 + 2) * 3″, and  expect the answer 9. I’ll also cover error-handling. For this example  I’m not going to use any standard Haskell parsing libraries, such as  Parsec or Alex/Happy – instead I’m going to hand-code the lot.</p>
<p>If you’d like to give Haskell a whirl, the easiest way is to download the <a title="Download Haskell" href="http://hackage.haskell.org/platform/" target="_blank">Haskell Platform</a> – it should have everything you need to get started, and is available for Windows, Mac, and Linux.</p>
<p>A note of caution: I’m going to present my code in explanation order,  not necessarily the order it’s present in the file. I’m also going to  gloss over many Haskell subtleties – I’m presenting this in the style of  “lies-to-programmers”.</p>
<h3>Top Level</h3>
<p>I’m going to write this evaluator “properly”, and hence there will be three phases: lexical analysis, parsing, and reduction.</p>
<pre>evaluate s = do tokens &lt;- lexer s
                tree   &lt;- parse tokens
                result &lt;- reduce tree
                return result</pre>
<p>Here I’m defining a function, <strong>evaluate</strong>, which takes one argument, <strong>s</strong>.  It calls functions for each of the three phases, and returns the final  result. Note that in Haskell, functions are called without parentheses –  so the equivalent to the C-style “<strong>f(x, y)</strong>” would be “<strong>f x y</strong>“. Also note that indentation is important – the four statements from “do” onwards belong to the “do” block.</p>
<blockquote><p>If you’ve never worked with Haskell before, I bet you’re  thinking “slow, untyped, scripting language”. Purge your brain of those  thoughts – Haskell is compiled to machine code (although it can be  interpreted), and is <em>extremely </em>strongly typed – more so than C#  or C++. The Haskell compiler uses type inference to work out a  function’s type if you don’t supply a type definition.</p></blockquote>
<p>That result value is going to be a Int, so I need to convert it to a  String if I’m going to display it on screen. I also promised  error-handling, so we need to cover that, too.</p>
<pre>formatResult s = case result of
                     Left e  -&gt; formatError s e
                     Right r -&gt; [ show r ]
                 where result = evaluate s</pre>
<p><strong>Left</strong> and <strong>Right</strong> are constructors for <strong>Either</strong> – an error state is represented by <strong>Left</strong>, and a normal state by <strong>Right</strong>.  (Incidentally, note that types and constructors begin with an uppercase  letter, while everything else begins with a lowercase one).</p>
<p>Arrows going left, arrows going right, equals signs… we need a bit of clarity:</p>
<ul>
<li>‘<strong>=</strong>‘ defines a function: in the example immediately above, we define two functions: <strong>formatResult</strong> (which takes one parameter), and <strong>result</strong> (which takes none – a value if you like).</li>
<li>‘<strong>-&gt;</strong>‘ is part of the <strong>case</strong> statement – it separates the patterns from the case expressions.</li>
<li>‘<strong>&lt;-</strong>‘ is part of the <strong>do</strong> statement – it binds expressions on the right to values on the left.</li>
</ul>
<p>‘<strong>do</strong>‘ blocks are both powerful and difficult to explain – involving the daunting <a title="Monad (functional programming)" href="http://en.wikipedia.org/wiki/Monad_%28functional_programming%29" target="_blank">M-word</a> – but for now we’ll just say that they allow sequential operations to be specified, and also support error/exception handling.</p>
<h3>Error Handling</h3>
<p>OK, enough chat, back to the code. We need to support error states:</p>
<pre>data ExprError = ExprErrorAt  { reason :: String, start :: Int }
               | ExprErrorEOL { reason :: String }

instance Error ExprError where
  noMsg    = ExprErrorEOL "unknown error"
  strMsg s = ExprErrorEOL s

formatError s e = map ("** " ++) $
                      [ "Error in expression:"
                      , "  " ++ s
                      , "  " ++ replicate (offset e) ' ' ++ "^"
                      , "Reason: " ++ reason e
                      ]
                   where offset (ExprErrorAt  _ start) = start
                         offset (ExprErrorEOL _)       = length s</pre>
<p>I’ve defined a new data constructor, <strong>ExprError</strong>,  which represents an error at a specific character position, or at the  end of the expression. I’ve also made it a member of the <strong>Error</strong> class, so that it works with the ‘<strong>do</strong>‘ blocks.</p>
<p>Finally, I define <strong>formatError</strong>, used by <strong>formatResult</strong>,  which prints some error text (prefixed with asterisks), the expression,  and a caret at the offending character. Note the use of  pattern-matching in the last two lines – they define a function ‘<strong>offset</strong>‘ which determines the position at which to place the marker. Underscores represent matches that we don’t care about.</p>
<p>As this article is getting a little long, I’ll end with a quick  definition of some static data: the operators supported by this  evaluator, and their associated operations. These are represented as a  list (square brackets) of pairs (round brackets). Note that the  operations are complicated a little by the need to support  error-handling.</p>
<pre>operators = [ ("+", oper (+))
            , ("-", oper (-))
            , ("*", oper (*))
            , ("/", (\ x y -&gt; if y == 0
                              then Left "division by zero"
                              else Right (x `div` y))) ]
            where oper op = (\ x y -&gt; Right (op x y))</pre>
<p>Haskell allows any function taking two arguments to be used in infix form by placing it within backticks – hence “<strong>x `div` y</strong>” is equivalent to “<strong>div x y</strong>“. It’s just a readability thing.</p>
<p><a href="../2010/11/13/reading-haskell-part-2/">Next article</a> I’ll move onto lexical analysis – converting a string into a stream of tokens.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/4qGGlH-4M0boisKmiqjm8zUnSb4/0/da"><img src="http://feedads.g.doubleclick.net/~a/4qGGlH-4M0boisKmiqjm8zUnSb4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/4qGGlH-4M0boisKmiqjm8zUnSb4/1/da"><img src="http://feedads.g.doubleclick.net/~a/4qGGlH-4M0boisKmiqjm8zUnSb4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/y_zlbvt46Dc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/11/08/reading-haskell-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.hackification.com/2010/11/08/reading-haskell-part-1/</feedburner:origLink></item>
		<item>
		<title>Designing a VS2010 Color Scheme – Consistency, Consistency, Consistency</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/2wQoPam6oHI/</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>stusmith</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/Colors1.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/Comments1.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/Literals11.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/Literals21.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/Types1.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/Errors1.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/Overlays1.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/Selection1.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>

<p><a href="http://feedads.g.doubleclick.net/~a/76kk-9bUseee2mYm9Ta5N9ic2rY/0/da"><img src="http://feedads.g.doubleclick.net/~a/76kk-9bUseee2mYm9Ta5N9ic2rY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/76kk-9bUseee2mYm9Ta5N9ic2rY/1/da"><img src="http://feedads.g.doubleclick.net/~a/76kk-9bUseee2mYm9Ta5N9ic2rY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/2wQoPam6oHI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/05/16/designing-a-vs2010-color-scheme-consistency-consistency-consistency/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.hackification.com/2010/05/16/designing-a-vs2010-color-scheme-consistency-consistency-consistency/</feedburner:origLink></item>
		<item>
		<title>Occasional Links – Programming Mistakes, Fixing Them, C, Pointers, and more</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/_K41WFVAh6A/</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>stusmith</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>

<p><a href="http://feedads.g.doubleclick.net/~a/eXTXxOEaoUltnazclRc72wU9rSk/0/da"><img src="http://feedads.g.doubleclick.net/~a/eXTXxOEaoUltnazclRc72wU9rSk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/eXTXxOEaoUltnazclRc72wU9rSk/1/da"><img src="http://feedads.g.doubleclick.net/~a/eXTXxOEaoUltnazclRc72wU9rSk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/_K41WFVAh6A" height="1" width="1"/>]]></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>
		<feedburner:origLink>http://www.hackification.com/2010/05/08/occasional-links-programming-mistakes-fixing-them-c-pointers-and-more/</feedburner:origLink></item>
		<item>
		<title>Weekly Links – Microsoft, Windows Phone 7, General Coding, and a bit of humour</title>
		<link>http://feedproxy.google.com/~r/Hackification/~3/o33OhfSCJiA/</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>stusmith</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>

<p><a href="http://feedads.g.doubleclick.net/~a/W_TSzjWxCXX0jdn-3U61VP1zqnM/0/da"><img src="http://feedads.g.doubleclick.net/~a/W_TSzjWxCXX0jdn-3U61VP1zqnM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/W_TSzjWxCXX0jdn-3U61VP1zqnM/1/da"><img src="http://feedads.g.doubleclick.net/~a/W_TSzjWxCXX0jdn-3U61VP1zqnM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Hackification/~4/o33OhfSCJiA" height="1" width="1"/>]]></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>
		<feedburner:origLink>http://www.hackification.com/2010/03/29/weekly-links-microsoft-windows-phone-7-general-coding-and-a-bit-of-humour/</feedburner:origLink></item>
	</channel>
</rss>

