6 ms·
So if you need that package in your 10 projects, do you copy those 20 lines of code in your 10 projects? Yikes. Then what happens when it requires a change? Do
by ggregoire 6y ago
So if you need that package in your 10 projects, do you copy those 20 lines of code in your 10 projects? Yikes. Then what happens when it requires a change? Do you make the change in all your projects? Double yikes. When it becomes 30 lines, do you still copy/paste those 30 lines in all your projects? Do you also copy/paste the tests related to those 30 lines in all your projects? ...
Having reusable code wrapped into packages is basic software engineering.
- nightski 6y agoOr you create a library which contains a collection of 10-20 line of code modules and share it among your projects.
- ggregoire 6y agoYes I agree it's better to have one library with 20 helper functions than 20 libraries with 1 function each. Think Lodash. Although some people will then complain about the size of the library...
- speedgoose 6y agoYes. Every Lodash function is available in its own npm package too. I use it like this, I rather have 4 lodash packages than the big whole lodash library in one package with almost everything left unused.
- runawaybottle 6y agoJS libraries only did that to reduce bundle size being sent to the browser. It’s done out of necessity, not because it makes any sense. Exporting out one method at a time is pretty absurd.
- speedgoose 6y agoLodash has a lot of features that are not needed anymore or even dangerous sometimes. If you don't need them, why would you install them?
- runawaybottle 6y agoBecause it’s simply not a big deal on the server.
- Master_Odin 6y agoThese will go away in v5 (if a v5 is ever released) and is not recommended if using a bundler as it'll end up wasting space rather than saving as it'll include duplicate code that each individual function could share. https://lodash.com/per-method-packages https://lodash.com/per-method-packages
- speedgoose 6y agoThanks for the information. I think it will be about time to completely remove lodash from my code bases.