Re:Read this post ‘unless’ you’re not a Ruby developer
by gsinclair on Tuesday December 13, 2022 @09:45AM
(#33969501)
Only false and nil are falsey, and the language shines for it. There is nothing weird about zero being a truthy value.
Re:Read this post ‘unless’ you’re not a Ruby developer
by jacobsenscott on Tuesday December 13, 2022 @09:54AM
(#33969618)
Yes, this is one of ruby's best features.
Re:Read this post ‘unless’ you’re not a Ruby developer
by fl_ciq on Tuesday December 13, 2022 @09:58AM
(#33969669)
In what other languages does 0 evaluate to true?
Re:Read this post ‘unless’ you’re not a Ruby developer
by nanny on Tuesday December 13, 2022 @10:20AM
(#33969982)
Lua, Elixir, Common Lisp, Scheme, Racket, Clojure.
Most statically-typed languages don't let you evaluate 0 as a boolean.
IMO, 0 is a value, and values should be truthy. 0 being falsy is only a wart from C.
Re:Read this post ‘unless’ you’re not a Ruby developer
by fl_ciq on Tuesday December 13, 2022 @04:14PM
(#33975899)
Thanks for that, I had no idea. Do you know if zero is truthy in erlang? It makes sense for elixir (based on ruby) but I'm wondering if erlang is that way too.
> As a general rule I think that if a language has some feature for which there is already a commonly understood syntax across other languages, it should just use that syntax. If you’re introducing a complete paradigm shift, then that’s fine, but unless is not that: it’s just a different way to write if ! and people jumping back and forth between ruby and, say, javascript, now have one extra idiosyncracy to keep in mind.