TSa (Thomas Sandlaß) wrote:
> Can't we have that as a general feature of all operators?
> That is:
>    my ($x, $y);
>    say $x * $y; # prints 1
>    say $x + $y; # prints 0
> It is a cleaver idea to make the operator choose an appropriate
> value for a Nothing value. Why having that only for meta operators?

Because it throws out the utility of the undefined value warning as a way to
catch mistakes.

Why special case increment and decrement?  Two reasons IMO.  Incrementing has
a very narrow use case and it's pretty hard to screw up.

Second is that it's really annoying if you don't.  Try working in Javascript
which doesn't.  You find yourself doing "input ||= 0" a lot... except oh wait
you can't do that because ||= doesn't work on undef in Javascript.  This is
the best I've come up with. [1] [2]

    input = (input || 0);

Point is, certain <op>= quietly treating undef as 0 avoids yucky constructs to
appease fussy compilers.  The rest, leave alone so the undef warning can do
its job.

[1] I am not a Javascript programmer, but I haven't seen anything better.

[2] Nevermind there's not a proper defined check in there.  That would be
      input = input === null ? input : 0;
    but most languages don't have a built in dor operator so we won't
    penalize Javascript for that.

185. My name is not a killing word.
    -- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army

Reply via email to