Re:Why was "goto fail;" added without any other change to th...
by wmgries on Friday February 28, 2014 @11:15AM
(#7319609)
Also, you almost never need to use goto.
Re:Why was "goto fail;" added without any other change to th...
by chrismcb on Friday February 28, 2014 @11:35AM
(#7319760)
This isn't goto's fault. A return, or a "finished = true;" or a ton of other code could have had the same result. Using a goto means it is easier to find it than some other similar mistakes.
Re:Why was "goto fail;" added without any other change to th...
by bakhy on Friday February 28, 2014 @11:40AM
(#7319808)
All three of those patterns are something which would lead me to consider is there a more functional-style option available to rewrite the method in question. I'll take a gigantic nested if over a split-end method (multiple exit points) any day of the week ;) But of course, such things cannot be avoided completely, nor will avoiding them magically eliminate all bugs in the universe..
Re:Why was "goto fail;" added without any other change to th...
by DanHulton on Friday February 28, 2014 @01:33PM
(#7320578)
Hm, and I'm of the opposite opinion. I like methods that fail early. Gigantic if-chains are hella-hard to parse.
I should go consult Code Complete again, actually...
Re:Why was "goto fail;" added without any other change to th...
by Dewie on Friday February 28, 2014 @11:30AM
(#7319716)
Does no one use a pretty printer before committing code? Pretty printing would eliminate any doubt as to what code belongs to what if-statement and the like.
Re:Why was "goto fail;" added without any other change to th...
by micro-ram on Friday February 28, 2014 @11:36AM
(#7319768)
I use Astyle to enforce both braces and indentation automatically. In VC Pre-Build Event add:
Astyle -A1 -j -c -v asterisk.cpp asterisk.h (Sorry asterisks italicize on HN) http://astyle.sourceforge.net/
This is why you always, always, ALWAYS put braces around your if()s.
(I'm not religious about what line the open brace goes on, but I will reject any code review that skips the braces entirely.)