ES6 is beautiful
ewanvalentine.io
ewanvalentine.io
Why can't we just be honest about it? "Welp, this is what we've got. We shouldn't be surprised, since this is what happens when we design by committee. Now let's make the best of it."
Who cares though, Hacker News embraces trolls who engage in syntax wars.
The future of Javascript is bright, and the new features added are vast improvements onto a language that stagnated far too long. Many of the criticisms towards the new features are not well thought out. Luckily the TC39 committee is full of extremely intelligent developers who have a good understanding of the nuances in adding new features.
On the other hand, I also work on Gosu (http://gosu-lang.github.io/) which is has its own kitchen sink issues, so I believe I'm not being a troll, or at least not simply being a troll, when talking about language design.
I think the lambda syntax is nice and concise, although the disconnect between an implicit return with a bare statement versus required explicit return with braces is kind of silly. They should have made it just implicitly return the evaluated value of the last statement in the lambda all the time.
The de-structuring syntax is less clear and consistent than, for example, Python's. The fact that both array-like things and object-like things are de-structured using '...' means that you have to consider the context when you see it, and you could probably construct cases where it isn't clear exactly what is going on.
Template literals are obnoxious because they bind when declared. This means you can't pass a template literal around to be evaluated later. You could wrap it in quotes and use eval, but then you lose multi-line support. Pretty fail.
The fact that module support is finally part of the language is a good thing. Not having a built-in module system is probably the biggest embarrassment in the language. Now we just need a dependency manager built into the browser so people can require jQuery >= 2.0 for instance, and we won't have to worry about CDNs and what not.
Other, one thing I often observe in ES6 examples is replacing quite complex constructs that could have been expressed much simpler using older JS standards. E.g., "Array.prototype.push.apply(arr1, arr2)", where "arr1.concat(arr2)" would have done fine. Not too sure, what this means for real-life applications, but there's definitely a trend in expressing things in artfully complex ways.
import Foo from 'bar';
or import { Foo } from 'bar';Given an extra few days to learn the semantics of import vs. losing access to the millions of npm packages out there, I'd rather spend the extra few days.
i think syntactically the destructuring syntax for imports is cool and clever, but in practice i find it annoying to use
In the case that they don't, I generally just try "import * as Foo" to find out exactly what the library exports. Not saying this is ideal, but it really isn't too bad either, in my opinion, considering the flexibility and conciseness this approach offers for the general case.
English.
We're talking about languages here. The most popular languages tend to be the ones that are the most adaptable. Successful languages aren't afraid to borrow and tend to have multiple overlapping grammars. They are not designed. They evolve over time. They are far from perfect.
The things you hate about these languages are exactly why they are so successful. Instead of being endlessly upset at the dominant programming language for not being 100% perfect, just embrace and celebrate its haphazard nature.
`({ id, option = true, name = 'unnamed' }) => // ...`
replaces
``` function(userObject) {
const id = userObject.id;
const option = userObject.option || true;
const name = userObject.name || 'unnamed';
// ...
}
```I think this comparison speaks for itself. In pre-es6 code bases you TONS of code that looks like the second.
It could be an argument to criticize changes proposed for a nimble performance-oriented language like Lua where "parseability" means hackability as a feature for developers working on the language & core tooling itself. But it seems to me that the bulk of the users of a popular / high-level language like JS is people trying to get things done, not tools developers hacking on JS itself.
"Difficult to parse" semantic constructs may be a hurdle for the 1% doing the parsing, but they mean more syntax goodness to help the the other 99% programmers do things pleasantly and succinctly.
I've heard Python is difficult to parse, too, but behind this difficulty there's syntax sugar helping your average developer. Much like Python list comprehensions, context managers and decorators, these ES6 features make the task harder for tool builders, but they help me as a developer.
You probably got it wrong. When he says "difficult to parse", he means for the programmers using JS -- not for people working on JS parsers.
Besides compiler construction, "parse" is also commonly used to mean "read/understand" some new code.
In this case, I'd still contradict OP, arguing the same as stevebmark did in a sibling comment: "[...] these syntax details are well thought out, practical, and improve the readability and writability of the language [...]. None of them seen "unnecessary" and teams I've worked on echo this experience."
Lots of people are being honest, this article included. Don't disguise your different opinion as "the truth". Not everything can or should have a consensus.
https://reagent-project.github.io/
Back when investigating React for a personal project, I fiddled around with Reagent as a short introduction to Clojurescript, I was not familiar with the language at all, and yet Reagent was immediately more understandable to me than React.
When an alien framework in an alien language are easier to grok than one in a familiar language, one can't call that language "beautiful" with a straight face.
ES6 is "less shitty", (maybe,) but the language itself is still a garbled mess. I can't wait for the day it goes the way of the dinosaur (or survives merely as a transpiler target).
I'm not usually one for bikeshedding. But in the case of JS, where the syntax actively hurts one's ability to understand and organize code, maybe it's warranted. Ever inherit a JS project of even moderate size? More often than not, it's a nightmare moreso than most other languages.
(Also please don't tell me I don't understand the lisp-syntax due to 'familiarity', I've heard that a thousand times and it's not the case, I just don't agree with the syntax trade-off).
A fairer comparison to Reagent would be something like Redux, which is far more elegant and understandable than low-level React code. I personally still prefer working with ClojureScript frameworks like Om/Reagent when given the choice since they have a much more robust solution for handling async tasks, but Redux doesn't fall very far behind in most other aspects.
`(text) => ({ label: text })`
In my opinion the arrow function has great syntax. Rest assured, no matter what the syntax was chosen to be, there would be an extremely vocal group of people who hate it (such as yourself).
[1, 2, 3, 4].map(x => x + 1)
You should probably avoid using them for other applications, particularly if you're using a library that uses prototypes because it won't work.
[1, 2, 3, 4].map(function (x) { return x + 1; })When it came to writing more complex stuff, I gravitated towards IE, ActiveX, and VBScript. I hated JavaScript. I was also 10 years old, so my criteria for picking a language was a bit less nuanced.
Obviously, JavaScript became the programming language of the web, and I had to learn it. I hated the inane syntax, and the fact that I was always forced to use jQuery for dealing with browser differences. I tolerated JavaScript, but still hated it.
With React, Babel, and ES6, that's all changed. I've been writing a lot of ES6 code over the last year, and it's been an absolute joy to use. Everything the author writes about is what I've learned to love.
Perhaps I've become more mature. But I'd like to think JavaScript has too.
I'd rather have a team that can handle multiple languages and shift between them, understanding that a language is simply a syntax for expressing your ideas, not something to be limited by.
Some poetry is written best in French, Arabic, or English. Some technical manuals are best written in German or Japanese.
You should choose the best language that fits your needs that lets your express yourself fully.
Really?
OTOH We've been using some ES6/Babel at work, and I'm really digging the Promise/resolve/reject paradigm.
x => this.y + x
Is almost pure signal, compared with the noise of: (function(x) {
return this.y + x;
}).bind(this)
I know which piece of code I'd rather maintain.ES6 was a long time coming, and has made Javascript much more legible to read as well as making it easier to write.
https://kangax.github.io/compat-table/es6/
That said, it will be a long time before you can write vanilla ES6 without transpilation and publish it, for the same reason that many sites still sadly support IE<=8.
Apple recognizes that the Web poses a threat to their business model (although I think it's not as big as they fear, after all, how much of their profits come from the app store). This is why I am skeptical they will support WebAssembly in the end. After all, it will be possible to compile ES6 to WebAssembly just as much as any other language.
I'm open to other suggestions for why Safari has become essentially the IE6 of our time, but pure business strategy is the only one I can come up with (which is fair, since Apple is a business after all).
Supposedly the STP version is getting updated every 2 weeks, so lets hope that that also transitions to the non-developer version of Safari.
WebAssembly is listed as in development.
Actually Safari (well, Webkit), in beta, is the closest to full ES6 support of all current browsers -- down to 98% or so.
It's just that Safari has a release only once or twice a year. But when it has, suddenly everybody on OS X/iOS using Safari would get all that stuff at once.
(And recently they started a public beta builds program that might see them releasing new versions much sooner).
>Apple recognizes that the Web poses a threat to their business model
And with that information above, can we put this age old conspiracy theory to rest?
Apple had long had the best mobile browser when Android still had the horrible "Android Browser". They regularly added all kinds of features that benefit apps (e.g. the canvas, css animations, several API to access native mobile features, etc.), and they continuously improve it (see this 98% ES6 support).
For a company that "fears web apps" Apple not only promoted them to developers (before and after they created their native app frameworks and app store), not only has extensive documentation and how to's for best mobile experiences on their dev pages, but also has seen that Safari webkit based apps have traditionally been a better experience than Chrome based web apps on Android.
Even today, it's faster, and more memory/cpu/battery efficient on mobile than Chrome is on Android.
https://blog.runspired.com/2016/03/25/the-chrome-distortion-...
Safari was only held back because it's not a huge priority for Apple -- not because of some fear that web apps will eat their app store lunch.
After all, web apps are difficult to monetize (no credit cards at hand), people expect most of them to be free, have a subpar experience for anything more demanding compared to bare metal languages, and don't integrate that well with native APIs anywhere (iOS, Android, Desktop, etc), as they have to run in a more restricted sandbox than native apps do (and of course somebody has to continuously porting all the native APIs, and at a great common denominator at that, since they also need to be portable).
And hey, for whatever reason, Apple has earned my eternal gratitude (and my consumer dollar) over the past few months by being one of the only entities in this country capable and willing to stand up to government bullying and surveillance. Web standard are great for me in my job, and I believe they're important for the future of online communication. But standing up to government overreach is of critical importance to all of us. I'm an Android user myself, but wife uses iPhone so I'm already getting ready to buy her a new iPhone 7 when they come out.
I'm curious: how much have "evergreen" browsers changed this? Do developers typically target Chrome from a few months ago? Two years ago? Just "today"?
Maybe a better way to put it: if you only cared about Chrome, how long would you wait after a new feature was introduced to start using it?
Few devs care for older support unless they're working on enterprise, are masochists, or really really really care about supporting 0.00000001% [0] of their users because they care that much (and more power to them!!)
Most devs can point to Microsoft and say "Look, even the guys who created it are no longer supporting it." as an excuse to not support it themselves. I frequently do this when asked to support Safari 5... on Windows. Apple doesn't support it - neither do I.
If you work with say.. Healthcare clients you often need to support back to IE7 or even IE6 because that is what they use internally....
[0] I mean to say "practically zero, but not zero percent".
IE9 is the oldest browser we support, and soon we won't support it either.
It makes my code look a lot easier to follow, easier to write, and less error-prone.
Why the fuck? What? WHAAAT?
face palm
TypeScript is (or tries to be) ES6/ES2015 plus interfaces/types. If you want types use TypeScript.
Always amusing to refresh a few times after saying something that isn't Technolitically Correct.
We detached this subthread from https://news.ycombinator.com/item?id=11449599 and marked it off-topic.
Please don't be uncivil in comments here.
If I could edit it now, I would rephrase it to something more along the lines of "This blog post shows some pretty nice code you can write in ES6, but overall the new features in ES6 are deeply flawed etc. etc."
Personally I think the ability to anonymously downvote a comment is socially problematic, and it creates a climate in which long-term users (who can downvote) can appear to be more intolerant of dissenting voices than they probably are.
https://mind-exchange.com/wp-content/uploads/2015/05/thank-y...
Here's how to deal constructively with the situation you deplore: post stories about things that are better. Then you'll help others learn and improve, even if only a minority do so.