4 ms·
Every where you see the "with statements are harmful"/"eval is harmful" drum being hit, you see Douglas Crockford. He's a great guy, and I really respect his op
by jeresig 14y ago
Every where you see the "with statements are harmful"/"eval is harmful" drum being hit, you see Douglas Crockford. He's a great guy, and I really respect his opinion, but I continue to feel that these are legitimately useful aspects of the JavaScript language -- especially if we want to consider JavaScript as the "assembly language" upon which other languages are built.
For with statements in particular, templating and scoped evaluation (I provide an example from the Firebug console in the book) are probably the two areas in which I've seen it most successfully used.
For code evaluation I only have to direct you to the creation of Coffeescript (an entirely evaluated language) whose innovations have directly influenced new versions of the ECMAScript language.
They have their place and when used sparingly, but effectively, the can be formidable parts of a web developer's arsenal.
- ville 14y agoI agree that code evaluation is a valuable feature in the language. But to be accurate, I wouldn't call CoffeeScript an entirely evaluated language, since it's mainly meant to be used by pre-compiling it to JS. (From CoffeeScript website: "While it's not recommended for serious use, CoffeeScripts may be included directly within the browser") Anyway the ability to eval code on the browser is awesome for trying it out or for building an IDE.
- jashkenas 14y agoI agree with what you're saying, but I'd also be remiss if I didn't quibble with this bit: > For code evaluation I only have to direct you to the creation > of Coffeescript (an entirely evaluated language) whose > innovations have directly influenced new versions of the > ECMAScript language. The standard way to use CoffeeScript is to compile it to JavaScript first, and then deploy and run with that. There's zero "eval()" involved. Or rather, doing direct "eval()" of CoffeeScript is possible, and on occasion fun, but is discouraged for all the usual reasons.
- davej 14y agoThere are some peculiarities with the `with` statements, but mainly it is just dog-slow compared to a standard lookup. Last time I checked it was 200-300 times slower to use the `with` statement rather than just doing an `obj.key` lookup. If nothing else, surely it should be avoided in production purely for performance reasons.
- bzbarsky 14y agoThe problem is that "with" statements basically disable lots of JIT optimizations in actual implementations, with browsers either falling back to a much slower baseline jit or running the function containing "with" entirely in an interpreter. So they _can_ be used effectively if one really knows what one is doing, but they're a bit of a footgun.