Posts
Why you should learn brainfuck (or: learn you a brainfuck for great good!)
What is brainfuck? Brainfuck is close to being the simplest programming language possible, with only 8 instructions:
> < + - , . [ ] These instructions move an internal data pointer, increment and decrement the value at the data pointer, input and output data, and provide simple looping.
As an aside: brainfuck was written with the intent of having a language with the smallest-possible compiler. Many compilers for brainfuck are smaller than 200 bytes!
Posts
Zen and the art of statefulness
The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said “Master, I have heard that objects are a very good thing - is this true?” Qc Na looked pityingly at his student and replied, “Foolish pupil - objects are merely a poor man’s closures.”
Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures.
Posts
Really really simple Ruby metaprogramming
Metaprogramming in Ruby has the reputation of being something only the true zen Ruby masters can even hope to understand. They say the only true way to learn metaprogramming is to train with Dave Thomas in his mountain retreat for five years - the Ruby equivalent of this XKCD:
But it’s not that bad. In fact, I’m going to go so far to say that it’s possible to learn to metaprogram in Ruby without even meeting Dave Thomas.
Posts
Ruby vs JavaScript: functions, Procs, blocks and lambdas
In my post Why JavaScript is AWESOME I compared Ruby to JavaScript like this:
A language like Ruby is a toolbox with some really neat little tools that do their job really nicely. JavaScript is a leather sheath with a really really sharp knife inside.
What I was partly getting at was how the two languages handle the passing around of code. Both have their own way of working with anonymous functions.
Posts
2011
Ok, I’m going to write one of those self-indulgent “what am I going to do with the next year?” posts. If you don’t like the sound of that then I won’t be offended.
I’m working full-time for a publishing project management company based in Stroud, which is where I’ve been since I graduated in 2007. It was never my plan to stay there forever, but I didn’t know what I wanted to do instead.
Posts
Clearing up the confusion around JavaScript references
One question that seems to come up everywhere in discussions of JavaScript is:
Is JavaScript pass-by-reference or pass-by-value?
This is often asked by people who don’t really understand what pass-by-reference or pass-by-value really mean. One of the stock answers is:
Objects are passed by reference; primitives are passed by value.
I really don’t think this is the best way to describe the situation, so I’m going to try a new way.
Posts
JS1k: Making a very small game in JavaScript part 2 - optimisations
This is part 2 of a series. See part 1 here.
Two types of optimisation There are three types of optimisation when you’re trying to reduce the size of the code. The first two are “defactoring” techniques: they change the code but not the functionality. The third changes code and functionality.
1. Optimising for the compiler One of the major optimisations the Closure compiler carries out is the renaming of identifiers.
Posts
JS1k: Making a very small game in JavaScript part 1 - tools
Well, that was fun. I’ve just submitted my JS1k Xmas edition demo. I only heard late on when the first JS1K happened, and I wasn’t up to coding anything decent at that stage anyway. So when I heard about this new one, I jumped on the task, working all weekend on it (except when I had to help move a piano). By the end of Sunday it was done, and I was mostly happy with it.
Posts
A brief introduction to closures
In this post, I’m going to attempt to explain what closures are and how to use them. Many modern (and some not-so-modern) programming languages contain support for closures, but for the purposes of this article I’m going to be using JavaScript. I’ve chosen JavaScript for a few reasons:
Ubiquity: If you have a web browser then you have a JavaScript interpreter Simplicity: JavaScript is conceptually a fairly simple language (especially if you limit yourself to its Good Parts), compared to other dynamic scripting languages such as Python and Ruby Familiarity: If you’ve used any of the C family of languages (e.