News for hackers. Stuff that matters.
Re:JavaScript async/await implemented in V8 by viperscape on Monday May 16, 2016 @09:58PM (#11710906)
The try and catch inside the async function is also great. Curious though, is using const over let common? I usually use const for imports and module level globals, and let inside functions. I recently got back into javascript, and it's nice to see it flourishing.
Re:JavaScript async/await implemented in V8 by bb85 on Monday May 16, 2016 @10:02PM (#11710919)
The great thing about let and const, for me, is that it gives you crucial information about variables without having to look further down.

const should be the default, and if you're going to reassign it, then use let.

In most code, you'll use const on the vast majority of variables, and it'll make let assignments stick out, which helps a lot when you're browsing the code or refactoring.

Re:JavaScript async/await implemented in V8 by spraak on Tuesday May 17, 2016 @04:15AM (#11711996)
This right here. One of my friends (a more experienced developer) told me at coffee one day, "I use const for everything" which really stuck with me. It really helps make it clear if you need a mutation to have let stand out.
Re:JavaScript async/await implemented in V8 by rpastuszak on Tuesday May 17, 2016 @05:42AM (#11712287)
However, it's worth noting that using const doesn't make variables immutable. It only protects them of being reassigned:

const val = 'a'; val = 'b'; // TypeError

const obj = { val: 'a' }; obj.val = 'b'; // This line will still work.

obj = { val: 'b' }; // TypeError

Re:JavaScript async/await implemented in V8 by dcherman on Tuesday May 17, 2016 @10:41AM (#11714027)
Yep. In those cases, I still prefer let personally even though I know the variable itself will not be re-assigned, kind of as an indicator that I expect the referenced object to be mutated.
Re:JavaScript async/await implemented in V8 by candu on Tuesday May 17, 2016 @11:18AM (#11714353)
Coming from a background that includes some experience with C / C++, `const` here works as I expect it to. I'd prefer `const` even for the object reference case: I get errors on reassignment this way, and presumably it makes additional optimizations possible. To each their own, I suppose :)

There's also `Object.defineProperty()`, `Object.freeze()` for more control over mutability.

Re:JavaScript async/await implemented in V8 by WorldMaker on Tuesday May 17, 2016 @11:55AM (#11714657)
I just wish let was in fact const (and something like "local" could be let), simply because the keyword let is nicer to type, easier to read, and more importantly better in line with the meaning of let in Lisp/Scheme/ML/OCaml/et al.
Re:JavaScript async/await implemented in V8 by spraak on Tuesday May 17, 2016 @02:07PM (#11715871)
Yeah, I was thinking the same! I was even considering writing a custom babel transform to do this for me :P
Re:JavaScript async/await implemented in V8 by bubersson on Monday May 16, 2016 @11:10PM (#11711155)
We also favor using const as a default for everything in our team's code. When someone uses let, it's right away obvious that the reference will change.

One case that surprised me a bit is that it's correct to use const in for-of loop, e.g.

for (const a of arr) {}

Re:JavaScript async/await implemented in V8 by spraak on Tuesday May 17, 2016 @04:18AM (#11712008)
I've been using a lot of const function declarations

`const fn = (i) => ...`

Re:JavaScript async/await implemented in V8 by tlrobinson on Tuesday May 17, 2016 @12:59AM (#11711435)
Yes, http://eslint.org/docs/rules/prefer-const is a fairly common [1] ESLint rule.

1. Admittedly my only data point is AirBnB's style guide / ESLint config: https://github.com/airbnb/javascript#references--prefer-cons...

Re:JavaScript async/await implemented in V8 by g_delgado14 on Monday May 16, 2016 @10:03PM (#11710926)
const is more declarative as you can immediately tell that the data isn't going to change throughout the duration of the program (although technically you can change the data, just not the reference).
Re:JavaScript async/await implemented in V8 by lewisl9029 on Monday May 16, 2016 @11:10PM (#11711154)
> although technically you can change the data, just not the reference

This is why I'm hoping to see native JS immutable data structures eventually (maybe it's already in a proposal somewhere?). ImmutableJS and Mori are great, but having a native solution that's available everywhere would be ideal.

Re:JavaScript async/await implemented in V8 by callahad on Tuesday May 17, 2016 @09:09AM (#11713270)
Consider looking at other languages. ClojureScript does a pretty good job at immutability, Elm is great for immutability + strong typing, and PureScript adds in Haskell's advanced type system (typeclasses, HKTs, etc.)
Re:JavaScript async/await implemented in V8 by lewisl9029 on Tuesday May 17, 2016 @03:05PM (#11716384)
Definitely. ClojureScript is what I usually choose for my own projects, but the reality of the front-end job market is that JavaScript still dominates, so improvements to JavaScript itself will still have a significant impact on the lives of developers everywhere regardless of the existence of other compile-to-JS languages.
Re:JavaScript async/await implemented in V8 by shimn on Wednesday May 18, 2016 @03:15PM (#11724884)
When I want to ensure strict immutability, I use an implementation of deepFreeze (https://github.com/jsdf/deep-freeze) that recursively calls Object.freeze() on all child properties. Obviously slower than strict browser support. Does ClojureScript rely on the Clojure compiler to ensure the properties aren't modified or is there some polyfill?
Re:JavaScript async/await implemented in V8 by WalterSear on Monday May 16, 2016 @10:10PM (#11710954)
IMHE, const is the generally the default and let is the exception.
Re:JavaScript async/await implemented in V8 by sotojuan on Monday May 16, 2016 @10:59PM (#11711128)
I'm alone in this but I prefer `let` over everything else unless it's something like Redux action strings, database connections strings, or anything of the like. I rarely use `const` for the ridiculous reason that I find it too long (5 characters!). `let` is short and reads nicely and my programming style in general never mutates stuff anyway (I use Ramda/always return new data).

That said, `const` is picking up to be the default for everything. I can definitely see good reasons to use it when declaring functions and required modules or working in a team.

Re:JavaScript async/await implemented in V8 by nemild on Monday May 16, 2016 @11:43PM (#11711234)
I'm curious why you let the amount of typing dictate what you use? If five characters is such an impediment, why not just use a snippet letting you have less error prone code than currently (e.g., 'co ' expands to const).
Re:JavaScript async/await implemented in V8 by garyclarke27 on Tuesday May 17, 2016 @02:56AM (#11711780)
As you admitted, your behaviour is rediculous, hope for your sake, your boss or customers don't read this.