Hacker News new | ask | show | jobs
by andrewzah 2242 days ago
No.

Other languages don't publish/import packages that are one line of code. I have never seen an issue like this with any other language that I've worked with.

Any sane developer that needed a one-liner like this would just manually implement it.

Not to mention that these sorts of functions are unnecessary in languages with a good stdlib or statically typed languages like rust, etc.

2 comments

I have posted one liners to crates.io that were eventually put in the stdlib.
True this problem also exists in Rust, even going so far as people "claiming" and SELLING nice package names.
Name squatting on crates.io is another issue entirely, though. It's also a can of worms that I won't open.
I haven’t heard about selling at all. Have a pointer?
Know what happens every time people like you say this here on HN? They post the one-liner they would have manually implemented in their code base and it's wrong. The one that comes to mind is the "is-negative-number" package. Yes, the geniuses of Hacker News, after finding out there was an npm package for determining whether something was a negative number, could not correctly implement that function.

You and everyone here are not as clever as you think you are. This is why people prefer known-good implementations. The maintainer here did a bad release, big fucking deal.

Please don't use allcaps for emphasis on HN. This is in the site guidelines: https://news.ycombinator.com/newsguidelines.html.

As a stretch target: it's a bad idea to create demons out of an assortment of posts you randomly saw on HN. This site gets 3M posts a year. You can find basically anything in there.

https://news.ycombinator.com/item?id=22098687

What happens is that we each have pre-existing images that bug us (e.g. for example, people who overrate their own genius) and as we move around in the statistical cloud, random bits of whatever we run into stick to the pre-existing image and give it form. Poof, you have a demon—but actually it just became visible. Readers with other images see other demons and arrive at other generalizations. It's not good discussion because it's really about one thing but we make it about another, and comments that are skewed in that way limit their own interestingness. (I definitely don't mean to pick on you personally. We all do this.)

You may be shocked to find that there are very novice developers as well as those with 20+ years of experience who frequent HN. Using a few poorly written comments is a strawman, unless the comments you're referring to are written by the same people you're addressing here.
Maybe its a failure of the language when it takes a third party package to determine if a number is greater than or less than zero?
> Maybe its a failure of the language when it takes a third party package to determine if a number is greater than or less than zero?

It's not a failure of the language. Javascript has comparison operators like every other language, it's entirely possible to determine if a number is greater than or less than zero without importing a third-party package.

What it is is a failure of modern JS development culture, because apparently it's anathema to even write a simple expression on your own rather than import a dependency tree of arbitrary depth and complexity and call a function that does the same thing.

Their code would have been wrong even in strongly typed languages because it considered 0 to be a negative number. What language prevents you from making that mistake?
> COULD NOT CORRECTLY IMPLEMENT THAT FUNCTION

As opposed to blindly trusting and adding a dependency for a random library with a one liner?

I don't think the "don't roll your own crypto" argument really applies here. Of course we can come up with hypothetical situations where developers are incompetent or don't test their code at all. This includes armchair analysis for a post on HN, by non-javascript developers.

I would argue that it's still better than adding a dependency. Heck, you could even copy/paste the correct code.

I know I'm not a perfect programmer, so important functionality like this gets unit tested as necessary. :-)

A package with over 11 million weekly installs vs. a brand new implementation by a coworker, when I might not necessarily be around for the code review? Absolutely. I would blindly trust the package 100% of the time. Zero hesitation.
As demonstrated in this reply - https://news.ycombinator.com/item?id=22979718, this package is also wrong. So the argument is invalid?
The package isn't wrong, you're just confused about duck typing.