Live data from Hacker News

ECMAScript 6 looks promising

kishorelive.com

91–94 of 94 posts

Re: ECMAScript 6 looks promising

#91
post #84
post #44

Earlier quoted context omitted.

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

I was arguing that non-strict destructuring is bad, so this code IMHO should throw exception:

    a,b,c=[1,2,3,4]
The reason for this is - if you assume array has 3 elements, but it has more, your code will silently ignore the rest. You'll have to write your assertion every time you destructure, to be sure that destructuring don't ignore data. The exceptional case IMHO is when you need to ignore data, and so code for this case should be uglier, not the other way around. You are right that catching exception for regular code path isn't the best way, but at least programmer intention is clear then.

You could also do

     a,b,c = list.slice(0,3);
which copies the array, but at least it's clear what it assumes about the array. And it can be easily modified to get last 3 values, or 3 values from the middle of list. So no need for 2 idioms depending on which items you want to get from the array.

Re: ECMAScript 6 looks promising

#92
post #85

Earlier quoted context omitted.

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

The statement was not intended to be rude

It comes off as a euphemism for much shorter phrase. Perhaps you didn't intend to be rude, but you failed to be polite.

Ignorant of what

(Exactly.) You've made assumptions and pinned them to me. I'd set you straight but I don't actually want to continue this conversation. Sorry it didn't work out.

Re: ECMAScript 6 looks promising

#93
post #92

Earlier quoted context omitted.

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

The statement was not intended to be rude It comes off as a euphemism for much shorter phrase. Perhaps you didn't intend to be rude, but you failed to be polite. Ignorant of what (Exactly.) You've made assumptions and pinned them to me. I'd set you straight but I don't actually want to continue this conversation. Sorry it didn't work out.

> Perhaps you didn't intend to be rude, but you failed to be polite.

Considering your messages seem to be about misleading and avoiding spelling out your issues more than conversing, I had (and have) no reason to go out of my way to be polite.

> I'd set you straight but I don't actually want to continue this conversation.

And now you're plain and simply lying. You never intended to set anything straight (or you'd have done this in your previous comment instead of going for the pithy implication) and never intended this to be a discussion.

> Sorry it didn't work out.

It's not a relation, there's no "working out" to do.

Re: ECMAScript 6 looks promising

#94
post #75

Earlier quoted context omitted.

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

I 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";

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

Post reply on HN