4 ms·
The unless is still harder for me to grok. The if !ruby_dev (read as "if not ruby_dev") is so much easier.
by asdajksah2123 4y ago
The unless is still harder for me to grok.
The if !ruby_dev (read as "if not ruby_dev") is so much easier.
- nickelcitymario 4y agoFascinating! I find it slightly easier to understand "unless" than "if not". But only oh-so slightly, and probably not enough to justify making it harder for others to read my code.
- burke 4y agoFor some reason this one feels right to express with if-not to me too. The one place I’ll often use unless is things like: return unless valid raise unless h.key?(k) I think it might have something to do with: 1. How abundantly clear it is that the condition is a Boolean; and 2. The “false” condition indicating a “no work to do” situation. I think I only use them for postfix return, break, next, and raise.