Re:Ask HN: What did the really successful programmers do dif...
by DavidPlumpton on Monday October 08, 2012 @08:59PM
(#4629430)
Specifically try to judge whether an "early exit" leads to simpler, more maintainable code in this particular case. Optimize for lower cost, not for just following a rule.
Re:Ask HN: What did the really successful programmers do dif...
by iopq on Tuesday October 09, 2012 @02:55AM
(#4630331)
Agreed. A lot of the time, early exits just make sense. Instead of holding a variable called "succeeded" and doing a bunch of if elses, why not just continue on every failure? You're only testing for half a dozen side-cases and just exit out early when you encounter any one. No need to wrap all of your actual work in 5 levels of if elses.
Re:Ask HN: What did the really successful programmers do dif...
by 3pt14159 on Monday October 08, 2012 @02:29PM
(#4628147)
That one caught me up too. Maybe if you have full control of the input data and performance is not a concern, then they should be avoided, but "never" is a pretty small set.
Re:Ask HN: What did the really successful programmers do dif...
by CalinBalauru on Thursday October 18, 2012 @04:25PM
(#4670883)
Although 'never' is a very hard word, I found that in real live most code that uses early exists simply breaks SRP (come to think of it 99% of the time that is the case)
I know people will say "but I will only write this little return statement here" before you know it you will "add this little assignment before it returns" ...
Never might be strong but it make a very good point.
Re:Ask HN: What did the really successful programmers do dif...
by startupslayer on Monday October 08, 2012 @02:19PM
(#4628103)
Agreed.
Data are on my side here: a quick perusal of the Quake 3, the Linux kernel, the Clojure runtime, and LevelDB show that Carmack, Torvalds, Hickey, and Dean all use them where appropriate.