Categories
other thoughts

The position of your curly braces

[Yesterday: 3 miles of hills in town]

I’ve been looking at the computer language called “Go”.

A non-programmer might be surprised to find that the layout of the text of a program can cause intense discussion among programmers. In group projects there is frequently some sort of standard. People who don’t like the standard will use automated formatters to translate from the standard to their favorite layout before they edit the program, and then from their layout back into the standard when they share their work back to the group.

The same happens with naming, the names of variables, functions, files, etc.

Anyway, I’ve been looking at Go and the training materials I’m using have a layout that is well known, but I have never understood.

I was trained originally in the language Pascal which used BEGIN/END to delimit chunks of resulting action statements like this:

Decision/controlling statement
BEGIN

resulting action statement one
resulting action statement two
etc.

END

Later I learned a curly-brace language called C and I carried forward my Pascal formatting style  ( a style which many people like).

Decision/controlling statement
{

resulting action statement one
resulting action statement two
etc.

}

So that is some explanation for what I do.  I like to see the blocks clearly delimited and the curly-braces act as beginning and ending markers for the block.

Here is the format used by the Go training material:

Decision/controlling statement {

resulting action statement one
resulting action statement two
etc.

}

I don’t understand putting the block-opening curly brace on the same line as the decision statement.  I don’t get it.  My eye looks to match up the beginning and ending curly braces and using that style I see a visual line from the upper right, slanting down to the lower left, directly through the block of action statements. I like to be able to draw a visual line from the opening marker to the closing marker to completely delimit the block of resulting / action statments.

This zig-zag style, I must make clear to you, it is very popular.  The people who invented the C language seem to have preferred it.  And that style propagated to other languages like Java and now Go.

Why?  why? why?

I can tell you don’t understand the importance of this issue.  If I were to share a program in my style with a person who likes the zig-zag style, they would be unhappy, probably even more unhappy than I would be if they shared their mess with me.