Random Acts of Pragmatism
March 06, 2020

I have been accused (by myself, mostly), of being a bit too much of a purist sometimes. It’s true that I do like things to have an intellectual rigour to them, but it’s mostly about being honest and clear with ourselves about what we’re doing and why. I welcome the application of common sense, and I’m fine with taking shortcuts as long as they’re consciously chosen for a good reason.

I’d like to think that I’m a pragmatist…

As I was adding an item to a list in some code this morning, it occurred to me that a tiny feature of list literals in Swift (and many other languages) is a great example of pragmatism.

What I’m talking about is the ability to do this:


let list = [
    "foo",
    "bar",   // <--- look ma, there's an extra comma
]

A purist might say that this is not correct (for some value of “correct”). It could be argued that it’s confusing to allow that extra comma. It could be argued that it implies that the programmer forgot to add the final item.

An experienced programmer, however, will often have had to edit long lists of things by moving existing lines around. When the last line of these lists didn’t have a comma, and they moved it to the middle of the list, they probably forgot to add the comma, and it caused an error. They also then exposed a new last line, with a comma, which also caused an error. Easy to fix, but annoying.

At some point during programming language evolution, someone asked themselves the question “does that error about the extra comma actually do anything useful?”. Is it actually ambiguous? No. Can we just get rid of it? Yes. Would that bring us a little bit closer to Nirvana? Possibly.

To me, this is a great example of a little random act of pragmatism.

« Github Actions and Swift
Got a comment on this post? Let us know at @elegantchaoscom.