3 ms·
"nil is greater than any integer", that was astounding. Which languages have a no-data is bigger than max_int rule?
by a3w 4y ago
"nil is greater than any integer", that was astounding.
Which languages have a no-data is bigger than max_int rule?
- throwawaymaths 4y agoThere is a total order on (almost) all data types in the beam. This is useful for arbitrary sorting and comparison of different types. I say almost because floats and their equivalent integer are different items but they are equal in the total order. In practice this is fine, and I have never heard of this causing a problem.
- a3w 4y agoFor me, no data is either NaN or zero, but +infinity is was the astounding part. Also, for some languages, not failing with an exception when comparing different strong types, could be a source of bugs, generally.
- throwawaymaths 4y agoIn Elixir, nil is an atom (a global enum namespace), it's not a special data type that has meaning outside of a convention (heavily supported by the stdlib) that "you should use it to mean nothing"[0]. To hammer this home, nil is meaningless and not generally understood by that convention in Erlang (which often returns undefined). Elixir/BEAM is strongly typed. There is no coercion going on when you are doing comparisons. [0] note that in elixir, "if" is in the stdlib, it's sugar over case, and the falsiness of nil is software-level (only false and nil are falsy in elixir, which is sane).