Hacker News new | ask | show | jobs
by fl_ciq 1278 days ago
Unless seems to be pretty common in many languages. https://www.indifferentlanguages.com/words/unless In my mind the javascript community would do well to address the idiosyncrasies in its language standard before criticizing other languages for using common human language patterns. If you want to pick on ruby for being weird with conditionals, consider the following.

   if 0 
     puts 'true'
   end
which will print true. I think there is a much greater chance that 0 being true will cause problems with programmers from other languages than using unless which is quite natural to humans. Ruby is first and foremost a language for humanity, and probably dead last a language for ease of implementation.

> 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.

1 comments

Only false and nil are falsey, and the language shines for it. There is nothing weird about zero being a truthy value.
Yes, this is one of ruby's best features.
In what other languages does 0 evaluate to true?
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.

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.
>Do you know if zero is truthy in erlang?

I don't know off the top of my head, but I would assume that yes, zero is truthy in Erlang as well, since Elixir is fully compatible with it.