I don't understand why so many devs use the Lodash versions of native functions instead of adding a shim. You can't both complain about a lack of native tools and not use the ones we have, folks.
To be clear, I have absolutely no issue with Lodash in itself - I use it a lot for the new tools it brings to the language. My remark only applies on those who are natively available.
If you're using lots of lodash functions in addition to the native ones, it's cleaner to read and write code running everything through there, rather than special-casing the ones that are worth shimming.
Internally lodash is pretty good at falling back to native functions where available if it's sensible, remaining extremely compatible with them (so you could migrate very easily if you wanted), and ensuring great performance.
Personally I use lots and lots of lodash functions, and while the ones listed here are useful to have natively, they're not the majority of the methods I use. Lodash is really good, native has a long way to include everything Lodash has (and I'm not sure it would be sensible to do so), and if you're going to include Lodash anyway you might as well use it for everything.
See, I don't really see performances as a valid reason to use these functions. I have yet to see an application where Array#forEach was the real bottleneck, and if you're writing a library, I'd very much prefer the library author to avoid dependencies, even if it means they have to implement a basic forEach that solves their particular use case, than requiring me to use Underscore or Lodash or whatever. I love taking libraries for a date, but I hate it when they require me to bring their friends along.
As for the consistency, it might make sense when making use of the functional style (since Lodash brings new features in this regard), but not quite as much when writing imperative code - one might argue that using the standard library is the actual best way to achieve consistency.
As I said, the primary reason isn't really about performance.
Getting more consistency from using the standard library is arguable. Consistency comes down to programming style and the overall composition of your program. It's not consistent if in your code you are using some of the native array methods but then have to constantly break out to write some for loop to do something those methods won't do. Or if you have to operate on objects similarly.
As has been said numerous times, Lodash provides more consistency (between methods and across browsers) and improves support for objects and convenience calls when dealing with collections (arrays of objects).
Why use a shim when you can use a fairly lightweight library that does the same thing better?
5
u/arcanin 🧶 Yarn maintainer Jan 26 '16
I don't understand why so many devs use the Lodash versions of native functions instead of adding a shim. You can't both complain about a lack of native tools and not use the ones we have, folks.
To be clear, I have absolutely no issue with Lodash in itself - I use it a lot for the new tools it brings to the language. My remark only applies on those who are natively available.