Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"Unless" should only be used when the imperative condition is simple.

You don't understand Ruby if you think there is something wrong with trying to have more than one option to do things, imperfect shortcuts and more human-readable code.

Unless works really well when there is one named boolean variable after it and it's named correctly or if the condition is simple to understand.

It also works well when used inline and without an else statement. For other cases "if" is better-suited. But then again "unless" is another option in your tool chain that makes for a more elegant programming language if you're not a stickler and not constantly finding yourself pining for a platonic language.

  user = User.find(2000)
  return unless user
It'd be easier to miss the "!" character in the case of "if !".

It also makes code read better in English.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: