I'm confused - most, if not all of the examples above can be achieved using less code in plain JS - without the overhead of a library. Using plain JS will also be faster. The debounce one is quite useful, but again - easy to write yourself instead of including a whole library
In general for this simple cases yes you don't need lodash, but in more real complex applications is simplify many things especially the chaining.
For example in 1 and 4 when you don't know in compile time the "path", but is something that is user/api/external input how you are going to do it ?
One other thing that I like in lodash is the internal error checking and handling. For example the 2 and 3 example if the adoptableDogs is null/undefined the code is going to get exception, you need to check it before use it.
The lodash is going to return empty array in map and null in find, a consistent result that you don't need to have special check or path in your code flow.
I agree. I was merely pointing out that these were poor examples, that do not really give any idea of why, and in what situations Lodash can be beneficial
I write code, front-end and back-end, and like deploying it on AWS. Software Developer for 20 years, and still love it. Amateur Powerlifter & Parkourist.
4 is doing mutation. In Lodash, set safely gives you a new object (not deep clone, but property copy)
1 - 4 cannot be curried in normal JavaScript unless you manually wrap them. When you start composing functions, whether using Promise, your own composition, or the new pipeline operator, you end up wrapping all this stuff.
You can re-use the partially applied functions in 2; creating these yourself just to re-use is tiresome.
Not all JavaScript supports this. Many of us still deal with various IE or old Node.js versions that can't be upgraded yet. #inb4Babel This is why we use Lodash, not just 5 methods that happen to have equivalent features in "the latest JS". We agree with you that if you have that ability in the browser or your current version of Node.js, yes yes, totally use the native functionality.
Outside of AWS Lambda, filesize doesn't matter in Node.js.
So, the writer's example for number 4 then does not even work? The way the example is written implies mutation. This adds even more weight to my contention that these are poor Lodash examples
well, import { debounce } from 'lodash'; kinda takes your argument away (there are even separate packages for everything). also, in past years I'd been writing my own debounce function in every project, it isn't that a complex mechanism. I'm not that foolish any more. the lodash's version is superior and documented. and that's gist of it.
I'm confused - most, if not all of the examples above can be achieved using less code in plain JS - without the overhead of a library. Using plain JS will also be faster. The debounce one is quite useful, but again - easy to write yourself instead of including a whole library
1.
2.
3.
4.
No 72.5Kb of
lodasheven remotely requiredIn general for this simple cases yes you don't need lodash, but in more real complex applications is simplify many things especially the chaining.
For example in 1 and 4 when you don't know in compile time the "path", but is something that is user/api/external input how you are going to do it ?
One other thing that I like in lodash is the internal error checking and handling. For example the 2 and 3 example if the adoptableDogs is null/undefined the code is going to get exception, you need to check it before use it.
The lodash is going to return empty array in map and null in find, a consistent result that you don't need to have special check or path in your code flow.
I agree. I was merely pointing out that these were poor examples, that do not really give any idea of why, and in what situations Lodash can be beneficial
Some points:
setsafely gives you a new object (not deep clone, but property copy)Promise, your own composition, or the new pipeline operator, you end up wrapping all this stuff.So, the writer's example for number 4 then does not even work? The way the example is written implies mutation. This adds even more weight to my contention that these are poor Lodash examples
Recommendation: Do not use Lodash in current year.
Like others here have pointed out, It is a literal waste of kb's in your payload. :)
well,
import { debounce } from 'lodash';kinda takes your argument away (there are even separate packages for everything). also, in past years I'd been writing my own debounce function in every project, it isn't that a complex mechanism. I'm not that foolish any more. the lodash's version is superior and documented. and that's gist of it.debouncing is not Lodash tho, it’s part of the library by practical coincidence.
It could also be a separate package like you point out.
Lodash was made in an age when array methods where lacking and polyfiling was less common.
If they changed the focus of the library, then I did not get the memo. :)
in Lodash, I use debounce and cloneDeep most :)