3 ms·
The `||` pattern is super common in a bunch of languages though and to code it with a `== null` test you would need to expand it to a full blown ternary operato
by ufo 11y ago
The `||` pattern is super common in a bunch of languages though and to code it with a `== null` test you would need to expand it to a full blown ternary operator
name != null ? name : "default name"
Some languages have a "null-coalescing" operator you can use in these cases but its a niche thing.
(And I agree with you on the Maybe thing but, as I said previously, 0 in conditionals is not a problem when conditionals have to be boolean)
- JoshTriplett 11y agoMy point is, you should be checking for null or None or equivalent, rather than boolean false; once you do, 0 being false is no more or less of a problem than false being false.
- Someone 11y ago"Some languages have a "null-coalescing" operator you can use in these cases but its a niche thing." I see that not as niche, but as a fairly recent invention, or at least one that recently is becoming popular. IMO, C#'s ?? is superior to reusing binary operators. Advantages are that it looks more like the ternary operator, and that it doesn't require adding implicit conversions to boolean to your language.