8 ms·
This has to be a joke right?
by dgb23 5y ago
This has to be a joke right?
- SenHeng 5y agoisOdd and isEven pop up often but they and all those other packages were explicitly created for the sole purpose of boosting the author's profile. https://news.ycombinator.com/item?id=29241943 https://news.ycombinator.com/item?id=29241943
- dncornholio 5y agotoo be honest, a comment of someone doesn't make it true. It could be he has actual use cases for these repositories. Just that someone thinks it should'nt be used like this, doesn't mean it's true. It seems like a lot of people think they think how npm should work, while forgetting to see how npm actually works. There's even an example of a well respected npm author that has repositories with just a few lines.. Y'all just love to hate on npm
- oneeyedpigeon 5y ago> It could be he has actual use cases for these repositories. If that were true, it would be useful for the author to actually explain that in his repo documentation. As it is, concluding that this is a joke is by far the most reasonable response.
- smoldesu 5y agoThe "joke" is that you can determime whether a number is odd or even with a modulo in half the code and a fraction of the storage space of a library. There is no use case for it because it's a built-in feature of the language, and in the age of inane web bloat, supply chain attacks and Javascript cargo-culting, I think laughing at stuff like this is perfectly warranted.
- layer8 5y ago> you can determime whether a number is odd or even with a modulo Or you could check the lowest bit. Better to abstract away from that implementation decision. ;)
- smoldesu 5y agoThat too, but I get the feeling those kinds of operations aren't in Javascript's standard library...
- layer8 5y ago`my_number & 1 == 0` works.
- c0wb0yc0d3r 5y agoJavaScript does have bitwise operators. Something I was surprised by was that numbers are stored as 64 bit while all of the bitwise operators operate on 32 but numbers. This means that every operation results in a number conversion first.
- recursive 5y agoNot just 64 bit. 64 bit floating point. You can't just get the "low bit". You need to take the exponent into account to figure out which bit of the mantissa to grab. It's intrinsically more computationally difficult than is-odd on a real integer.
- dncornholio 5y agoI don't get the issue. You write a function to check if a number is odd. You seem to have this function in every project so you make a package for it so you, and others, can easily include it. This is exactly what npm is made for?
- oneeyedpigeon 5y agoHow far do you take this: an `inc()` function? If we get to a stage where every piece of software in the world depends on one random person's ridiculous npm module, we'll be in a pretty precarious state.
- zeta0134 5y agoThe issue is the idea of introducing an external dependency for a one line function that anyone with a rudimentary understanding of programming should be able to write in their sleep. The idea of sharing code isn't flawed here, but the risk / reward in these cases is very much out of whack.
- dncornholio 5y agoThe risk / reward of using npm is always there. It doesn't matter how big the package is. Any dependency is a risk? You're free to not use the dependency. Nobody is forcing you. If someone wants a 1 line dependency, I say let them. I have zero issues with that. Again, if you think something is not how it supposed to be, maybe YOUR view on what it supposed to do is whack instead?
- jraph 5y agoTesting whether a number is odd is done in 3 characters: n % 2 if you don't like the % you can also do it using a bitwise AND, this also handles negative numbers: n & 1 this is equal to 1 if the number is odd, 0 if it is even, and will be converted to true or false in a if statement. You don't need a library for this. And you should not need a library to handle string conversions, you should be aware of the types you manipulates. If you do need to handle strings, that's still easy: Number(n) & 1 And Number(n) is a no op if n is already a number. But wait, no, actually, you don't even need this because % and & will auto cast the string to a number anyway. You can use parseInt(n) if there's a chance that your number is going to be non integer, but meh. So n & 1 will cover everything. All this is readable and idiomatic, there's no need to write a function for that, let alone a full fledged library with unit tests, package.json and all this crap that bloats the node_module folders of everybody. isOdd = require('isOdd') and your entry in the dependencies of your package.json is going to be more verbose than isOdd = n => n & 1. Even "isOdd(n)" is longer than "n & 1". Nothing beats the "& 1". If people are going to write libraries for all kind of similarly small and trivial things, soon we will need more than the Earth to handle our code.
- luispauloml 5y agoThat's what it looks like. This is one of the dependents on `is-odd`: https://www.npmjs.com/package/is-104 https://www.npmjs.com/package/is-104 https://github.com/acappato/is-104/blob/main/index.js https://github.com/acappato/is-104/blob/main/index.js
- JohnWhigham 5y agoYes, JavaScript is a joke for having such a barren standard library that the community has to do it for them.
- jraph 5y agoOk, which programming languages actually have an isOdd or an isEven function in their standard library? Anyway, Javascript, like virtually every programming language, has "& 1". Yes, the standard library is lacking and yes, that's a big issue, partly responsible for the huge mess that is NPM. No, it does not matter one bit here so this is off topic.
- lotsofcows 5y agoGosh, never look at C. You'd break ribs.