On Maintainability: Gold Plating the Game of Life in Elm

Launch Pad

In a previous article, we explored how to write Conway's Game of Life in the Elm programming language. This example was predicated on one from several years before and compared the differences in Elm over the intervening period of time. Today, we will add some entirely unnecessary features to the simple version of the program.

This exercise in gold plating will serve as a means of probing what it feels like to add new features to an already established Elm program; these microcosmic changes will, hopefully, be reflective of maintaining larger applications in Elm. Throughout the course of this article, we will consider successive diffs, starting from the original implementation, while moving toward the final version.

Continue reading

Common Table Expressions in ActiveRecord: A Case Study of Quantiles


Today, we are going to look at a straightforward real-world problem, and build a comprehensive solution. In doing so, we will start with some various naive approaches as we increase our understanding of the underlying mechanics, encounter some pitfalls, and, ultimately, approach a reasonable level of sophistication and abstraction. The stack we will be using for this case study is Ruby on Rails 5.1 with PostgreSQL 9.6 for the database.

Now, let me present to you the problem through which we will frame this discussion: given a number of student records, when displaying a single student, also display the quintile into which their grade falls.

Continue reading

Continuations in Ruby - Part 1: First Class Objects

Caveat Emptor

This is the first in an ongoing part series exploring the possibilities presented to the programmer when continuations are a first class part of a language. These articles follow Chapter 20 of Paul Graham's venerable treatise On Lisp .

While a powerful semantic construct, there is no secret that continuations are, for good reason, thoroughly reviled . In short, give us the ability to store the state of a computation and return to it at a later point in the execution of our program. This form of non-local return (or jump anywhere ) can be compared to goto statements of old or try/catch semantics commonly seen today. Both of these language features, in fact, can be implemented in terms of continuations, and in section 5.8.3 of The Ruby Programming Language , the authors construct a BASIC inspired goto function. Today, when we require 'continuation', the interpreter will kindly inform us that 'warning: callcc is obsolete; use Fiber instead'.

With continuations framed in this way, it should go without saying that, under no circumstances whatsoever, should these curios be used in anything with any degree of seriousness. Why, then, should should we even bother? Sometimes, the simple fact that we should not is enough to make it worthwhile.

Continue reading

Revisiting the Game of Life in Elm


Over three years ago, I wrote an article exploring how to write Conway's Game of Life in the Elm programming language. That article was originally written for version 0.12.3 and later updated for 0.14, but during the intervening span of time, Elm has matured significantly. In the process, Elm has dropped its functional reactive roots in favor of subscription-based concurrency. Today, we will go through the same exercise of writing the game of life, as a means of exploring the basics of a simple modern Elm program.

Continue reading

Hacking S-expressions into Ruby


S-expressions are a classic means of storing trees of data. Part of the original Lisp specification, they have been a part of software engineering since the very beginning. Other languages, notably Scheme and, more recently, Clojure, have helped maintain the relevancy of this very simple means for representing data.

In the spirit of Greenspun's tenth rule , we are going to attempt make first-class s-expressions in Ruby. There is already a nice implementation of s-expressions in Ruby, for reference, but they are not first-class, which makes them less than ideal. As such, we are going to to see how far we can push (read: abuse) the dynamic nature of the Ruby language, and investigate just how much control we have over certain elements of its syntax.

For anyone more interested in the result than the journey, be warned that this attempt will not be successful, but some interesting results will be found along the road to ultimate failure.

Continue reading