Little known fact...the only reason the brace is on the same line as the function declaration is because K&R just wanted to save space in the code listings.
Um, no, K&R braces after function declaration are in the next line, because they are special.
Braces after if, for, while, switch, etc. are on the same line, and yes, it was to save space on the 80x24 screen.
Get a copy of "The C Programming Language, Second Edition". It's right in there. It's the only technical computer book I know that is still accurate after more than twenty years.
I agree it's fun to read and has some good points, but it's obvious it's meant only for really imperative-styled C that you'd expect to find in the kernel. e.g.:
> ... if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
class A:
def foo(self):
while cond:
if othercond:
bar()
Opening braces on the same line means that you can always open a new line for editing with O and o in vi and it will be a valid line for placing code on.
Braces after if, for, while, switch, etc. are on the same line, and yes, it was to save space on the 80x24 screen.
Get a copy of "The C Programming Language, Second Edition". It's right in there. It's the only technical computer book I know that is still accurate after more than twenty years.
I also recommend reading the Linux kernel style guide http://www.kernel.org/doc/Documentation/CodingStyle . It's fun to read and has some good points. Sticks quite close to K&R.