As a non-native English speaker, when I read an unless on a codebase it gives my brain extra work to make sure when the condition will evaluate to true. It's possible that it is due to unfamiliarity, though.
Yes, and the same is true for English speakers as well I think.
I like to avoid #unless by ensuring that there is an inverse logical test available, just as #any? and #empty? are inverses.
I think that some Rails developers don't realise that just as you can call #valid? on a model, you can also call #invalid?, so you can avoid do_this unless my_model.valid? in favour of do_this if my_model.invalid?.
I think the latter reads much better.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
As a non-native English speaker, when I read an
unless
on a codebase it gives my brain extra work to make sure when the condition will evaluate to true. It's possible that it is due to unfamiliarity, though.Yes, and the same is true for English speakers as well I think.
I like to avoid
#unless
by ensuring that there is an inverse logical test available, just as#any?
and#empty?
are inverses.I think that some Rails developers don't realise that just as you can call
#valid?
on a model, you can also call#invalid?
, so you can avoiddo_this unless my_model.valid?
in favour ofdo_this if my_model.invalid?
.I think the latter reads much better.