8 ms·
ECMAScript 6 looks promising
- rglullis 15y agoExcept for the inclusion of "let", it is looking like Python with braces.
- karterk 15y agoYes, and David actually mentioned openly in that talk that they try to borrow good ideas from other languages if possible! There are templates from PHP too :)
- rglullis 15y agoDon't know much about PHP, but the templates also exist in Python.
- funksta 15y agoPython's string formatting is different though– it doesn't automatically have access to the variables in the current scope. You have to explicitly pass in the variables that you want to include, which seems to me like a cleaner way of doing things.
- wulczer 15y agoLet keyword: good. The function scoping of vars is gruesome. Default arguments: good. Clearly useful and already used a lot with the if (foo === undefined) foo = 'default' pattern. Non-strict destructuring: bad. It's neither destructuring-bind nor pattern matching... If I destructure a 3-list to 2 vars, I want it to fail, dammit! Multi-line strings: good, obviously. Templating: hello, PHP! I thought we already know better. List comprehension: useful. My humble opinion: it's hopeless. A mix of useful and terrible features means it'll still be made out of "the good parts" and the awful rest.
- karterk 15y agoTo me this spec itself is a step in the right direction. There has been no major work towards improving JavaScript in a long long time. I left out in my post the part about modules (which will hopefully solve all the crazy 3rd party JS issues), because I have no idea when they will actually get implemented by the browser vendors. But, I am hoping that this will continue to evolve in future, instead of getting stagnated.
- DaNmarner 15y agoI don't know much about PHP, what's wrong with it regarding templating?
- wulczer 15y agoAutomatic interpolation of variables into string literals is a bad idea IMHO. Couple that with variable hoisting (function scope) and hilarity can ensue when variables defined further down a function influence the value of another variable that looks like it just contains a string literal.
- lclarkmichalek 15y agoEvery time I try Ruby, this features seems odd, yet I never see much discussion of it. It feels unnatural to me, coming from a python background, and the only real advantage I can see is the fact that you do not have to type `.format(foo")` after the string, or some similar construct. What advantages did I miss? I doubt that the creators of ruby did not put any thought into this, and I'd be interested in their justification.
- telemachos 15y ago>> I doubt that the creators of ruby did not put any thought into this, and I'd be interested in their justification. I don't know what Matz's thinking was, but it may just be that Ruby owes a great deal to Perl. Interpolation in double-quoted strings is present in Perl (and used constantly).
- DanielRibeiro 15y agoNice to see many of CoffeeScript's constructs coming to ECMAScript.
- Cushman 15y agoTrue-- but it's frustrating that there's so much resistance to the idea of making the syntax prettier and more concise, which is one of the primary benefits of CoffeeScript. (Almost?) all of these features can be added to JavaScript with libraries-- that's exactly what CoffeeScript demonstrates. The only thing missing is a contemporary syntax.
- vidarh 15y agoThe syntax is one of the things that keeps me from using CoffeeScript.
- jamesra 15y agoBecause it is badly designed? Or because it is too different from js?
- masklinn 15y agoBecause it's kind-of a mish-mash, and syntactic elements imported from other languages (I know) tend to behave differently in subtle ways, usually making them worse or weird. Also having a single token change so much meaning (fat vs thin arrow) feels icky and hard to read/notice.
- Cushman 15y agoThat's a fair perspective, although what you call a "mish-mash" I'd call borrowing the best syntax for every feature :) The syntax came out of a community effort over the course of many months, and a lot of thought went into the decisions that were made. (And of course it's still under development!) Since you mentioned the => operator in particular, I'll defend it briefly-- it's a feature JavaScript sorely needs, and in the situations where it's useful it's a godsend, turning a pile of ugly JS into a single operator. The thing it describes is a little complex semantically, but in practice it's very straightforward, and in the cleaner environment of CoffeeScript it stands out well. It does seem like a small difference, but do you mix up == and -= much? Same deal. Visually speaking it actually makes a lot of sense: -> indicates a vanilla, unbound function, while => indicates a bound function whose context equals the one it's defined in. I know I'm a bit of a fanboy, but if you do a lot of JavaScript I'd encourage you to at least give CoffeeScript a second chance over a weekend sometime; it's the same, normal JS semantics you know and love, but you get to use all the futuristic shortcuts and clean syntax of a modern scripting language, and it outputs nice, readable, compliant JavaScript. (Say goodbye to JSLint!) That's well worth the minimal learning curve, in my opinion of course.
- boucher 15y agoI think it will be really sad if we end up with a module system that's incompatible with CommonJS, which is the only such system that has gained any real traction.
- starwed 15y agoDo you have reason to think that's likely?
- juliennakache 15y agoThe most interesting part to me is the "generator function", which basically allows for cooperative scheduling. This would put an end to spaghetti callbacks when doing blocking I/O operations. Very similar to EM-Synchrony for EventMachine/Ruby and (I guess) Inline Callbacks in Twisted/Python. This and the new module would be a blast for Node.JS !
- wladimir 15y agoand (I guess) Inline Callbacks in Twisted/Python Python has had real generators (using the yield keyword) for a long time... See http://www.python.org/dev/peps/pep-0255/ http://www.python.org/dev/peps/pep-0255/ .
- bitanarch 15y agoPython has been having coroutine based, cooperative scheduled I/O for a long time.. go read about gevent and eventlet.
- barumrho 15y agoBut, how are we going to migrate? Compile down to the current version and serve two files? I feel like this migration process will take way too long.
- lautis 15y agoEither that or wait until last version of IE which doesn't support it has died. Might happen in time for HTML5 becoming W3C recommendation in 2022.
- Bootvis 15y agoFor some web apps it will probably take long. But with all the developments in browser land there is often more then one reason to develop against the latest anyway. Hopefully this will motivate corporate IT to move faster also.
- nkassis 15y agoThat's one good thing about using a feature like WebGL :) By forcing my users to use the latest versions of Firefox and Chrome I get access to a lot of nice new functionality.
- philjackson 15y agoThat bears more than a passing resemblance to coffeescript. Great stuff.
- jemeshsu 15y agoCoffeeScript is popular and there is Dart. Instead of using another language and translate to JavaScript, what are the hindrances to improve JavaScript so that the "bad parts" are removed? Maybe a 'half-clean' break from existing javaScript? Sorry for my ignorance.
- deleted 15y ago[deleted]
- masklinn 15y agoThere's a very high interia, as there are at least 5 major implementations still being developped (MSIE's Chakra, Mozilla's SpiderMonkey, Google's V8, Apple/Webkit's JavaScriptCore and Opera's Carakan). Work has not stopped, but it's basically about cat-herding, and each player does his own additions. As an example, Mozilla has kept working on core Javascript with "internal" versions: 1.6 added Array Extras and String and Array generics (array extras have since then been adopted by everybody else) as well as E4X (literal XML syntax in JS) and a `for each` loop. 1.7 added generators and iterators, array comprehensions (listcomps), let definitions, statements and expressions and destructuring assignments 1.8 added a function shorthand (function (foo) { return bar; } => function (foo) bar), generator comprehensions (lazy listcomps) and two missing array extras (left and right folds) 1.8.1 and 1.8.5 mostly added ES5 and draft APIs (e.g. the Object.* stuff and the Proxy type)
- tikhonj 15y agoYou can already remove a bunch of the bad parts via "use strict".
- program 15y agoUsing the ` (backquote) character for multiline strings isn't a wise choice (probably inherited from Go) cause it's difficult to reach that character on non-english keyboard layout. In the italian layout it's alt+\ or alt+9 on the Mac but you can't reach it using Windows; you need to press alt+96.
- heisenmink 15y agoI just press shift+´ to get `
- deleted 15y ago[deleted]
- benjoffe 15y agoWhat other character would you suggest? At least multi line strings arent super common (nor essential) so extra difficulty isn't a major problem.
- masklinn 15y ago> What other character would you suggest? Fixing the language so newlines in strings are legal, Python-style triple quoting or some sort of string modifier prefix (similar to Python's rawstring modifier)
- program 15y agoI don't think that there is the need for a new character. The problem here is that JS has automatic semicolon insertion. This: var a = "abc def"; generate a "unterminated string literal" syntax error cause a semicolon is inserted after abc. Why not using C/C++/ObjC syntax? var a = "a very " "very long string";
- dbattaglia 15y agoThe only thing about the C syntax version is you still end up with a bunch of double quotes all over the place. The #1 reason I have for using multi-line strings currently is when writing full-out SQL or Javascript code inside C#; using C#'s @-prefixed strings make the whole thing a lot prettier to look at IMO. For me personally I'll probably never have to write multi-line JS strings more than once a year so I don't really care about the feature, but I do agree with their way of implementing them.
- smosher 15y ago`let` is good but please, give me `let ... in` too: let callback = function(a, b) { // ... } in object.registerCallback(callback);
- masklinn 15y agoI don't know what they've selected for ECMAScript 6, but the `let` keyword as introduced in Firefox 2 has 3 different forms: * Let definitions are equivalent to `var` but block-scoped, so if (x > y) { let gamma = 12.7 + y; i = gamma * x; } `gamma` is local to the `if` block and will not leak out. This form can be used to create bindings in `for` as well: for ( let i=0 ; i < 10 ; i++ ) { console.log(i); } here, `i` is only visible from the condition, incrementor and body of the `for` statement but not outside * Let statement, mostly for side-effects, sufficient for what you need: let (callback = function (a, b) { // ... }) { object.registerCallback(); } * Let expressions, this works like the `let` statement but returns a value, just drop off the braces: let foo = let (i=42) doSomethingWith(i) will bind the result of `doSomethingWith(42)` to `foo`.
- smosher 15y agoLet statement, mostly for side-effects, sufficient for what you need: Sadly it's not. JS has some semantic foibles, but I find myself up against syntax more often than I'd like. Every time I write it I'm impressed at how ugly the syntax is vs for such a good language (modulo the standard library.) The very thing I'm trying to avoid is the use of blocks within parentheses. (Aside: I changed my font to Monaco for JS because of the frequent appearance of `})`, and went to the trouble of fixing it up in Fontforge so gvim et al. would be willing to use it.) I never want to see this: anything(block { // ... }) <--- this ^^____this but I still want the definition to be short-lived (more for self-documenting purposes than anything else, now that I think of it.) Your last example almost has it, but the parens are right there where I want them gone.
- masklinn 15y ago> The very thing I'm trying to avoid is the use of blocks within parentheses. That, er, makes no sense at all. Javascript's function uses braces, having an anonymous function within anything will yield either a brace-and-parens or a brace-and-comma. > Your last example almost has it, but the parens are right there where I want them gone. Then there's no point in using javascript, go do something else because trying to get rid of this will just yield to an idiosyncratic and mostly unusable coding style.
- jorangreef 15y ago64-bit integers and bitwise operations together with default arguments and destructuring would solve just about everything.
- Animus7 15y agoI cannot rightly comprehend what problems one must be having if the solution is a wider bit width and variable assignment sugar.
- Fargren 15y agoDoes anyone know if this will get implemented into ActionScript? I want let so much.