panzerdp / dmitripavlutin.com-comments

7 stars 0 forks source link

/javascript-arrow-functions-best-practices/ #55

Open panzerdp opened 3 years ago

panzerdp commented 3 years ago

Written on 01/27/2020 13:51:47

URL: https://dmitripavlutin.com/javascript-arrow-functions-best-practices/

panzerdp commented 3 years ago

Comment written by Rob on 01/29/2020 15:13:43

Great tips, Dmitri!

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 01/29/2020 15:15:30

Thanks!

panzerdp commented 3 years ago

Comment written by Karl on 01/30/2020 09:11:35

Great post! I've been having problems with excessive nesting, so #5 was really helpful!

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 01/30/2020 10:11:29

You're welcome. Agreed, excessive nesting is an usual problem. But you could solve it by using async/await syntax, or extract standalone functions from nesting as much as possible.

panzerdp commented 3 years ago

Comment written by Woo on 01/31/2020 23:38:21

So good! JavaScript is weird....

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 02/01/2020 13:32:54

You're welcome.

panzerdp commented 3 years ago

Comment written by Martijn ᗢ on 02/03/2020 15:22:38

The operators >, <, <= and >= look similar to the fat arrow =>.

This can be mitigated in the editor by using a code editing font with ligatures, like FiraCode.

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 02/03/2020 15:27:07

That's a great tip. Thanks for sharing.

panzerdp commented 3 years ago

Comment written by Samiullah Khan on 02/04/2020 05:25:50

You kept things simple by pointing all of the good things about the arrow functions. I really like them because they improve the code readability a lot and some time reduces number of lines we need to write.
Some times I am so obsessed with saving some characters that I avoid name inference (without thinking much about I would ever need to debug this arrow function) which is problematic in debug session.

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 02/04/2020 15:29:14

A good approach is to keep the things as simple as possible, but without compromising clarity.

In case of an inline arrow function, you could skip the name inference because the function is too simple. In other cases, if the function does many things, a good practice is to apply the name inference to say in a few words what the function does.

panzerdp commented 3 years ago

Comment written by Михаил Александрович on 02/05/2020 06:55:17

JetBrains Mono not bad.

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 02/07/2020 10:46:17

Took a try with JetBrains Mono, and indeed it's easier to distinguish the fat arrow =>:

https://uploads.disquscdn.c...

panzerdp commented 3 years ago

Comment written by EV Lover on 09/02/2020 07:55:15

Thanks a ton for this amazing write up

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 09/02/2020 07:57:15

You're welcome!