Idiomdrottning’s homepage

Idiomdrottning brace style

When I am sending patches I always try to use whatever brace style upstream is using, and my own projects rarely use brace languages.

So I rarely get to use my own prefered brace style, and maybe that’s a blessing for the world since it’s so unusual and non-standard.

Put on safety goggles for this one because it’s gonna look weird. It’s just what makes sense to me.

Here’s how it works:

All indentation widths are two spaces

I like my code compact, is the running thread through all of these. This isn’t to try to obfuscate, I still want to write the code as clearly as I can, I just wanna fit it all on my super tiny screen.

Elidable parens (including braces) are elided

That last one includes single statement clauses in ifs and elses. Some languages make braces mandatory for such clauses but in other languages, they indicate a progn. Progn and side-effects are fine but I want to be deliberate about them.

This goes for operations, too. I hate infix but I do my best to try to elide the elidables. I’m sure there are many places where I’ve missed that. That’s just how difficult infix is.

All braces are hanging

This means that opening curly braces hang on the preceding line, and closing curly braces hang on the last line of their block.

Like this:

foo {
  if (baz) {

This is unlike the so-called lisp style because they often put the opening parens on the line below. Here is Wikipedia’s example of that style:

while (x == y)
  { something();
    something_else(); }

For me, that would look like this:

while (x == y) {

The progn brace belongs to the while, not to the first statement.

Reading & writing

For writing and editing it, editor support that can match parens is pretty clutch. The whitespace pulls a lot of weight when reading this since curly braces are all over the place.

But since I do have that editor support for writing it, and the indentation helps me read it, it’s great. If I didn’t have those two things, it’d suck, but I do so it’s great.

I could read that example above if it read:

  if baz

So my brace style is just adding the grawlixes back into the pseudocode as unintrusively as possible.