You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sure, some of the examples given there do a very good job at showcasing how ES evolved and brought us fine replacements for what we could only do nicely with these libraries. But some native alternatives are plain outright worse. Let's what I mean.
_.chunk, _.pull: the native alternative means reinventing the wheel, and such actions in general are often sources of errors.
_.difference, _.intersection are easier to read than most implementations using reduce, which is like the lowest level of all "functional loops", thus it's great for implementation details, bad for when that's the last thing we want to see (in a higher-level code).
_.dropRight, _.takeRight, _.first are easier to read than slice. In fact slice tries to be too smart, often to the sacrifice of readability. I have been avoiding slice because it makes me think, it's like a puzzle. Sure if I use and see slice for thousands of times, my familiarity bias should be gone, especially that languages like Groovy also use negative indexes (list[-2]), but at the end of the day it's still more complicated than just using simple English words. There are popular keywords for shift/unshift/push/pop operations, some of which we have in ES already, but others just need to go there already, because slice wants to be too generic, like reduce. For that reason I'd rather take _.initial over .slice(0, -2), provided we all understand well enough what initial means, otherwise we of course need a better function name.
(I didn't check but the Array-related sections, but I think I've seen enough.)
=> So what we need is the best of both worlds:
Libraries updated to support ES6 (and later as newer standards gain more spread). E.g. we can reimplement Lodash's _.dropRight with the use of Array.slice instead of whatever else we had there before to give nice names to native things. And that's what already happened:
The good parts of Lodash/Underscore/etc. should be kept and still used. By no means we should say these libraries are completely useless now. Some parts still are.
And if you really need the new standard but you have to support older browsers: then we got shims. But this should be used for the right reasons, like not missing out on updated libraries.
The text was updated successfully, but these errors were encountered:
Sure, some of the examples given there do a very good job at showcasing how ES evolved and brought us fine replacements for what we could only do nicely with these libraries. But some native alternatives are plain outright worse. Let's what I mean.
_.chunk
,_.pull
: the native alternative means reinventing the wheel, and such actions in general are often sources of errors._.difference
,_.intersection
are easier to read than most implementations usingreduce
, which is like the lowest level of all "functional loops", thus it's great for implementation details, bad for when that's the last thing we want to see (in a higher-level code)._.dropRight
,_.takeRight
,_.first
are easier to read thanslice
. In factslice
tries to be too smart, often to the sacrifice of readability. I have been avoiding slice because it makes me think, it's like a puzzle. Sure if I use and seeslice
for thousands of times, my familiarity bias should be gone, especially that languages like Groovy also use negative indexes (list[-2]
), but at the end of the day it's still more complicated than just using simple English words. There are popular keywords for shift/unshift/push/pop operations, some of which we have in ES already, but others just need to go there already, becauseslice
wants to be too generic, likereduce
. For that reason I'd rather take_.initial
over.slice(0, -2)
, provided we all understand well enough whatinitial
means, otherwise we of course need a better function name.(I didn't check but the Array-related sections, but I think I've seen enough.)
=> So what we need is the best of both worlds:
_.dropRight
with the use ofArray.slice
instead of whatever else we had there before to give nice names to native things. And that's what already happened:https://github.com/lodash/lodash/blob/2f79053d7bc7c9c9561a30dda202b3dcd2b72b90/dropRight.js
vs.
https://github.com/lodash/lodash/blob/2900cfd288f72671c335021fa3220818445f9123/dropRight.js
The good parts of Lodash/Underscore/etc. should be kept and still used. By no means we should say these libraries are completely useless now. Some parts still are.
And if you really need the new standard but you have to support older browsers: then we got shims. But this should be used for the right reasons, like not missing out on updated libraries.
The text was updated successfully, but these errors were encountered: