What about this?
int c[] = {
3, 6, 9,
12, 15, 18,
...
300, 303, 306
};
or int v =
((r << 24) & 0xff000000) |
((g << 16) & 0xff0000) |
((b << 8) & 0xff00) |
( a & 0xff) ;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.
Thanks for sharing those examples!
You might be interested in literate programming:
https://en.wikipedia.org/wiki/Literate_programming#Tools
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.
Cheers!
int v =
((r << 24) & 0xff000000) |
((g << 16) & 0xff0000) |
((b << 8) & 0xff00) |
( a & 0xff) ;
Is there a reason you're doing the shift before the mask? I find this much less intuitive than the equivalent int v =
((r & 0xff) << 24) |
((g & 0xff) << 16) |
((b & 0xff) << 8) |
( a & 0xff) ;Cause it was like 1AM here when I wrote it?
Take your pick ;)
Yeah I'd totally write the bottom way I think, or I hope, cheers.
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.