Readable code (Was: Re: [H-GEN] Which is better?)

David de Groot david-humbug at viking.org.au
Wed Apr 28 08:45:56 EDT 2004


On 28/04/2004, at 9:53 PM, Adrian Sutton wrote:
> <snip>
>
> So for Java code I would follow the Sun Java coding convention:
>
> if (orient == east) {
>     if (x + radius > side) {
>         if (clockwise) {
>             orient = south;
>         } else {
>             orient = north;
>         }
>     } else {
>         x = x + step;
>     }
> } else if (orient == south) {
> ....
>
> Note the use of spaces around operators and the brace on the same line 
> style.  Both of these styles are hallmarks of Java code.  There's no 
> need to be too pedantic about the fine details though.
>
> However, if I were writing in C, I would say the style that should be 
> used would be the second one you quoted but probably with spaces 
> around the operators.  Braces however would be the on the next line 
> type.
>

I tend to code like the above in C or perl (I don't do Java). But can 
equally justify the separate line for braces philosophy too.

The exception being else if statements, which for some reason I tend to 
put on a new line (but indented to where line up with the closing brace 
of the previous block). Yet again, this isn't a hard and fast rule but 
I try to remain consistent over a project.

Indents are either 3 or 4 spaces (but consistent over a project).

> <snip>
> Anyway, I would be interested to hear from people who like different 
> styles to these as to why their preference goes that way, even if it's 
> a very informal "I find whitespace makes it harder to parse chunks of 
> code".

Dave





More information about the General mailing list