This seems rather odd from example 14: // Boolean expressions need to resolve to either true or false, as no // implicit conversions are supported. I'm sure they have good reason for this, does anyone know of the rationale? I think I'd miss patterns like `if (arr.length) { ... }`
Implicit coercion is often a source of bugs. Some languages simply mandate that you be explicit about your intent. It can be slightly more verbose, but you gain clarity and reduce ambiguity. With implicit coercion, the programmer must mentally keep track of how values get coerced (are negative numbers truthy? are empty strings? empty lists? empty objects?). Different languages have different answers for all of these…
The Angular team, for instance, has defined toBool() (which they use in directives like ng-if) like this:
bool toBool(x) {
if (x is bool) return x;
if (x is num) return x != 0;
return false;
}
It treats true and non-zero numbers as true, and everything else (including null) as false.