r/badcode • u/s1nical • Aug 21 '20
js moment.js: modern problems require modern solutions.
112
Aug 21 '20
Probably a placeholder for the future funcionality.
51
u/geesuth Aug 21 '20
Yeah. That's
29
Aug 21 '20
It?
24
u/glydy Aug 21 '20
Yeah. That's
11
u/sezirblue Aug 21 '20
What I was going to say?
11
u/thatwasagoodyear Aug 21 '20
Yeah. That's
10
2
35
Aug 22 '20
Highly unlikely to be stupid — both of the options already presented here (a placeholder, and leaving something there to override in a locale) are likely candidates for what we are seeing here, and neither one is a stupid thing to do.
1
u/galexj9 Aug 22 '20
I'm a novice programmer so forgive the question. But don't languages usually have a way to denote default methods that are intended to be overridden? Like a Java abstract?
4
u/maxslayer44 Aug 22 '20
In JavaScript there's no abstract or interfaces unfortunately
11
u/haikusbot Aug 22 '20
In javascript there's no
Abstract or interfaces
Unfortunately
- maxslayer44
I detect haikus. Sometimes, successfully. | Learn more about me
Opt out of replies: "haikusbot opt out" | Delete my comment: "haikusbot delete"
5
1
Aug 22 '20
This provides default behavior so that you don't have to override it when you don't need to.
Also, JavaScript (to the best of my knowledge) has no built-in equivalent of an
abstractmethod - in fact, in js you're not manipulating classes that inherit from each other but prototypes. You can achieve class-like behavior with them, but fundamentally they are a different approach.
16
10
Aug 22 '20
Another possibility besides the suggested options is that maybe this actually did something at some point, but the actual body of the function was removed because it was causing issues. Not good practice, but doubt that someone would do this just for shits and giggles. Especially in a library like moment.js
4
u/TheUnlocked Aug 22 '20
This is very reasonable code. They know that at some point in the future it may be necessary to do formatting on certain strings, so instead of just putting it off for later, they've made a function which will let them make any necessary changes in one place later.
4
u/timgfx Aug 22 '20
This is not bad at all. If you ever have to change the format you will only have to change one function.
It’s pretty much equivalent to making abstractions over third part modules; it allows you to change code very efficiently
6
5
3
-2
157
u/lesleh Aug 21 '20
Must be there for locales to override as necessary, would be my guess?