For example, in Swift
let f: Float = 1.0
let d: Double = f
is invalid code. You have to write let f: Float = 1.0
let d: Double = Double(f)
In such languages, true is true, false is false, and all other values are neither true nor false.I think that, certainly for booleans, that’s the sanest choice.
In any case, the next thread down is making the same point, and specifically calling out languages that do exactly this and get it right: Clojure, Lua, Ruby, and others.
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?
But better yet, `if` should only accept a boolean expression. Passing a string to `if` should be a type error.
The entire concept of "falsey" makes my teeth ache.
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.
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.
If a type is not a boolean already, the only way to get a boolean out of it is by using a comparison function.