I was rummaging around in some old directories and found an implementation of the Sieve of Eratosthenes that I’d thought I’d share.  I thought I’d share it because of the simplicity of the algorithm, it represented a very enjoyable programming exercise and one that I now use as a standard kata when learning a new language. The Sieve of Eratosthenes is an algorithm used to identify prime numbers.

In it’s simplest form, the algorithm states:

set Array to array of size N
set Array to all true
for i from 2 to N
  for each j where i divides j, j from i + 1 to N
    set Array(j) to false

Basically, it trawls an array of “on” bits and “turns off” any index that is cleanly divisible by any number less than the square root of it’s size.

Continue reading

The tag line for the blog is “Lessons from The Code Face”, a reference to the coal face where miners would hack away at the stone in their search for black gold.  This, and the “Mining Code” title, seem to give an unfair assessment of the coding craft.  Comparing coal mining to the intricate art of computer programming?  Preposterous.  However, as I sat down to refute my own title and explain it away as simply an evocative name, I began to see correlations (Which I suspect was easier because I was actively seeking them).

Mining implies hard work, potentially long hours and a subtle skill with the tools, which are all true of coding; it also implies that anyone can just show up and start swinging an axe to get some results, but true mastery takes practice and constant improvement, which is also true in part.  More and more attributes match: a focussed purpose, teamwork and a certain element of risk taking.  Although these are arguably all attributes that constitute a recipe for greatness in any field or purpose, it does highlight that perhaps the correlation between coal mining and code mining isn’t too stretched; therefore justifying, at least partly,  my poor pun.

This blog is a way for me to reflect and codify my own lessons, offer any subjective advice that I may have to others coming into the mine and as a learning opportunity.  I hope that the act of putting these into words may consolidate my own understanding, and offer a forum for others to share their own advice with me.