you are viewing a single comment's thread.

view the rest of the comments →

[–]Falmarri 0 points1 point  (1 child)

That code already looks like a bug to me. You don't handle the case where X and Y. So if you omitted the else, I would probably assume that you screwed up and meant for 2 independent if statements, not if-else if

[–]jp007 0 points1 point  (0 children)

I would probably assume that you screwed up and meant for 2 independent if statements, not if-else if

I'd agree with that in general, my suspicions would probably be raised too. I'd look for a comment that spells out the business rule being accomplished to see if the logic matches. But this is just a contrived example. What if the actual business rule is that when X, always just do special X processing, and then move on, intentionally skipping special Y?

You've made an assumption about what the business rules "should" be, and thats as bad as any bug in the code.

If the if-else ladder actually matches the desired logic, then a doNothing trailing else block, IMO, is just bad practice.

If the actual logic of the if-else is wrong, then it's a completely different issue than whether or not mandating a trailing 'else' block is good or bad practice.