On 27 December 2012 05:36, David Herman <dher...@mozilla.com> wrote:

> On Dec 26, 2012, at 7:40 PM, Brendan Eich <bren...@mozilla.com> wrote:
>
> >> Many also believe that hoisting is an excellent feature, not a
> weirdness.
> >
> > For functions, I can defend hoisting, although if I had had more time, I
> might have done a let ... in ... or BCPL'ish equivalent form that groups
> the recursive bindings. For vars hoisting is pretty much an implementation
> abstraction leak in JS1 :-P.
>
> I absolutely can defend hoisting. (It's hoisting to *function scope*
> that's the issue, not hoisting itself.)


I think hoisting can mean different things, which kind of makes this debate
a bit confused.

There is var-style hoisting. Contrary to what Rick said, I don't think
anybody can seriously defend that as an "excellent" feature. First, because
it hoists over binders, but also second, because it allows access to an
uninitialized variable without causing an error (and this being bad is
where Dave seems to disagree).

Then there is the other kind of "hoisting" that merely defines what the
lexical scope of a declaration is. The reason we need this
backwards-extended scope is because we do not have an explicit let-rec or
something similar that would allow expressing mutual recursion otherwise --
as you mention. But it does by no means imply that the uninitialized
binding has to be (or should be) accessible.

Here's the rationale:
>
> - JS is dynamically scoped, so having an implicit dummy value isn't a
> problem for the type system.
>

I think that's red herring. An implicit dummy is bad regardless of types.
It rather speaks for types that they would prevent it. :)

- It automatically makes forward references work, so you can:
> * order your definitions however it best "tells the story of your code,"
> rather than being forced to topologically sort them by scope dependency
> * use (mutual) recursion
>

Right, but that is perfectly well supported, and more safely so, with TDZ.

- It binds variables without any rightward drift, unlike functional
> programming languages.
>

I totally don't get that point. Why would a rightward drift be inherent to
declarations in "functional programming languages" (which ones, anyway?).

So yes, you are right, we need hoisting. Nobody seems to disagree with
that. We only seem to disagree about what kind of hoisting we mean by that.
You have argued for a more var-like hoisting, but I honestly still cannot
see why you would consider that a good thing.

/Andreas
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to