Small Programming Languages Are Annoying
Small programming languages are annoying. The most idiomatic solution to any problem is to use a language's builtin functionality, but small programming languages often lack what is taken for granted in other languages. It's common for novices to ask for the easiest way to add a sequence of numbers or merge two dictionaries. In response, they're told how to implement it. An example of this is a function that takes a number N
and a sequence as arguments and then returns a new sequence containing sequences of length N. The original sequence items are in those subsequences.
[1, 2, 3, 4, 5, 6, 7, 8, 9] => [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
At least several popular languages implement this in their standard library:
- Haskell has the
chunksOf
function. - Clojure has the
partition
function. - Ruby has the
each_slice
method.
Why not just implement it yourself?
- The next person to read code using your utility must learn the utility, despite it being unique to your code base.
- You must handle edge cases.
- You must document the behavior.
For the partition function, the designer must decide how to handle when the length of the sequence is not divisible by the length of the chunks. For example, if the length of the sequence is five, but the length of the chunks is three. There are several ways to handle this.
- Throw an error.
- Truncate the original sequence.
- Make the chunks different sizes. The last chunk size will be increased to contain the remaining items.
- Make the chunks different sizes. An extra chunk with a decreased size will contain the remaining items.
If everyone is implementing their own partition function, then edge cases will all be handled differently. This is needlessly confusing.
The following is often said about C++:
C++ is so big that no one uses every feature. Every C++ programmer uses a different subset of the language.
Every C++ programmer is using a different subset of the language.
Compare this to the following:
Scheme is so small that every implementation defines its own OOP library. Every Scheme does classes a different way.
Every Scheme programmer is using a different superset of the language.
It is easy to dismiss C++ and other large feature-rich language as kitchen sink monstrosities created by giant committees, but there is an easy way for programmers to escape the dangers of a large language: just learn the language. Once the language is learned, the only surprises are new standards. In contrast, with small languages there is no solution. A programmer must learn every superset on a need to know basis and they are lucky if any of what they learn transfers to other supersets.