News for hackers. Stuff that matters.
Re:Modern Javascript: Everything you missed over the last 10... by halfmatthalfcat on Saturday May 15, 2021 @12:40PM (#27166720)
Newbies aren't the only ones stringing them together and nesting them, even seniors like me are...to great effect, increased readability and are safer than potentially dangerous mutations.

I teach all my reports to lean heavily into the new array functions because, if wielded correctly, are much more powerful than using for loops while using less code.

Re:Modern Javascript: Everything you missed over the last 10... by hajile on Saturday May 15, 2021 @11:59PM (#27171098)
The big problem with them is that they are naive. If you string 10 of them together, you will iterate the array 10 times and generate 10 garbage arrays.

Lodash and similar libraries are much better in this regard as they tend to use iterators internally which don't generate all the extra garbage and don't iterate multiple times. Because they don't have to handle all the weird edge cases, they tend to also execute faster too.

Re:Modern Javascript: Everything you missed over the last 10... by grandpoobah on Sunday May 16, 2021 @07:45AM (#27172999)
It's pretty rare for me to string more than two or three together. If you're chaining 10 together, maybe it is time for a loop.

Computers are fast, and all browsers are really good at this stuff, so I don't tend to worry about creating a bunch of extra work for the GC.

Something something.. premature optimisation?

Re:Modern Javascript: Everything you missed over the last 10... by tomxor on Sunday May 16, 2021 @12:39PM (#27174859)
> premature optimisation

This is the most missused phrase of all. We are not talking about optimisation here, we are talking about _not_ writing slow code, there is a huge difference. Optimisation tends to add complexity with a trade off.

Re:Modern Javascript: Everything you missed over the last 10... by hajile on Sunday May 16, 2021 @09:18AM (#27173518)
I’ve always heard premature optimization used to refer to convoluted, harder to use and understand techniques that trade lots of developer time for extra performance.

In this case, we’re talking about a single import and almost identical API while also gaining access to tons of additional and more advanced functions that save time too. It hardly seems comparable.