4 ms·
> Lodash is tree-shakeable... > Just use Lodash, it's better than having to maintain your own hodgepodge of poorly documented and tested utility functions. The
by jonahx 4y ago
> Lodash is tree-shakeable...
> Just use Lodash, it's better than having to maintain your own hodgepodge of poorly documented and tested utility functions.
There are good reasons not to:
- You don't want to add a build step to your project
- You don't want to introduce any additional knowledge burden on contributors to your code, other than knowing JS. Your "chunk" is the few lines of source code in your repo -- not an external thing with documentation you have to lookup.
- You don't want to deal with the security issues every dependency introduces
Let's specifically address this claim, which is often used in roll-your-own vs use-a-library debates:
> to maintain your own hodgepodge of poorly documented and tested utility functions
I feel, in this particular case, this argument is a straw man. The functions in question are basically 1-liners. The likelihood of bugs are low. The need for documentation is nil: the implementations self-document.
- phailhaus 4y ago> The functions in question are basically 1-liners. No, they're not. The first one is not a one-liner. What's the point of spending the time writing your own interface, implementation, and tests of every single util that you end up needing, if you could just import lodash and move on?
- jonahx 4y agoThe first one is 157 characters, and what it is doing can be grokked at a glance, in less than 10 seconds, by a competent developer. Choosing to format the body across 5 lines for clarity does not change that. I consider that "basically" a one-liner. > What's the point of spending the time writing your own interface, implementation, and tests of every single util I would not write tests for many of these, and the interfaces usually require no design because these are familiar functions like map, filter, etc, to most experienced developers. I gave the main reasons answering your questions in my last post, and I think those reasons are powerful enough that I would consider using a lodash a mistake in most situations. You are essentially making the "leftPad" argument, it's a kind of inverse "NIH" ethos: Why should you ever write your own anything when someone else has done it? And the answer, again, is the same: dependencies have a non-trivial cost.
- ysavir 4y agoI don't think the idea is "if you need these 6 simple functions, use lodash, not vanilla JS". If you only need 6 simple functions, then writing them in house makes sense. But suppose you already have usecases for lodash's more complex functions. It can make sense to use a library like lodash to fill in those functions rather than utilizing your own. And if you already have lodash available, you may as well use it for simple functions, too, rather than write your own.