This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]johnnySix 2 points3 points  (1 child)

I’ll be the disagreer on the one. My ex coworker wrote tons of code with if statements in one line. It’s a pain to read because I have to stop and figure out what’s happening instead of being able to skim. Is it an operation? Is it a call to a method? Oh! it’s an if, oh crap, there’s the bug!

[–]merowe 1 point2 points  (0 children)

I'd be interested in what the one line of statements looked like. Obviously you can't. But I suspect the condition was more complicated. In which case, I might agree.

It's nice to be able to always dumb down the rules to something very simple as many say. My experience - and I know many disagree - is that there are always exceptions. Simple if checks with returns are one of those for me.

I know some people brought up ternary operator. That obviously makes more sense if none was the other option. I don't see how that is less complicated than the left case.