DEV Community

Discussion on: πŸ‘‹ Say Goodbye to Spread Operator: Use Default Composer

Collapse
 
spock123 profile image
Lars Rye Jeppesen

No dev should be using lodash

Collapse
 
insidewhy profile image
insidewhy

What's the reason? With lodash-es and a tree-shaking bundler I only pay for what I'm using, so I don't see the harm in importing a few functions from lodash if I need them.

Thread Thread
 
rokuem profile image
Mateus Amorim • Edited

lodash has bad types in general, destroying typesafety and can be easily overused, creating very ugly code that is hard to understand unless you are really familiar with it. Many of the things it does can easily be done with native javascript too.

ofc, you can still use it for some things, and you can wrap it with functions with better typings, but in general it is good to avoid using it at all when working on teams since others might overuse it or use it in an unsafe manner.

something that is commonly oversued is the lodash "get" method, ex:

_.get(a, "b.c", [])
Enter fullscreen mode Exit fullscreen mode

this has many issues:
1 - the second parameter is not typed, so we don't know what we can access or if it exists or not
2 - the third parameter is not restricted to the type of a.b.c
3 - the resulting type is "any", making it easy to do typeErrors.

Nowdays we have better alternatives in general, for example:

a?.b?.c ?? []
Enter fullscreen mode Exit fullscreen mode

this will solve all of the issues mentioned before and doesn't rely on a library for it :D

Thread Thread
 
grsmto profile image
Adrien Denat

And there is Remeda!

Thread Thread
 
insidewhy profile image
insidewhy • Edited

I agree with that, there's bad stuff in lodash for sure (I never use get so it's good you point out the problems with it), but there's okay stuff too.

Collapse
 
renekaesler profile image
RenΓ© Kaesler • Edited

Hehe, okay okay!

I had not planned to trigger a framework debate. I'm sure your preferred FP-utility framework is capable of the merging concept, too. No matter if it's ramda, underscore or whatever else exists.

Collapse
 
mikethai profile image
Mike Thai

Why not? I think lodash is totally fine if you use it efficiently and understand what it does.

But if you're one of those devs who imports the entire library into every project to only use like 2% of it and don't know how any of it works/are completely helpless at your job without it, then yeah I agree - you're just shooting yourself in the foot.

Thread Thread
 
spock123 profile image
Lars Rye Jeppesen

Because lodash is not maintained as a project any longer afaik

Thread Thread
 
twiddler profile image
twiddler
Thread Thread
 
aneesshameed profile image
aneesshameed

Lodash is a matured library. Because its not updated, that doesn't means that it cannot be used on projects. Lodash works and it helps to write clean code.

Thread Thread
 
aplombomb profile image
Christian Baldwin

Our definitions of clean code are obviously different.

My definition of clean code is thoughtful composition of logic and data in order to avoid needing to depend on 3rd party libraries to help you maintain it.

Collapse
 
dchowitz profile image
Denny Christochowitz

🀣