Skip to content

Instantly share code, notes, and snippets.

@pallan
Created November 15, 2012 14:28
Show Gist options
  • Save pallan/4078881 to your computer and use it in GitHub Desktop.
Save pallan/4078881 to your computer and use it in GitHub Desktop.
Nested if statements without else conditions
if a || b == d || c != n # lets check a bunch of conditions
if m <= p && a > n # we passed! ok, let's check some more
puts 'YAY' # we passed again!
end # I guess that's all we really needed
end # fine!
@pallan
Copy link
Author

pallan commented Nov 15, 2012

For the record, I am not saying this is wrong (or right). I (suppose I) can see how it can improve readability. It just annoys me to see two if conditionals stacked on each other when no negative conditions exist

@slamotte
Copy link

I agree, and if the conditional logic is that complex, why not extract it into a method? Here's another that boiled my blood:

a = 0 unless a == 0

though when I first saw this, it was written in PL/1:

if a <> 0 then do;
  a = 0;
end;

though to be fair, this was from a programmer who still used GOTOs at the time. The worst was when they would GOTO into or out of the middle of a subroutine, no one could ever explain to me what happened to the call stack when this happened... I'm so glad it's not the early 90s anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment