Page 3 of 3

Re: The obvious thing I should've learned 5 years ago

Posted: Sun Mar 14, 2010 1:19 pm
by Synon
earlz wrote:
JamesM wrote:Personally I use "early-exit" operators as much as possible in order to reduce the amount of nesting needed and therefore make code easier to read. That means break, continue, return.

They don't impact performance and it's blatantly obvious what the intention is. If it improves my code's readability, it's worth it. YMMV.
Yup, I believe Linus or some famous coder put it something like "Using break and continue is bad cause it's basically a disguised goto. But if you have over 3 levels of indentation, your screwed anyway"
It wasn't Linus; it was the guy who wrote the kernel coding style file (linux-XX.XX[.XX[-ABC]]/Documentation/CodingStyle). Here's an online version: http://lxr.linux.no/#linux+v2.6.33/Docu ... odingStyle

Re: The obvious thing I should've learned 5 years ago

Posted: Mon Mar 15, 2010 12:24 am
by Solar
"Early return" from a function is different. It is well-defined and completely obvious what is being returned from, and where it returns to.

My personal litmus test is how an NSD of the code would look. Try it yourself; you immediately realize how disruptive "break" and "goto" are to the control flow.