Hi Jack,
thanks very much for those pointers. I had a quick look at that contest you gave the link to and can't believe those code examples, complete gobbledegook to me. Great to see some humour in the matter.
After reading your post I went and played with autoformat and expected it to move my curly bracket positions all over the place but surprisingly it didn't. I then went and Googled the matter and came across a writeup on different methods of indentation. The differences seem legion, but like you say I'll probably start to see a general pattern used by most coders. I was relieved to see one method was along the lines of what I suggested Robin could use for teaching beginners and in fact in the writeup it said that method is one of the easiest for beginners to understand, although it does take up more line for the same amount of code. It also said it is very common for C.
Here's a part of that writeup (italics):
Allman / "East Coast" / Horstmann
Example: GNU-example in Allman style
int f(int x, int y, int z)
{
if (x < foo(y, z))
{
haha = bar[4] + 5;
}
else
{
while (z)
{
haha += foo(z, z);
z--;
}
return ++x + bar();
}
}
This style is named after Eric Allman, who wrote a lot of utilities for the BSD family of operating systems, which also is a reason why this style is sometimes incorrectly referred to as the BSD style. Please note that this style might sometimes be called BSD style, but that this is wrong. For BSD itself, just as for UNIX and Linux, 1TBS is used. You can read about this in the man pages of the different BSD derivates e.g. for ?FreeBSD and ?OpenBSD.
This style is usually preferred by newbes to C-derived programming languages for being the easiest. Despite the fact that the inventors of C, UNIX and BSD use 1TBS, this style is very common for C.
The main disadvantage of this style is the waste of precious screen lines. Per block at least one additional line is needed compared to 1TBS. In C, C++ and similar languages with comparable preprocessors there is one single situation where this style shows an advantage over 1TBS.
I accept that is not the norm, but I am surprised by that too. It is so easy to read and I equate it to looking at the graphical representation of a computer folder system, where you can see a folder inside a folder inside a folder with great ease, but in this case it's functions. I'm guessing as I get more proficient at C then I'll see functions and nested functions easier without my preferred bracketing method. Right now though some of the code I've looked at is incredibly confusing to my beginner eyes. I see an opening curly bracket, then in the same line another opening one. My eyes continue scanning serially along the lines and oh my God another opening bracket. Somewhere each of these opening brackets have a closing bracket and a lot of my effort is spent identifying individual functions and the nested functions inside them. Welcome to the world of C I tell myself LOL.
As per your suggestion I'll keep an eye out for what seems to be the norm in coding style. Even if I don't use it personally, my sketches are fairly simple at present and I can change it to the general method if I post it on the forum.
Cheers,
Keith.