Stupid Template Tricks: Snake Part 2 - Interactive Nibbler

Compile time Nibbler, man. We gotta get this sucker done. Last time, we got so caught in metaprogramming that we ended up with a state machine. To play a game, you had enter all of the commands ahead of time. That's pathetic. Is that what you want to do with…

Stupid Template Tricks: Snake

Conway's game of Life may be mathematically interesting, but it is not what most people would consider a real game. So let's take a look at another product of the 70's, the arcade game Snake. This post walks through a complete, compile time implementation of a Snake game using C…

Stupid Template Tricks: Short-Circuiting

C++ templates make it remarkably easy to shoot yourself in the foot. Case in point, this seemly innocent template function: template <unsigned val> struct is_even { static const bool value = (val > 1) && (is_even<val - 2>::value); }; template <> struct is…

Stupid Template Tricks: Compile Time Pseudo-Random Number Generator

What with all those pesky NSA backdoors, runtime random number generation is just not secure. So let's build a compile time pseudo-random number generator with C++ templates. In this post, I'll walk through the implementation of a simple, deterministic pseudo-random number generator using a linear feedback shift register (LFSR). The…

Responsive, Two Column Documentation Layout With Markdown and CSS

Adrift in Markdown, longing for structured layout sans HTML Markdown is great. I find myself using it everywhere, even places where it makes no sense, such as Word documents and iMovie titles. But Markdown works best for documents that consist of a single column of content. Ask Markdown to do…

Parsing User Defined Operator Expressions in a Scripting Language

One thing that's always bugged me about Javascript is the language's treatment of operators. Javascript operators, like their C and Java ancestors, are hardcoded into the language. The * operator always multiplies two numbers and is always parsed the same way. Javascript operators are special too. They get to use cool…