4 ms·
I am absolutely flabbergasted that the `is-odd` package on NPM [1] was downloaded 3 million times last week. In any project, a check for an odd number would hal
by suprfnk 8y ago
I am absolutely flabbergasted that the `is-odd` package on NPM [1] was downloaded 3 million times last week. In any project, a check for an odd number would half the time not even have its own _function_.
Even an aggressive build server that redownloads and builds 50 times a day would require 60.000 separate installs...
Does anyone have any reasonable explanation for this?
[1] https://www.npmjs.com/package/is-odd https://www.npmjs.com/package/is-odd
- rypskar 8y agoThe best part is that is-odd depends on is-even [1] [1]https://www.npmjs.com/package/is-even https://www.npmjs.com/package/is-even
- flukus 8y agoOther way around, is-even depends on is-odd. But wait, there's more. Is even depends on is-number, so in the node.js world '515' is odd. It doesn't matter how good javascript compilers get when you throw this level of slop in.
- pluma 8y agoAs a JS dev, this actually offends me. I wouldn't expect a specialised package to silently convert strings to numbers. I think is-odd and friends are the aftermath of the microlibrary craze that followed the popularity of "toolbelt" libraries like jquery, underscore and lodash (which featured some equally inane methods but bundled them along with a load of far more complex helpers you wouldn't want to implement and maintain yourself).
- grajaganDev 8y agoI found this funny but on further reflection it is just good engineering.
- LandR 8y agoThis is should be funny, however in the JS / Web dev world nothing suprises me anyone. The whole ecosystem is an insane mess.
- bovine3dom 8y agoYes: the author of the package uses it himself in some of his other packages, which are popular and used in popular projects, e.g. [1]. So it isn't that millions of people think isodd is a sensible package: just at least one person does, and he made it. [1]: https://www.npmjs.com/package/nanomatch https://www.npmjs.com/package/nanomatch
- suprfnk 8y agoAh that's what I missed. This makes more sense. Thanks.
- caspervonb 8y agoWhich in turn gets pulled into Webpack and Babel, but the case stands for just about any is-* package.
- stupidcar 8y agoCorrectly checking if a variable is odd is not quite as simple in a dynamic, type-coercing library like ECMAScript as you might think. You have to consider things like: is the variable null or undefined? Does it have the Number type? Is the number an integer? Is the integer odd? In a statically typed language, the compiler would guarantee many of these things for you, but in ES you need to do it yourself. It's not rocket science, but it's tricky enough that you could perhaps make a mistake or overlook something. To be safe in these situations, when writing a small amount of "nearly trivial" code, programmers have generally resorted to a package manager called "Google / Stack Overflow". This package manager works as follows: You Google for "safely check if odd in JavaScript", open the top Stack Overflow link, then copy and paste the answer (usually a single function) into your codebase. Then you add a comment saying "taken from https://stackoverflow.com..." https://stackoverflow.com...". Whenever you have another piece of "nearly trivial" code to write, you install it the same way. ES developers thought that this workflow could be optimised a bit. To that end, they invented a package manager called "npm". Unlike the Google / Stack Overflow manager above, this lets you install functions like "is-odd" without having to manually copy and paste them from your browser. It also keeps track of where they came from, who authored them, and even lets them be updated, if necessary.
- goatlover 8y agoIn that case, sounds like is_odd/even should be part of the language, given how widely used and basic it is. Useful methods get added to strings, arrays and objects each ES release.
- charliesome 8y ago> You have to consider things like: is the variable null or undefined? Does it have the Number type? Is the number an integer? This is a non-problem. If you really have to consider all these edge cases before testing if a number is odd or even that's a sign you need to seriously rethink your domain model, not reach for a library that has already thought about these edge cases for you. Well written dynamic code should be mostly statically typed.
- sedeki 8y agoIf every one of your functions are type asserting at run-time, I think you should just switch to a statically typed language.
- siddhant 8y agoIs anyone else bothered by the following? isOdd('1'); //=> true String input to a function that checks on numbers is considered valid?
- HelloNurse 8y agoThe Javascript tradition is coercing '1' to 1, so it is a number for most practical purposes. A language with more restrained type conversion rules would have a different, and more trivial, isOdd() function.
- caspervonb 8y agoPersonally I'd just let that be UB; garbage in, garbage out.
- spondyl 8y agoClearly there is value here: https://github.com/micromatch/nanomatch/pull/7/files/573338f1f118775f0c16370d989e6079aa2a6c68 https://github.com/micromatch/nanomatch/pull/7/files/573338f... /sarcasm