Considering how many websites were temporarily obliterated by the
left-padfiasco, being an npmjs maintainer might be an even higher power-to-effort ratio (by virtue of a near-zero denominator) than being a billionaire CEO.I still find it hilarious people think linking to some lib online on a live website makes sense. And people still do. Ehh.
One way in which this could have come about is that
Math.randomwasn’t supported in all relevant browsers when the library author wrote the library. So they had to roll their own randomness with blackjack and hookers. Later the web standards evolved and the author was able to remove the custom code, but now had people relying on his library’s exposing agetRandomfunction.Pretty sure that math.random is decades old.
Pretty sure many codebases running today (even JS ones) are older
Math.random() was always in the spec: https://ecma-international.org/wp-content/uploads/ECMA-262_1st_edition_june_1997.pdf
How many JS codebases are over 30 years old? Can you name even one?
You see this kind of stuff in C all the time when a code base supports multiple OSs by using macros.
Yes, though at least with C you have the compiler to optimize the cruft out of your binary and end up with a nice, clean program.
With JavaScript this is going to incur some runtime cost everywhere this library is used, even if it only happens once when getting optimized out by the JIT compiler.
If only there was a way to put ads in the code. Think of the revenue!
Copilot - I see you’re using a random function, would you like to buy this cool shirt whose designer used Math.random() to help make them all unique?
Simmer down, Satan
😂
I get that this is a joke, but would something like
import Math.random as getRandomwork better? Because that basically what you’re doing here, renaming the function.that’s not really a thing in JS as Math isn’t imported, it’s just an object available globally. the closest you can get is like
const { random: getRandom } = Mathbut that’s just uglier.the implication is that this function is exported from a library so they have to keep the function around - obviously in a modern project you’d just do
Math.random()And that’s only one of the many reasons that JavaScript is a clown language.
I can imagine multiple scenarios where this could be useful. Simplest is perhaps the coder imagined at the time they could extend the function in later stages.
Then they could add their own function in later stages. YAGNI exists for a reason.
i mean its still good to use an abstraction layer in case you ever have to change the underlying call; it’s far easier to change it in one place instead of replacing every call
YAGNI








