Before I get flamed for my choice of packages, I acknowledge that each of them has its use cases where it would be legitimate and perhaps even recommended to use the library. But let's be honest here: for what Mari wants to write, she clearly does not need them.
Today, January 30, marks 2 years since the airing of YoriMoi episode 5 (the source of this clip).
Sauce: {Sora yori mo Tooi Basho} Base script and styling: Coldgirls (orz) Source subtitle file (In case you missed my reply in the Best of 2019 winners announcement thread, I've started uploading the subtitles for my videos to a GitHub repo for anyone who wants to play around with them.)
Zero-padding numbers to be a certain width comes to mind. You might even space-pad it if your application is running in Node and your output is to a terminal. But it's only useful if your environment doesn't support String.prototype.padStart and you really don't want to write it yourself.
You could, but if you're going to do that, it's not much more work to just import it from somewhere, which has the additional benefit of being updatable in case there's a bug in the polyfill. Of course, apart from the overhead of importing a package, a big downside is that you're opening yourself up to the whole left-pad debacle.
The only major platform that doesn't support String.prototype.padStart is IE, so there's really no excuse not to use it.
var element = document.createElement('div')
element.innerHTML = `
<h1>This element is looping</h1>
${Array(5).join(0).split(0).map((item, i) => `
<div>I am item number ${i}.</div>
`).join('')}
`
/*
Results:
<div>
<h1>This element is looping</h1>
<div>I am item number 0.</div>
<div>I am item number 1.</div>
<div>I am item number 2.</div>
<div>I am item number 3.</div>
<div>I am item number 4.</div>
</div>
*/
I'm sure it's useful and I can see the value especially since dates and times are hard, but I was thinking back to a time where I saw Moment only being used to parse an ISO date, which can easily be done with the native Date constructor.
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.
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.
Edit: I've directed a number of colleagues to this site in the past because they didn't know any other way to get the day of the week. I'm sure there are apps that require the functionality of moment, but it carries a lot of bloat if you're only using it for a couple functions.
There's no excuse for loading moment in a project and just using methods already easily available / implementable within JS Date.
But regardless, even if you ever feel the need to use a library, use it. If you're not sure, always just go with the library. I've noticed lots of junior developers always think they can reimplement everything themselves to save space and performance but it usually has the opposite impact on the project.
Honestly, it's 2020: No one really seriously cares about 500kb of space and how performant your code is unless it starts to negatively impact the users experience
There's nothing wrong with using a library, but it would be responsible to shop around first to see if there's anything lighter if you only need a function or two.
No one really seriously cares about 500kb of space and how performant your code is unless it starts to negatively impact the users experience
That's just the thing: if your users are a known subset or you're targeting a certain demographic, maybe not, but if your users are anyone on the Internet, people with metered connections are going to care. 500kb still goes over the Internet, and the page loads that much slower for them. 500kb is the equivalent of a large image, but unlike an image, it'll block the page from rendering since it's a script.
Array.prototype.reverse is really old, though: it's old enough to have been in the initial version of the language. I can't say that JavaScript was ever designed to be fully functional, although you can certainly use it like that nowadays as Ramda demonstrates, but the functional paradigm was clearly not a consideration at the time Array.prototype.reverse was added.
129
u/bucket3432 Jan 30 '20 edited Jan 30 '20
Before I get flamed for my choice of packages, I acknowledge that each of them has its use cases where it would be legitimate and perhaps even recommended to use the library. But let's be honest here: for what Mari wants to write, she clearly does not need them.
Today, January 30, marks 2 years since the airing of YoriMoi episode 5 (the source of this clip).
Sauce: {Sora yori mo Tooi Basho}
Base script and styling: Coldgirls (orz)
Source subtitle file (In case you missed my reply in the Best of 2019 winners announcement thread, I've started uploading the subtitles for my videos to a GitHub repo for anyone who wants to play around with them.)
EDIT: formatting
49
u/IsaacDy Jan 30 '20
This is such a high quality meme, good work OP
28
u/[deleted] Jan 30 '20
whats the built in replacement for handlebars?
not trying to meme, just trying to learn.
19
u/Oiux Jan 30 '20
I noticed you put moment as a useless dependency but I can't even count how many times moment has saved my ass lmao
10
u/XmiteYT Jan 31 '20
i recognized the anime from the outside house frame, high quality meme, OP.
sora yori best anime.
7
u/Busti Jan 31 '20 edited Jan 09 '26
10
u/[deleted] Jan 30 '20
This is amazing.
1
u/Mitoni Feb 06 '20
Knowing that our enterprise level front end has half those libraries in our Angular project...
1
u/blaZofgold May 29 '20
This is beautiful