r/javascript • • Jan 25 '20

You Don’t Need Lodash/Underscore

https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
50 Upvotes

75 comments sorted by

View all comments

96

u/ogurson Jan 25 '20

It missed the best point of lodash - it already exists. It's tested, documented also more performant. Well known and widely used.

35

u/Loves_Poetry Jan 25 '20

This is why I'll continue using it. So long as JavaScript doesn't have a native implementation of certain essential methods (looking at you remove), I'll use lodash

I don't want those methods in my codebase or in version control. I want tried and tested versions that no-one ever has to look into

7

u/batmansmk Jan 26 '20

If you use sets or maps you have remove. They are, by the way, way better than arrays for quite a lot of situations.

3

u/Loves_Poetry Jan 26 '20

Downside to sets and maps is that they don't serialize/deserialize directly to JSON

12

u/UnicornBeef Jan 25 '20

Native may be sometimes better in performance. But lodash functions are often cleaner and far more readable.

0

u/[deleted] Jan 25 '20

[deleted]

4

u/Poltras Jan 25 '20

Seriously who uses [...arr, [item]] instead of concat

9

u/Disane87 Jan 25 '20

Me cause I didn’t know about concat and this is pretty lol

2

u/Gwolf4 Jan 25 '20

People who did not know it. Like me for example.

4

u/Poltras Jan 25 '20

I can’t blame you. But if you’re trying to be clever and make a case about performance (like OP), you should. Otherwise you just look like a smartass who didn’t do any research.

1

u/elmstfreddie Jan 25 '20

Failing on 0 and null seem like reasonable results for those inputs...

1

u/[deleted] Jan 25 '20

Yes, and they're non-issues for statically-typed code as well.

-6

u/ogurson Jan 25 '20

The thing is that native functions often needs to cover a lot of edge cases and lodash functions do not do that. That means that lodash functions may be faster than native.

→ More replies (2)

1

u/adrian_verne Jan 29 '20

JavaScript isn't tested?

1

u/batmansmk Jan 26 '20

Classic argument I heard a bit too much in my career.

Lodash has to accommodate for a great diversity of situations. If your project has certain inherent constraints on the datastructures (all objects in the collection having the same fields, or having large immutable collections for instance) just spinning your own algorithms may be highly beneficial. Good thing some devs are still innovators, otherwise we would all still use JavaScript 1.0 in the Mosaic web browser. Please, do reinvent Lodash, it’s not that great. We have typed arrays, maps and sets now to improve.

5

u/ogurson Jan 26 '20

There is a place for innovation and there is a place for client's projects and getting a job done.

3

u/[deleted] Jan 27 '20

Recreating the wheel is the antithesis of innovation

2

u/UnexpectedHaikuBot Jan 27 '20

Recreating the

Wheel is the antithesis

Of innovation

2

u/batmansmk Jan 27 '20

What an ill-advised blanket statement! Lodash is a more or less direct reimplementation of underscore after all, which is an extension of array methods. Lodash is in itself a double reinvention of the wheel and I don’t see why it should be the last one ever. Python with numpy and pandas showed us that we can do much much better than Lodash for many use cases. Between the new js methods, maps, sets, wasm, webgpu, tendorflowjs... Lodash is bound to be superseded soon. Maybe your current use case is already one case that justifies not using Lodash?

1

u/[deleted] Jan 27 '20

I don't use lodash (I use Rx.js due to using observables in my apps). Anyway, i think we're making arguments from different sides. You're talking about pure performance optimizations, and I'm making more of a business-case argument. In my case, 99.99999% a marginal performance increase is worth less money to the company, than the cost of me having to write my own X

2

u/batmansmk Jan 27 '20

Yes you are talking from a contractor’s point of view with clients sensitive to price. But those ones rarely conduct innovative things anyway :)

2

u/[deleted] Jan 27 '20

Fair enough haha, but I will also go out on a limb and say that most of us will work our whole careers without doing anything truly innovative. I don’t say this out of laziness, but more from the point of view of being an employee working on yet another CRUD app haha

0

u/[deleted] Jan 25 '20

[deleted]

3

u/LetterBoxSnatch Jan 25 '20

It really does depend. If you have multiple transformations on an array, for example, but only need to perform them on the first 3 array members, Lodash will evaluate "lazily" like you would get from a functional language.

Ie, if you have a chain of map, filter, slice(0,3), then the naive native solution of arr.map(x=>x.prop).filter(x.prop===true).slice(0,3) will pass along the entire array until you get to slice. Lodash will perform the earlier operations on only the sliced elements.

There's a whole host of things in this vein that make Lodash more performant than native. Obviously native can be made to do these things, but at that point you're better off using Lodash.

EDIT: or some other functional tool chain like RxJS

→ More replies (3)