News for hackers. Stuff that matters.
Re:Preparing Yourself for Modern JavaScript Development by wickedchicken on Friday July 06, 2012 @11:37AM (#4208187)
I always find it odd that the same developers who deride PHP look at things like IIFE and think "wow, JS is a cool, modern language!"

Thanks for the article though, if I ever need to write some JS this will help keep me a little more sane.

Re:Preparing Yourself for Modern JavaScript Development by azakai on Friday July 06, 2012 @02:41PM (#4209070)
> I always find it odd that the same developers who deride PHP look at things like IIFE and think "wow, JS is a cool, modern language!"

I don't deride PHP (I don't know it), but I see nothing wrong with IIFE. Yes, it could benefit from some syntactic sugar, but otherwise it is just using one of the best features of JavaScript, function support (first-class functions, anonymous functions, etc.).

It makes perfect sense to use a pattern like IIFE in order to encapsulate code, often using closures to allow access in a controlled manner from the outside, etc.

I suppose perhaps you don't like closures and so forth, and that's fine, but many people including me love them.

Re:Preparing Yourself for Modern JavaScript Development by ufo on Friday July 06, 2012 @02:55PM (#4209132)
IIFEs are cumbersome and non-intuitive. Better languages have block scope or a "let" statement instead.
Re:Preparing Yourself for Modern JavaScript Development by grannyg00se on Friday July 06, 2012 @06:19PM (#4209899)
Javascript [does/will]* have a "let" statement.

*depending on which version of ECMAscript is being used.

Re:Preparing Yourself for Modern JavaScript Development by TazeTSchnitzel on Friday July 06, 2012 @06:09PM (#4209875)
`let` is drafted for ECMAScript 6.
Re:Preparing Yourself for Modern JavaScript Development by georgemcbay on Saturday July 07, 2012 @12:37AM (#4210739)
...and ECMAScript 4 had block scope.

Language design by committee is seriously flawed and until a feature is shipping in all the major browsers it isn't real.

Re:Preparing Yourself for Modern JavaScript Development by TazeTSchnitzel on Saturday July 07, 2012 @04:53AM (#4211160)
ECMAScript 4 was cancelled.
Re:Preparing Yourself for Modern JavaScript Development by georgemcbay on Saturday July 07, 2012 @02:08PM (#4212276)
That was exactly my point.
Re:Preparing Yourself for Modern JavaScript Development by ufo on Friday July 06, 2012 @02:06PM (#4208940)
The first time I saw something like IIFEs was in one of the SICP lectures, where they show that variable definitions with let or define can be seen as syntactic sugar over immediately invoked lambdas.

And even those Scheme uber-nerds considered it big hack, more useful in theory then in practice.

Re:Preparing Yourself for Modern JavaScript Development by silentbicycle on Friday July 06, 2012 @09:00PM (#4210332)
It's useful as a de-sugaring step during compilation, not something people generally do by hand.
Re:Preparing Yourself for Modern JavaScript Development by ufo on Sunday July 08, 2012 @01:27AM (#4213750)
Continuation Passing Style is also supposed to be used as part of acompilation step but look at how everyone does in by hand in Javascript-land :(
Re:Preparing Yourself for Modern JavaScript Development by silentbicycle on Wednesday July 11, 2012 @02:33PM (#4230618)
For real. I tried to find a way to point that out without sounding snarky, gave up.
Re:Preparing Yourself for Modern JavaScript Development by DivisibleByZero on Friday July 06, 2012 @02:42PM (#4209080)
Exactly my thoughts. There really needs to be some healthy competition in client side languages.
Re:Preparing Yourself for Modern JavaScript Development by tomjen3 on Friday July 06, 2012 @03:44PM (#4209323)
Oh definitely. Or rather we need a vm designed to write code that can be optimized to run fast (personal dream, allow me to optionally include typing information. I already type my JS, might as well make it run better).

This means that the vm would be lowlevel enough that performance would start to approach that of native code, with complete freedom for the programmer to write the code for it in any language he desired.

The browser would then be able to execute this code instead of the corresponding Javascript file (e.g you compiler outputs two different object codes, one minified javascript for legacy browsers, one modern vm file for modern browsers).

Re:Preparing Yourself for Modern JavaScript Development by TazeTSchnitzel on Friday July 06, 2012 @06:10PM (#4209882)
You'll be disappointed to know that Dart doesn't use bytecode.
Re:Preparing Yourself for Modern JavaScript Development by kmontrose on Friday July 06, 2012 @06:25PM (#4209921)
There's a wholly unconvincing argument as to why Dart isn't pushing a VM as well, http://www.dartlang.org/articles/why-not-bytecode/ . Might as well be titled "Why not the JVM?" in my opinion.
Re:Preparing Yourself for Modern JavaScript Development by TazeTSchnitzel on Friday July 06, 2012 @06:27PM (#4209928)
It isn't unconvincing. They make the case that bytecode is not assembly in reality, and constrains what you can do in languages compiled to it.
Re:Preparing Yourself for Modern JavaScript Development by kmontrose on Friday July 06, 2012 @11:05PM (#4210583)
Nonsense, a VM is what it's defined to be. If you wanted the x86 (or ARM, or PPC, etc.) instruction set to be your bytecode, you've got it.

That article starts from the assumption that any in browser VM will resemble the JVM; which is a faulty assumption. In fact, any in browser VM would have to be very different from the JVM since Rule 0 for any such VM would be "acceptable Javascript performance".

From that article:

> Meanwhile, JVMs don't do these optimizations. Since all types are statically

> known, the compiler knows exactly how much storage they need and what

> operations they support. It can then generate appropriate tight code for those

> types. This is fast if your language is statically typed, but if you're trying to

> compile a dynamically typed language to the JVM, it won't be able to run as fast as a

> VM that can assume dynamic typing all the way down and optimize specifically

> for that.

A whole wasted paragraph. Of course a browser VM wouldn't be statically typed, that'd make compiling/running Javascript a bear. One would hope there'd be some system of type-hinting, because eliminating dynamic dispatch is really low hanging fruit in terms of optimization, but JVM/CLR-style static typing? Madness.

Re:Preparing Yourself for Modern JavaScript Development by tomjen3 on Saturday July 07, 2012 @02:05AM (#4210873)
Dart isn't relevant, since google isn't pushing it nearly hard enough.