Arguments and formal parameters aliasing
brendan at mozilla.com
Sat Sep 27 20:28:51 PDT 2008
On Sep 27, 2008, at 8:14 PM, David-Sarah Hopwood wrote:
> liorean wrote:
>> ~~~~<10.1.3 Variable Instantiation>~~~~
>> [...] If two or more formal parameters share the same
>> name, hence the same property, the corresponding property is given
>> value that was supplied for the last parameter with this name.
> Can anyone explain what the original rationale was for this? To me it
> seems like duplicate parameter names are an obvious programming
> error, and
> it makes no sense from a language design point of view to allow them.
I do not know. Shon Katzenberger of Microsoft may be the only person
who can say. Duplicate formals were not allowed in my original (Mocha)
Netscape 2-3 and rewritten (SpiderMonkey) Netscape 4-era
implementations. JScript allowed them and the standard included them
as a compromise (there were compromises in the "other direction").
> (Yes, I understand that they are disallowed in ES3.1 strict mode,
> and that
> disallowing them in non-strict mode would break compatibility. I'm
> curious what was going through the minds of the ES1 standardizers.)
The rationale is lost to the mists of time. I vaguely recall some
belief that looseness in other parts of the language justified
allowing duplicate formals, but bad doesn't justify worse. The
complexity involved in supporting duplicate formals (compiling and
decompiling) is out of proportion to any subjective value in the
"feature". Really, it's just a botch hammered out during ES1
(Netscape) side too, so I'm not throwing stones.
Anyway, soon we can just "use strict" and move on. :-)
More information about the Es-discuss