Re:5 Things They Told You Not To Use In JavaScript
by madrobby on Tuesday April 24, 2012 @07:38PM
(#3886913)
I wouldn't use "with" in most situations, but I like it in the testing code and for some DSLs, as it makes things more readable (again, personal style).
I think that once you start optimizing performance problems you need to 1) measure things anyway, and 2) fix on a case-by-case basis. (Don't optimize prematurely, etc.)
Re:5 Things They Told You Not To Use In JavaScript
by madrobby on Tuesday April 24, 2012 @07:56PM
(#3886967)
In addition I'd say that the interpreter is broken and
should be fixed to be faster. "with" is not deprecated.
Re:5 Things They Told You Not To Use In JavaScript
by chc on Tuesday April 24, 2012 @08:39PM
(#3887108)
The trouble with armchair quarterbacking is that many things are easier said than done. It's not like they're deliberately making your code slower — the with-statement makes certain optimizations unfeasible. Their options are to always disable those optimizations or to do it only when there's a with-statement in scope — there's no third option that makes with-statements magically fast. If you can come up with new optimizations that make the with-statement faster, I doubt they'd turn down your patch.
Re:5 Things They Told You Not To Use In JavaScript
by slexaxton on Tuesday April 24, 2012 @08:10PM
(#3887010)
I don't believe that this is just an oversight because "people say you shouldn't use `with`". It simply cannot be optimized in the way that normal property accessors are. If you look at old IE perf, they're actually pretty close (both really slow).
EDIT: I went ahead and JSPerf'd it, and it is 13x slower to run the example in the article.
http://jsperf.com/with-perf
A lot of times this doesn't matter, but it's not nothing.
Edit 2: Also people avoid using `with` so their minification tools have a better chance. Another thing that can be overcome, but just pointing out that it's not religious dogma that makes people avoid `with`.