3 ms·
All programming languages have some problems in this department. Some lisps for instance use the empty list nil for false, others have a distinct #f value. E
by PaulHoule 2y ago
All programming languages have some problems in this department. Some lisps for instance use the empty list nil for false, others have a distinct #f value. Each of those choices has strengths and weaknesses.
Dynamic programming languages usually have some arbitrary rules about what X is treated true or false in
if(X) (…}
whatever rules are used are what you want almost always except for the times that they aren’t. A strongly typed language like Java will require X to be a boolean which now puts a load on the programmer to choose some f such that
if(f(X)) {}
which could be correct every time in principle but a small increase in cognitive load is certain while most likely the f you choose (inclusive of your choice and it’s action) will do the right thing almost all the time except when it doesn’t. So I wouldn’t laugh at any particular programming language’s almost-right choice for ‘casting’ any to boolean because people are going to screw it up in any programming language.