Hacker News new | past | comments | ask | show | jobs | submit login

The real problem is that all negatives make it harder to understand things. They open the door for double (and triple) negatives to find their way into the code, and then bang: The only person who can read it is the person who wrote it.

Since unless has a not built into it, it has a lot of potential to confuse people. In my experience, guard clauses are the only place where they make sense.

  def mute_mic  
    return unless mic_active?
  
    ..
  end
In this sense, you know that the entirety of the function is an expected (positive) case.



I agree guard classes are great with unless...other places not so much




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

Search: