Live data from Hacker News

ECMAScript 6 looks promising

kishorelive.com

81–90 of 94 posts

Re: ECMAScript 6 looks promising

#81
post #79

Earlier quoted context omitted.

I 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 * Let statement, mostly for side-effects, suf…

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

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

Re: ECMAScript 6 looks promising

#82
post #77
post #9

Earlier quoted context omitted.

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

Strings with interpolation look different in ES6. They don't just look like string literals. You can easily see where the variable substitutions happen. Also, I don't know what your argument about PHP is all about. I don't agree with the idea that string interpolation is going to lead to people writing code vulnerable to SQL injection, for example. You can just as easily write "select * from foo where name=\"" + name…

> You can just as easily write

No you can't. You've got 8% more character and 2 switches between string context and expression context. It does not "flow" it's something which is forced on the user by limitations of the language.

Re: ECMAScript 6 looks promising

#83
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.

What other character would you suggest? At least multi line strings arent super common (nor essential) so extra difficulty isn't a major problem.

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

Re: ECMAScript 6 looks promising

#84
post #44

Earlier quoted context omitted.

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

Catch an exception of something that isn't exceptional? isn't that the anti-case for exception handling?

I don't get why strict restructuring is a bad thing... as long as it's consistant, it's just a nuance of the language.

Am I missing side effect of this? What are potential pit-falls of this pattern?

Re: ECMAScript 6 looks promising

#85
post #79

Earlier quoted context omitted.

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

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

Then there's no point in using javascript, go do something else

No need to be rude. Look, I know JS likes to do things in ugly ways. It has great strength in the consistency of its syntax. That's cool. But by the time you say the word "just" you're being ignorant.

Re: ECMAScript 6 looks promising

#86
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.

Friends don't let friends use layouts other than QWERTY (glares at the AZERTY keyboard her employer gave her that was rapidly replaced with a QWERTY from home).

Re: ECMAScript 6 looks promising

#87

The 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 !

Python has been having coroutine based, cooperative scheduled I/O for a long time.. go read about gevent and eventlet.

Re: ECMAScript 6 looks promising

#88
post #69
post #25

Earlier quoted context omitted.

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

Because it looks like the type of syntax a Haskell developer might create...

Downvoted for giving an honest answer to the question I was asked. Classy. This place is becoming more and more like Reddit.

Re: ECMAScript 6 looks promising

#89
post #85

Earlier quoted context omitted.

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

Then there's no point in using javascript, go do something else No need to be rude. Look, I know JS likes to do things in ugly ways. It has great strength in the consistency of its syntax. That's cool. But by the time you say the word "just" you're being ignorant.

> No need to be rude.

The statement was not intended to be rude and I'm sorry you took it this way, it was merely intended to be factual: you seem unhappy with javascript's core syntactic elements, you should use something else because they're not going to be changed.

> Look, I know JS likes to do things in ugly ways.

Uh... ok, whatever.

> But by the time you say the word "just" you're being ignorant.

Ignorant of what, of you trying to work around javascript's syntax in javascript for debatable reasons of personal aesthetics? No, I think I got that now, I was originally mistaken indeed in that I thought you were looking for an improvement to the language, not "fixing" an irrelevant syntactic pet peeve.

Re: ECMAScript 6 looks promising

#90
post #26
post #9

Earlier quoted context omitted.

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

It's not really automatic interpolation. You have to very explicitly place the variable name inside ${var}. I'm puzzled in how you would think this will happen accidentally, or more accidentally than writing "+var+". I've used Ruby quite a while and never experienced any problems with the very same construct in there.

You can also get away with doing just "$var", though, which is the problem. We encountered a strange bug the other day where having a string containing "$3" meant it never appeared on the page after (with it being converted to null).
Post reply on HN