This Code is Such a Brainf*ck — No, Really!

While languages such as Brainf*ck and the more kid-friendly Ook! (in name only) are generally left to the realm of toys and bragging rights, their real beauty is having an extremely simple turing complete interactive environment in which to learn underlying computer science concepts.

Engineers like to do things differently, and nothing demonstrates this more than the plethora of esoteric programming languages available. Usually relegated to research projects of debatable value, toys and bragging rights the ability to strip back to the bare metal of the computer hardware, of even an emulation thereof, can be of huge educational value for the legion of high level software developers who have no understanding on exactly a pixel is actually rendered on a screen.

For example, a code sample in the unfortunately named Brainf*ck.

++++++++++        // Set first cell (counter) to 10
[
        >         // Move to next cell (output)
        +         // Increase value of current cell
        .         // Display value of current cell
        <         // Move to previous cell (counter)
        -         // Decrease value of current cell
]

The above commented code simply displays the value 1 to 10 on the output. A few things to note:

  1. Memory cells can be used for any purpose, their use as described in the above comments, is to aid in understanding only.
  2. Code blocks (defined by ‘[' and ']‘) continue to execute while the current memory cell is greater than zero.
  3. Brainf*ck compilers/interpreters typically display output as ASCII symbols, so running this program will not display actual characters.
  4. Seven of the eight available operations, with the exception of read value to current cell indicated by a comma (‘,’), are represented in the example program.
  5. Layout, whitespace and unknown characters are (or at least should be) ignored.

The program can be executed with an online interpreter. To see the output rendered in a human readable form you will need to use debug-mode as the ASCII symbols for number 1 to 10 are control characters and do not normally display anything on screen.

Using only eight instructions with an implicit operand makes this an excellent model for understanding memory allocation and for thinking about how these operations can be completed at the basic level. The use of ASCII output highlights the relation between the decimal value of a memory cell and it’s on screen representation. Parallels can also be drawn with assembly language programming. The highly reduced instruction set, again, coupled with implicit operands and pointer, provides a deeper insight to how a modern microprocessor might carry out instructions and introduces the thought processes required to understand memory addressing and operations.

While such and intricate understanding of the underlying implementation details of computer hardware is arguably not essential, and as such only peripherally taught in many modern degree level computer science course, esoteric programming languages such as Brainf*ck can help developers understand these underlying concepts of the digital computer by giving them an interactive path for investigation and have the potential to bring about a more enlightened, openminded and flexible developer workforce if their educational value is properly exploited — despite some rather institution unfriendly names.