Using the C-preprocessor to replace curly braces

In my article I argued that curly braces neither enchanced clarity nor reduced keystrokes to point out that whatever you care about curcly braces is not an advantage.

As to why I like a number of languages with curly braces. I don't like them because of curly braces, I like them despite curly braces.

I quite like Go, Swift, C and Zig. However the curly braces is not something I think adds to their appeal. Quite the opposite.

I think the C pre-processor should be used as little as possble. That is one of the advantages of Zig, that it ditches the pre-processor. It just does simple text substitution with no understanding of the language, which is a receipt for problems.

But perhaps more importantly the C-language has been specifically designed for use with curly braces. A simple text substitution cannot easily fix that. Consider transforming this:

Now I am going to replace all the braces with begin and end:

How does that look? It looks terrible. C was not meant to be used that way. And I would say that applies to most curly-brace languages. You cannot to a simple 1–1 substitution. You have to actually design the language around not using curly braces, the way Julia, Lua and other languages have been made. I seem to recall Ruby also making curly braces optional but they made the alternative forms actually nice to use.

Written by

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store