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 ... odingStyleearlz wrote: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"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.
The obvious thing I should've learned 5 years ago
Re: The obvious thing I should've learned 5 years ago
Re: The obvious thing I should've learned 5 years ago
"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.
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.
Every good solution is obvious once you've found it.