r/ProgrammerAnimemes • • Jan 30 '20

OC Dependencies

Enable HLS to view with audio, or disable this notification

1.6k Upvotes

39 comments sorted by

View all comments

Show parent comment

8

u/BakuhatsuK Jan 31 '20

I agree with both. If you are already using it in a bunch of places (you are already paying the bundle size price) it doesn't matter if you use it for a trivial task.

But if you are including it for a single use in your application, chances are using Date wouldn't be that painful.

Date in JS is actually really nice compared to, for example, C's datetimes in seconds from the epoch. JS Dates have millisecond resolution btw.

Furthermore, moment is really huge, even more if you need locales (I'm in Colombia so I have to include them to get months and stuff in spanish).

With webpack treeshaking might save you but only if you also have good chunk splitting.

2

u/bucket3432 Jan 31 '20

If you are already using it in a bunch of places (you are already paying the bundle size price) it doesn't matter if you use it for a trivial task.

Certainly, and that's part of what the "they might already have solutions for what you need" line was alluding to.

Would you extend this to using a dependency of a dependency (e.g. using lodash if one of your dependencies uses lodash)? I'm not sure if I would, because although the bundle size doesn't change, you're still adding a dependency. The package using the library might upgrade to an incompatible version or move away from it altogether in a future version, leaving you with a separate copy of the library.