reformed with

Yuh-Ruey Chen maian330 at gmail.com
Sun Feb 4 04:31:29 PST 2007


I've been looking at the reformed with proposal. It seems that using a
let statement would be much easier than writing a reformed with
statement. Compare:

with (obj.obj2: {a: int, b:Object, c:String, d:Array) {
  a = 10;
  var x = b;
  c = 'hi';
  d.push(5.5);
}

vs.

let (o = obj.obj2) {
  o.a = 10;
  var x = o.b;
  o.c = 'hi';
  o.d.push(5.5);
}

Brendan makes the argument that "migrating code should not require
hand-expanding with to get precise types", but I would argue it would
take just as much time (if not more) to look within the |with| block to
see what properties need to be in the object literal and defining their
types there, than to change the whole thing into a let statement. An
example (sample code found with google code search):

    with ( this.DOMTable )
    {
        // Sets the toolbar direction. IE uses "styleFloat" and Gecko
uses "cssFloat".
        style.styleFloat = style.cssFloat = FCKLang.Dir == 'rtl' ?
'right' : 'left' ;

        cellPadding = 0 ;
        cellSpacing = 0 ;
        border = 0 ;
    }

What's easier here? Changing the first line to |with(this.DOMTable:
{style: Object, cellPadding: int, cellSpacing: int, border: int})|. Or
changing the first line to |let(o = this.DOMTable)| and prefixing each
appropriate property with |o.|. Note that in both cases, the author has
to search through the |with| block to see which names are properties of
DOMTable. It's bad either way. Moreso for reformed with IMO, since you
also have to enter the types of each property.

There's also the argument of discoverability. Script authors are likely
to learn the new let syntax since it can be used pretty much anywhere.
The reformed with syntax, on the other hand, is a bit obscure. If a
feature isn't that discoverable and there's an alternative feature that
is and is just as good, I'd say drop the less discoverable feature.

Unless there's reformed with would result in noticeably better
performance than the let equivalent, I'd say that |with| is a lost cause
and reforming |with| is unnecessary.

-Yuh-Ruey



More information about the Es4-discuss mailing list