Live data from Hacker News

ECMAScript 6 looks promising

kishorelive.com

41–50 of 94 posts

Re: ECMAScript 6 looks promising

#41
post #3

Let 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…

>If I destructure a 3-list to 2 vars, I want it to fail, dammit! Why should that fail any more than: var a = foo[0]; var b = foo[1]; // rest of foo unused Destructing is just another way to access into a list. There's no notion of completeness here, and there's nothing necessarily erroneous with not referring to all the elements. What would you do if you need just the first 5 elements of a 100-element long list? That…

They are:

    var [ a, b, ...rest ] = foo

Re: ECMAScript 6 looks promising

#42

CoffeeScript 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]

Re: ECMAScript 6 looks promising

#43
post #32

Earlier quoted context omitted.

I doubt. /* */ is already used for commenting.

That's the idea. Python uses the same syntax for multi-line strings as for comments.

This is completely wrong. Triple quotes in Python indicate a string. It happens to be able to be used for a multi-line comment because it officially leaves no artifact in the AST if it's not assigned to anything (can't find the documentation for this atm).

/ * ... * / is a comment in Javascript. Changing it to mean multi-line string is a terrible idea.

This list of changes to Javascript borrows so much from Python I'm surprised they didn't also borrow Python's multi-line string syntax.

Re: ECMAScript 6 looks promising

#44
post #3

Let 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…

>If I destructure a 3-list to 2 vars, I want it to fail, dammit! Why should that fail any more than: var a = foo[0]; var b = foo[1]; // rest of foo unused Destructing is just another way to access into a list. There's no notion of completeness here, and there's nothing necessarily erroneous with not referring to all the elements. What would you do if you need just the first 5 elements of a 100-element long list? That…

> What would you do if you need just the first 5 elements of a 100-element long list?

I like Python solution there:

    list = [1,2,3,4,5,6,7,8,9,10]
    a,b,c = list[0:3]
Also when I do

    a,b,c = list[0:4]
I get "ValueError: too many values to unpack" as it should be - you can always catch the exception and ignore it, if your code really don't care.

Re: ECMAScript 6 looks promising

#45
post #3

Let 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…

I guess that's what happens when a language becomes this popular. All the immigrants from other languages start sticking their fingers in and trying to make JS the way they think it should be. The main issue is that half of these features don't solve any real problem. They should look to libraries like underscore that add features and solve problems that JS currently doesn't. It's almost like they just want to elimin…

Eliminating libraries has adventages - it eliminates dependency. When you have to integrate 2 projects using different basic libraries, it's painful.

In one of C++ programs I've worked on, we've had 4 different classes for string used (along with char* of course).

Re: ECMAScript 6 looks promising

#46
Using 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.

Re: ECMAScript 6 looks promising

#47

Earlier quoted context omitted.

Every 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 justif…

>> 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).

I think the bad part of string interpolation is that it encourages to use it constantly, in place, instead of extracting it to method.

Gluing strings together is the weak point of application, and should be hard to do, to encourage people to wrap it in functions, that can also validate input, escape what needs to be escaped, etc.

Maybe that's my "discipline and bodage" part talking :)

Re: ECMAScript 6 looks promising

#48
post #25

Earlier quoted context omitted.

Because it is badly designed? Or because it is too different from js?

Because 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.

That'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.

Re: ECMAScript 6 looks promising

#49

But, 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.

For 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.

Re: ECMAScript 6 looks promising

#50
post #46

Using 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.

I just press shift+´ to get `
Post reply on HN