3 ms·
You want to learn the specifics of ?? means in this language, but not the boolean projections? It's one thing to be peeved that empty strings or lists are falsy
by naniwaduni 3y ago
You want to learn the specifics of ?? means in this language, but not the boolean projections? It's one thing to be peeved that empty strings or lists are falsy when it's useful for them not to be, but this seems like barking up the wrong tree.
- fieldcny 3y agoI’m not clear on what the point of your response is, the comment you responded to is making an often overlooked point that certain subtleties in how languages implement constructs can create sharp edges, one of those being the null coalescing operator.
- smegsicle 3y agothe point is that lua didn't make the mistake of false 'empty' values, so that particular sharp edge is absent
- DemocracyFTW2 3y agoThe edge of "false 'empty' values" is absent in Lua, indeed, but the `a = b or c`, more often used in the form `b = b or c`, has, in Lua, still the problem that it will evaluate to `c` if `b` is `nil` and when b is `false` which may or may not be what one wants—and often one wants it not. The idiom is commonly used to assign a proper value to a variable that has not been set to an explicit value, i.e. a variable that is `nil`. The assignment `b = b or true` will set `b` to `true` if it was `nil` or `false`; assuming allowable values for `b` are `true` and `false` and the default is `true`, `b` will then never keep the value of `false` and always be set to `true`.
- DemocracyFTW2 3y agoYou almost never want to exploit, in a scripting language, the subtleties of the Boolean projections when writing the (un-) idiom `b = b or b_default`; it is more commonly a mistake made by script kiddies and hand-waving mavericks (i.e. People Who Finish First, a.k.a. People Who Never Write Proper Tests) that has become deeply ingrained due to the Look Ma How Clever effect. If `b` should be a Boolean with a default of `true` then `b = b or true` will quite obviously never allow it to be `false`. Rewrite that and put it in a row of such assignments as in `a = a or a_default; b = b or b_default`; c or c or c_default;` and it looses its fishy smell enough to pass as "OK, trivially no problem here". I've indeed gotten tired by the entire idea of Boolean projections, yes, but that's not the point here, at least not almost always in practice.