DEV Community

Discussion on: What language features/concepts do insiders of the language love and outsiders hate?

Collapse
 
bobbypriambodo profile image
Bobby Priambodo

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.

Collapse
 
databasesponge profile image
MetaDave 🇪🇺 • Edited

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.