LWN.net Logo

Quote of the week

When you write:

if (ret) {
        one_line_statement();
}

somewhere, a puppy dies. And the DRM guys just took out an entire kennel.

-- David Miller
(Log in to post comments)

Quote of the week

Posted Feb 23, 2012 11:12 UTC (Thu) by fhuberts (subscriber, #64683) [Link]

That's all a matter of taste.

I also prefer to do it like this because:
1- then I _always_ use braces, no exceptions
2- it prevents stupid mistakes of adding statements to the if block without adding braces

More consistency = less thinking = good ;-)

Quote of the week

Posted Feb 23, 2012 11:25 UTC (Thu) by sdalley (subscriber, #18550) [Link]

Note the parentheses ().

I think he's objecting to functions that only have one statement in them.

As you say, punctilious use of braces is good practice.

Quote of the week

Posted Feb 24, 2012 0:28 UTC (Fri) by marcH (subscriber, #57642) [Link]

Braces do not matter in this case since the visual signal from them is dwarfed by indentation. In this case braces are just very small visual noise.

> 2- it prevents stupid mistakes of adding statements to the if block without adding braces

Never happens with any decent editor indenting the code.

> More consistency = less thinking = good ;-)

Abuse of consistency can easily lead to verbosity; see Java for instance.

Abuse of anything is bad. Guess what abuse of "less thinking" is.

Quote of the week

Posted Feb 24, 2012 8:42 UTC (Fri) by jezuch (subscriber, #52988) [Link]

> Braces do not matter in this case since the visual signal from them is dwarfed by indentation. In this case braces are just very small visual noise.

One man's noise is another man's cue that that's not just a wrapped line but a completely new statement.

Also, I prefer a style that doesn't transform trivial changes to a single line into a multi-line diff ;)

Quote of the week

Posted Feb 24, 2012 8:54 UTC (Fri) by marcH (subscriber, #57642) [Link]

> One man's noise is another man's cue that that's not just a wrapped line but a completely new statement.

Not everything in perception is relative. Dimensions aren't relative.

Granted: you can skew anything with training but, training is precisely what should be made as small as possible.

> Also, I prefer a style that doesn't transform trivial changes to a single line into a multi-line diff ;)

Very good point.

Identation is not all, unless you're coding in Python

Posted Feb 24, 2012 7:58 UTC (Fri) by rvfh (subscriber, #31018) [Link]

Completely agree. It was a mandatory coding rule in a big company I worked for, and I kept it for the exact reasons you mention.

Quote of the week

Posted Feb 24, 2012 19:11 UTC (Fri) by daglwn (subscriber, #65432) [Link]

Yep. I had to look through the link to figure out what he was complaining about.

I've been burned too many times by adding statements to blocks without branches in other projects.

Quote of the week

Posted Feb 24, 2012 8:29 UTC (Fri) by jimbo (subscriber, #6689) [Link]

Hmm - smells like Perl!

Quote of the week

Posted Feb 24, 2012 11:37 UTC (Fri) by jwakely (subscriber, #60262) [Link]

> And the DRM guys just took out an entire kennel.

I had to read that three times before I saw "kennel" not "kernel" and it finally made sense.

Stupid brain.

Quote of the week

Posted Feb 24, 2012 18:18 UTC (Fri) by bredelings (subscriber, #53082) [Link]

Oh. Right.

Quote of the week

Posted Mar 1, 2012 9:31 UTC (Thu) by renox (subscriber, #23785) [Link]

Thanks, I did the same mistake and worst, didn't realize it until I saw your post..
Not in a good day.

Quote of the week

Posted Mar 3, 2012 23:33 UTC (Sat) by blujay (guest, #39961) [Link]

Ditto! Doh!

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds