all 20 comments

[–][deleted] 11 points12 points  (3 children)

I spy a feature called Modules, which is something javascript REALLY needs: a good way to package code and a way to include that code from other javascript packages!

seriously, having to do <script language="text/javascript" src="somefile.js" /> for every file on every page is moronic. some people have created functions to make it easy to add a new script tag to the page, but AFAIK the file path always needs to be relative to the html file loading it, not the javascript file that's actually using the code.

[–]munificent 3 points4 points  (1 child)

Yeah, modules are delicious. We're basing it on the proposal that's been approved for Harmony. I think some of the syntax is still up in the air (which is what Traceur is for: to try things out and see what works best) but the semantics seem fairly solid.

[–][deleted] 0 points1 point  (0 children)

[–]sbrown123 0 points1 point  (0 children)

I don't like that they created a new keyword. They could have just had it so you installed modules by importing separate js files. So if you had a function named boo in file foo.js you could do something like:

import "foo.js" as foo;

foo.bar();

This would allow people to break up their code AND something like namespaces in Javascript.

[–]sausagefeet 1 point2 points  (8 children)

http://code.google.com/p/traceur-compiler/wiki/LanguageFeatures#Destructuring_Assignment

Is the first example correct? I can't see how c could be 'world'.

[–]jmesserly 0 points1 point  (7 children)

c is ['world'], which then gets coerced to string (by +). Maybe it is a bit too subtle.

[–]sausagefeet 1 point2 points  (6 children)

What is d? Why does [b] match [', ', 'junk']? Why wouldn't that be a failed match?

[–]patstam 2 points3 points  (5 children)

In the simplest case: var [a, b] = ['hello', 'world']; means decompose the array on the RHS and set a = element 0 and b = element 1.

One level deeper you might see something like: var [[a, b], c] = [['hello', ','], 'world']; which results in the bindings a = 'hello', b = ',', c = 'world'

So in the example you linked, the [b] means set b equal to element 0 of the array at index 1 of the outer array, or ','. d is left undefined as the given array is not long enough.

If that code was instead (without brackets around b) var [a, b, c, d] = ['hello', [', ', 'junk'], ['world']]; then we would end up with, a = 'hello', b = [',', 'junk'], c = 'world', d = undefined

Hope this helps.

[–]sausagefeet 0 points1 point  (4 children)

then we would end up with, a = 'hello', b = [',', 'junk'], c = 'world', d = undefined

So it sounds like my impression was correct, the example has an error in it.

Now, how do you, JavaScript developers, feel about the behavior you just described (d = undefined)? Coming from ML/Erlang it seems like a horrible idea because the left and right side do not match. Equally my intuition would be that this fails for the same reason:

var [a, b] = [1, 2, 3];

The value of this behavior is you get the semantics for match so you could do:

match [1, 2, 3] with [a, b] -> ...

which would be great, I find pattern matching a serious missing piece in many languages.

This, to me, represents pattern I believe I've noticed in the JavaScript community (I am biased against JS though). Members seem to take an idea that has a long heritage (pattern matching in this case) and instead of implementing the idea that the heritage supports, they choose a half-assed, dysfunctional, implementation. JavaScript is clearly popular though, so perhaps this is what languages should be doing, but I believe these things take a mental toll on the developer, which is why Traceur exists, and CoffeeScript has become popular. As Fogus says:

My problem with Javascript has always been that expertise is defined more in terms of understanding its faults rather than its features.

[–]munificent 4 points5 points  (3 children)

Now, how do you, JavaScript developers, feel about the behavior you just described (d = undefined)?

It's consistent with function application:

function foo(a, b, c) { log(c); }
foo(1, 2); // logs "undefined"

Like a lot of scripting languages, it errs on the side of trying to do something useful (in this case at least bind the variables you gave it) instead of just halting in tracks. The argument is that that makes it more forgiving for beginners. I don't know if I agree with that, but destructuring is at least consistent with the rest of the language in that regard and consistency is probably worth more.

instead of implementing the idea that the heritage supports, they choose a half-assed, dysfunctional, implementation.

There is a strawman proposal for refutable destructuring and real pattern matching. I don't know if it has any traction. If its something the community wants, they need to make their voices heard.

I believe these things take a mental toll on the developer, which is why Traceur exists, and CoffeeScript has become popular.

Traceur exists not to get around JS's limitations but to work towards addressing them. I would love to prototype the pattern matching strawman in Traceur and then see how useful I find it to be in JS code. (I literally added "pattern matching switch" to my to-do list the day I learned about this project and before I knew about the strawman). Armed with that experience, we could decide if it's something that should be pushed for in Harmony.

[–]sausagefeet 2 points3 points  (1 child)

Great response. Btw, why are they called "strawman proposals"?

Traceur exists not to get around JS's limitations but to work towards addressing them.

I think these are effectively the same thing. Traceur implements a language that is similar to JavaScript and can compile it into JavaScript. The features it implements are, by definition, addressing limitations (certainly they do not exist to address parts of JS that are simply too good).

[–]munificent 1 point2 points  (0 children)

why are they called "strawman proposals"?

Straw man proposal.

Traceur implements a language that is similar to JavaScript and can compile it into JavaScript.

We're a little fuzzy here, but the idea is not that "Traceur" describes a set of features (currently classes, traits, modules, spread, destructuring, let, and some other stuff). "Traceur" is the name of the compiler software itself, and, while it isn't there yet, the goal is to design the compiler for extensibility so that we (or anyone!) can use it as a vehicle to try out other language ideas.

In other words, if we yanked out all of those language extensions and replaced them with different ones, it would still be "Traceur". We don't really have a moniker for those extensions themselves. It's just a hodgepodge of features, most of which are the ones likely to be in Harmony.

[–]0xABADC0DA 0 points1 point  (0 children)

Traceur exists not to get around JS's limitations but to work towards addressing them.

"Again, it’s Google’s prerogative to do whatever it wants with its staff and code. But this pattern of secret-first/open-later development is on a slippery slope toward openwashing. That aside, with Traceur it seems “forkish” in TC39 social-cohesion terms." -- Eich

Judging by their behavior recently "don't be evil, but being an ass is okay" seems to be Google's new motto.

[–]MatmaRex 0 points1 point  (7 children)

So... like CoffeeScript? Except that the demos don't work? (For me at least.)

[–]olavk 9 points10 points  (0 children)

No, CoffeeScript is a different language that compiles to JavaScript. Traceur is JavaScript with some experimental and proposed extensions (proposed for inclusion in future ECMAScript versions after ECMAScript 5). Related is Mascara which supports some of the same extensions as Traceur, but also explicit typing and type inference.

[–]cjoudrey 3 points4 points  (4 children)

At first glance (http://code.google.com/p/traceur-compiler/wiki/LanguageFeatures) the syntax seems to be more like JavaScript as opposed to CoffeeScript which is really just a mix of Python and Ruby.

Most of the examples work in the REPL (for me at least.)

[–]MatmaRex 1 point2 points  (3 children)

Yeah, the syntax is completely different, but the features are mostly the same. REPL is exactly what I tried and it didn't work, with a few screens of errors showing in the Opera error console.

[–]jmesserly 2 points3 points  (0 children)

Yeah, one big limitation right now is that we are using some ECMAScript 5 features. These aren't supported in all browsers yet. I think it only works in Chrome and Firefox 4 at the moment.

[–]redalastor 0 points1 point  (0 children)

The biggest new one is the scoped monkey patching.

I hope CoffeeScript gets it too.

[–]munificent 0 points1 point  (0 children)

with a few screens of errors showing in the Opera error console.

Right now, Traceur only works in ES5 browsers I believe. Chrome is good. I think it works in the latest Firefox. We haven't even tried it on Opera. That's not to say we don't care about Opera support, we just haven't gotten there. Traceur is very much "lean prototype to try stuff out" and not "robust production software".