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

That's a lot of words for a simple matter of cleanliness. Do not use 'unless' for complex expressions, only single conditions. I personally hate grouped negatives like the one shown:

    !(valid_token && !expired)
This expression is also a double (triple?) negative, and a lot harder to parse. The correct approach is to make the `valid_token` flag take `expired` into account, or add a third variable that represents validity, not append `expired` to the unless clause. This keeps everything readable, if the variable names are descriptive enough:

    valid_token = token.valid? && !expired
    return 'invalid' unless valid_token
It's also damning that the author uses `unless ... else` as his starting point for the critique, while he is aware that the style guide says "Do not use unless with else" (briefly acknowledged in the last section).


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

Search: