At work today I saw this little beauty at the end of a method with void return type:
if(true)
return;
I thought it was quite wise of him to check that. Incidentally, the author of this little koan now works at Google.
living la vida obscura
{ 2006 10 27 }
At work today I saw this little beauty at the end of a method with void return type:
if(true)
return;
I thought it was quite wise of him to check that. Incidentally, the author of this little koan now works at Google.
DAR | 27-Oct-06 at 6:45 am | Permalink
Sounds like fodder for thedailywtf!
Brent Ritchie | 14-Nov-06 at 12:02 pm | Permalink
I think someone needs a little practice with DeMorgan’s Laws and basic Logic Principles. This is totally not cool, and unacceptable. I could only imagine how much redundent checks like these slow down execution and clutter the control flow of a program.
Peter Holm | 04-Dec-06 at 11:50 am | Permalink
Haha I love the title “but wait, perhaps we can optimize it further!”.
Reg Braithwaite | 13-Aug-07 at 7:46 am | Permalink
The good news is that this should have NO effect on performance. Just about every compiler and interpreter implementation out there can optimize the test and the return statement away.
I recall writing a Scheme implementation in 1998 that optimized this sort of thing just so that I could use my own version of #IF statements without incurring runtime costs.
That being said, now we can count the cost of human capital. How long does it take a programmer reviewing this code to recover from the inevitable coughing/laughing fit?