3 ms·
> if a language has False/None/Null/Nil as first class values, then the only sane path is for everything else to be True I very much disagree. Every type shou
by anamax 4y ago
> if a language has False/None/Null/Nil as first class values, then the only sane path is for everything else to be True
I very much disagree.
Every type should have a false value.
Note that False is a bool while None/Null are pointers/references and Nil is Lisp's empty list. (Python's empty list is [] and it also has empty tuples.) Why should those types and no others have a false?
- sph 4y agoNot necessarily every type, but just those that obviously look false: False, 0, null. Empty string iff it's a very high level language. Empty list iff it's a lisp. But better yet, `if` should only accept a boolean expression. Passing a string to `if` should be a type error.
- Espressosaurus 4y ago0 shouldn't be false. 0 compared to something can be false. Null isn't false. Null compared to something can be false. The entire concept of "falsey" makes my teeth ache. Non-boolean expressions in a boolean context is asking for a runtime error.
- anamax 4y ago> Non-boolean expressions in a boolean context is asking for a runtime error. And yet, it doesn't, in strongly-typed languages that define which values are "false" and "true" for types such as strings, sets, dictionaries, and yes, even numbers.
- anamax 4y agoIt's unclear why empty strings or lists should be considered false yet it's somehow evil for empty sets to be considered false. The purpose of type checking is to help people write correct programs. It's unclear that requiring "if {string}.isempty() ..." does that better than "if {string} ..." in a strongly-typed language.
- joe-collins 4y agoThe notion that any non-boolean type has a "false value" is strange to me. There's some convenience in it, certainly, but I don't see it making sense on a more basic level.
- imtringued 4y agoOne could define a BooleanConvertible interface with a toBoolean() method.
- matt_kantor 4y agoWhat's the false value for my EmailAddress type?
- deleted 4y ago[deleted]
- darthrupert 4y agoTo me that makes just as much sense as saying that every type should have a zero, or that every type should have the empty string. Just nonsense. If a type is not a boolean already, the only way to get a boolean out of it is by using a comparison function.
- kazinator 4y agoThe fact that there is exactly one false object in Lisp means that we can test whether a value is false extremely efficiently, even in the presence of any static type inference. It's just a machine instruction to compare the value's bit pattern to the NIL bit pattern.