Thanks! In fact, your first example of the while loop is almost exactly how I format it. The only very minor difference is that I don't put a space before the first parenthesis:
while(
a &&
b && c
) {
a = a + 1;
b = b - 1;
}
That's not a big difference; the only reason I leave out that one space goes back to my idea of having fewer formatting rules and special cases. I don't put a space before the open paren on a function call, so I don't put one there on a statement that has parens either. Not a big deal either way, I'm just lazy and like to have one rule instead of two. :-)
I experimented in the past with some other ways of formatting this kind of code, e.g.
while (
a &&
b && c ) {
a = a + 1;
b = b - 1;
}
Of course you can see the problem here - there's no visual separator between the while expression and the statements in the loop body.
That's why some coding standards require a double-indent:
while (
a &&
b && c ) {
a = a + 1;
b = b - 1;
}
That never appealed to me at all, but when I started moving the close paren to the next line and dedenting it there was no need for the double indent.
Those are nice - especially the second one, which is a great illustration of how you can use thoughtful alignment in a monospaced font to make the logic in a piece of code really stand out.
It's very different from the examples of column alignment I was critiquing in my earlier message, where there's an equally good or better way to format the code using indentation only.
All in all, I still prefer the visual appearance and compact nature of proportional fonts, especially my current favorite, Trebuchet MS - and they do just fine for almost all the code I write. But for all my criticism of column alignment, I have to admit I do miss it in cases like your second example where it brings clarity.
My dream editor would have a way to allow the use of both proportional fonts where they work well and monospaced fonts where they are better, all within the same file. Perhaps a special commenting convention that would let you switch back and forth.
One of the editors I use, Komodo, has a bit of this. When you create a custom visual theme, you can specify both a proportional font and a monospaced font, and either toggle the entire file back and forth with a hotkey or select one font or the other as part of syntax highlighting - similar to the way many editors let you select bold or italic for particular syntax elements. For example you can select a monospaced font for comments so you can do ASCII art there, while using a proportional font for other code.
First I just want to thank you for the very pleasant reply. More often than not people online tend to get very religious and downright mean about things like convention like this, so thank you the dialog here has been refreshing.
It's not exactly what you are after, but I think is more fundamentally what you are after - ways to make it easier to understand what code is doing. You can have the best of both worlds too here with something like noweb and two windows.
One other thing I ran into is a code base that had incredibly long lines (more than 132 often). So I started using ndiff to help me there. It's a python script that puts + and - under the lines where the differences are as well. I also wrote a little script to html it with different colors. It was pretty awful until I made it monospace too sadly.
I experimented in the past with some other ways of formatting this kind of code, e.g.
Of course you can see the problem here - there's no visual separator between the while expression and the statements in the loop body.That's why some coding standards require a double-indent:
That never appealed to me at all, but when I started moving the close paren to the next line and dedenting it there was no need for the double indent.