C++ style question/criticism, was Re: Mozy Contest Answers

Levi Pearson levi at cold.org
Sat Nov 4 20:30:56 MST 2006

On Nov 4, 2006, at 7:25 PM, Roberto Mello wrote:

> On Sat, Nov 04, 2006 at 07:09:50PM -0700, Levi Pearson wrote:
>> space.  What is the point of putting curly braces on lines all by
>> themselves?
> It looks better.

You've got to be kidding me.

> Yes. It looks better. Code should be written with readability in mind.
> "Beautiful is better than ugly".
> Braces on the same line as opposed to a line by itself is personal
> preference. But   if (foo) { do something }   is butt ugly and  
> makes it
> harder to read, and should be avoided IMNSHO.

C++ is just butt-ugly no matter what you do; spreading it over a  
bunch of lines doesn't improve the situation, it just means you can  
see less of your code.  You'll note that there are no dangerous  
ambiguities or anything; I put the 'do something' inside braces to  
combat that argument, though I'd normally leave them off if I put a  
statement on the same line as a conditional.  Because I think it  
looks better that way.

There is more to readability than subjective opinions of beauty,  
though.  For one, if something is not visible, it is not readable.   
Therefore, my formatting was objectively more readable than the  
original.  That trumps some abstract and ill-defined notion of beauty  
in my book, though I happen to think mine looks much better anyway.

I didn't simply erase all the extra space, either.  You'll note I  
left in spaces to separate structures in the code, as a sort of  
punctuation.  When there's more whitespace than code, as in the  
original formatting, such subtle additions are practically invisible  
and just contribute to the vertical space bloat.


More information about the PLUG mailing list