1. Introduction to Writing Node in 2022
Let's write Node like it's 2022. My name is Pedro, a software engineer at blockchain.com. I've been evolving with Node and I'm proud of it.
Hi. Let's write Node like it's 2022. Well, first of all, who am I? My name is Pedro, and I'm a software engineer at blockchain.com. And, well, I was looking at the code I wrote a few years ago, like 10 years ago, and I saw that my life was very, very challenging and fun. But nowadays, it's just fun. I wrote a bunch of this equals that, and I used a lot of low dash underscores, and everything else that you can think of. Just make some stuff that work as expected today. Node evolved, and I've been evolving with it, and I'm very proud of it.
2. Writing Node in 2022
So, let me tell you how to write code node like it's 2022. Look at this example, for example. So, we had to use multiple methods to iterate over an object. So, in this get total score, we had to use object keys and a for each to access the property inside of the object, and then assign the value to the totals. But now, we can do a for in, and we can access the key of the object And we can do it very easily, and with only one method. So, it's way easier to read, it's easy to return about. I know what I'm reading as soon as I put my eyes on it, way better.
Well, we had to concat strings to get phrases with variables, and LongAVI started with multi lines. These were very, very hard to create. In this example, I just created one that puts together three strings in this case. I had to use strings to spaces because I hated to add space in the end of this one, and here, I really need it because I can't add anything to this string directly. But now, I can use template literals and I can just make it work. I can do multi lines easily and everything I see is exactly what appears in a screen. So, much easier.
3. Writing Code Like It's 2022
A equals A or 1. You can pass default parameters right in the function. Async await eliminates the need for callbacks. Arrow functions inherit the scope, eliminating the need for 'this equals that'. Const prevents variable reassignment. Let helps catch errors earlier. Write code like it's 2022!
A equals A or 1. And in some cases, in cases of objects, you would have a bunch of them listed at the top of the function, making it very hard to read. But today is not the case. Because today, you can do it like A equals 1 and B equals 2 in the top.
So on the function, you can literally pass the default parameters right there without any other fuss. And Nogami started with async await. Now you don't need callbacks to handle HTTP requests. You can use async await. I'm an async await person but you can use like then that is very helpful to write like async code. You have arrow functions that don't have this scope and they inherit the scope. So you don't have to write this equals that in a bunch of cases. You have const that doesn't let you reassign the variable. You have let that makes it easier to see the errors before you see them because with the var it would hoist to the top and you would get a bunch of cannot read a often defined for example. And there are other things that I don't remember right now but are very very important.
So well do a favor to everyone and write like a 2022. It's not that hard. Well that's my GitHub and my Twitter. And that's all folks. Let me know if you have any questions.