Transcript from the "New Good Parts in ES6" Lesson
[00:00:22] And the answer is yes we've got actually lot of good stuff in it. So my number one most favorite new feature of the language proper tail calls. So compiler will turn that into a jump instead of a call return, so it'll go a little faster. Take less memory in getting there, it enables continuation passing style in other modes of programming, it's great.
[00:01:05] This one's inexcusable, this one's actually pretty nice so that it's going to be a good thing. We've got modules in the language now unfortunately the module system we got is way too complex. But it works, so there's a subset of the module system which is adequate. Which if you just wanna say here's some stuff, I'm gonna export this thing.
[00:01:25] That's how you use it and that's all it needs to be, and it can do that. So that's good, that's much better than requires, or any of the other module loaders. We've got let in const, which by themselves are not that big a deal. Except they are less confusing to Java programmers.
[00:01:44] So it's good not to confuse the Java programmers, so I like that. One thing I find confusing about this is that I've seen a lot of developers who are confused about the difference between const and freezing. And so they're surprised that you can put a mutable object in a const and still mutate that object.
[00:02:04] So constants for variables, freezing is for values, just remember that, it's pretty easy. We have Destructuring, destructuring is something you can do and let and can't statements, and also in assignment statements. Where we can create new variables and initialize them from some object at the same time. So again not a big change, doesn't let us do anything we couldn't do before but it is a convenience, yeah.
>> Speaker 2: I think you said freezing is for values, did you mean freezing is for objects?
>> Speaker 1: Objects are values.
>> Speaker 2: Okay, yeah.
>> Speaker 1: In theory you could freeze numbers, except they're already frozen, and strings are already frozen. So you don't need to freeze those.
>> Speaker 2: One follow up, what apart about nested objects?
>> Speaker 1: It only freezes the outer one, there is no deep freeze in the language.
>> Speaker 2: So you have to do a recursive freeze.
>> Speaker 1: If you care about that, you have to descend into the language and freeze each level.
>> Speaker 1: Then we have WeakMap, WeakMap is a really nice thing.
[00:03:49] The biggest problem with WeakMap is it has maybe the worst name ever put on a feature of a programming language. Because who wants to use something called a WeakMap, right? But it's actually a really good thing. It's just a really bad name and we have Megastring literals. We have the back tick which we can now use to make literals that can spam many lines, so here's are an example of a regular expression.
>> Speaker 1: This particular regular expression matches all of the number literals that are an ES6. And you can see why I don't like regular expressions because you can't make any sense out of this right. Just looking at that, it's just noise it's really hard to understand what it's about.
[00:04:37] So I can make things all easier now, I've got a function here which we'll call the regular expression constructor passing it in a string but first it will remove all of the spaces from that string. And so now, I can use one of these mega literals to write it out with all the whitespace in it.
[00:05:00] And with whitespace in it, regular expressions aren't quite that bad, we get spaces between. Each of the elements and I can line them up and you can kind of see what's going on, so we now have binary literals. You can have zero B followed by zeros and ones and we've got aka literal which I'm still not sure about those.
[00:05:20] You've got an 0 for a zero and then octal digits and we've always had the hacks and the floating point. So that's pretty neat, this is a much nicer way of reading regular expressions. There are still things about the mega literals and I don't like. That back tick is the smallest operator we've got and it's used to bracket the biggest structures we've ever had.
[00:05:46] So there is potential for misreading here so we're gonna have to be cautious with this but I think this is probably a good thing. And again regulex, if you're writing regular expressions even with the whitespace you still wanna be suing regulex. So we've got fat arrow functions or fart for short.
[00:06:10] So the motivation here, there are people who are complaining that with function you have to type eight letters. You have to F you N, and I said that's too much to type and I said well there are these new things now called keyboard back rows, it's too much to read.
[00:06:30] Okay, so we added them. So it's a short form for writing a function that will return a value. So we got the parameter list, we got name and then we got the fart and then we've got the return value after it. So, you don't have to write function and you don't have to write return except this will fail.
[00:06:50] This looks like it's a little mini constructor that's gonna return a new object, right? It's gonna return a new thing where the id is whatever the name is that we passed, this is going to fail. Instead it's going to give you a function that returns undefined, which is not good.
[00:07:06] And it's because of a syntactic ambiguity in the language, the committee was aware of this when they did it, we just keep adding new bad parts we can't stop doing it. So because of that I'm not a big fan of these.
>> Speaker 3: So it will compile but it won't run.
>> Speaker 1: It will compile, it will run, it will return undefined when you call it. You will not get the new object that you're trying to construct. We keep doing this to ourselves, keep doing this to you, how that actually works.
>> Speaker 2: Because the brackets are ambiguous?
>> Speaker 1: Yeah, because the brackets are ambiguous.
[00:07:40] There are number of ways they could have disambiguated it, but they decide instead to make them.
>> Speaker 3: A couple quick [LAUGH] because that's not what you put inside the brackets isn't really the contents of a function. Typically, a function would return. I'm confused about, I'm confusing this. I just fart with what we're using in another language.
[00:08:03] In TypeScript, I think, they put var in TypeScript. I've been using it, I'm using it to call a function to do something
>> Speaker 1: So this will work for lots of other purposes, the place where it fails, as if you're trying to return a new object literal.
>> Speaker 3: You would have on the other side of this X var X equals.
>> Speaker 1: Yeah, or you pass this more likely pass this as an argument to another function That's one of the most common uses for these.
>> Speaker 1: So anyway moving on, and there are lots of other bad parts in the language too like generators with the yield operator, I think that was probably a mistake.
[00:08:47] It adds a lot of complexity and not much value and kind of locks people into patterns which I think are things that we should be evolving away from and not getting trapped in. A lot of the other new features we haven't had enough experience with them yet to know.
[00:09:39] But worse than that is it keeps you trapped in the mindset of the classical model, which means you will never learn to use the functional model. And also you don't have the strong type system that you need in order to deal with classes. And so I'm pretty confident that the people who are gonna be using classes are gonna feel vindicated.
[00:10:01] It's in the standard, I have a right to use it. It's all that good stuff. But they will never learn to use the language effectively. They will go to their graves never knowing how miserable they were.