News for hackers. Stuff that matters.
Re:4B If Statements by oefrha on Thursday December 28, 2023 @02:57AM (#38791094)
This approach is perfect for the is-even npm package[1], with 196,023 weekly downloads, or the is-odd npm package[2], with 285,501 weekly downloads. Wouldn't it be cool if you type `npm install` and it starts downloading a 40GB is-even and a 40GB is-odd?

[1] https://www.npmjs.com/package/is-even

[2] https://www.npmjs.com/package/is-odd

Re:4B If Statements by lvncelot on Thursday December 28, 2023 @03:38AM (#38791336)
It's always worth mentioning that those packages stem from the effort of one dedicated npm spammer[1] to weasel his way into as many node_modules directories as possible. There's also packages for ansi-colors (no, not one package for all colors, one package for each color) and god knows what else. These then get jammed into any cli tool or other half-way sensible looking package, all referencing each other obviously - and any "real" project is just a single innocuous dependency away from having dozens of jonschlinkert packages.

[1] https://www.npmjs.com/~jonschlinkert

Re:4B If Statements by jevoten on Thursday December 28, 2023 @04:46AM (#38791758)
Achieving supply-chain security by controlling every link in the chain. This Jon is very noble.
Re:4B If Statements by jbverschoor on Thursday December 28, 2023 @05:47AM (#38792111)
Packages should specify their entitlements.. network access, file access, executing system calls, being able to monkey patch things, accessing packages outside their own.
Re:4B If Statements by vorticalbox on Thursday December 28, 2023 @05:54AM (#38792154)
Deno has a few of these by default an application has no access to the filesystem, env or network.

You can allow only reading or only writing for files and you can also define what domains are allowed.

Re:4B If Statements by jbverschoor on Thursday December 28, 2023 @06:57AM (#38792560)
Sure it's a huge step forward. But that's on an application level, which honestly I can do with sandbox-exec on macOS (see below).

In Deno, all permissions would still propagate down to the dependencies.

  (version 1)
  (deny default)
  (allow file-read*
    (subpath "~/Downloads")
  )
  (allow network-outbound
    (remote tcp "localhost:80")
  )
or

  (version 1)
  (allow default)
  (deny network*)
or

  # start an airgapped shell, and play around in there..
  sandbox-exec -p "(version 1)(allow default)(deny network*)" bash
Re:4B If Statements by vorticalbox on Friday December 29, 2023 @03:17AM (#38802750)
There have been a few GitHub issues open but from what I can tell it's in the "not technically possible with V8 VM" category
Re:4B If Statements by smolder on Thursday December 28, 2023 @06:22AM (#38792333)
Realistically I think they long ago should have been banned from npm, with all submissions deleted.
Re:4B If Statements by fmx on Thursday December 28, 2023 @05:46AM (#38792105)
When I first heard of the is-odd and is-even NPM packages I was sure they were a joke, yet there we are: 200K weekly downloads! Publishing the packages may have been the effort of one spammer, but many developers obviously chose to use them - that's the part that boggles my mind.
Re:4B If Statements by lvncelot on Thursday December 28, 2023 @06:02AM (#38792199)
Well, look at one of the dependents: https://www.npmjs.com/package/handlebars-helpers - certainly a more useful npm package, but by the same author. Seldom do people actually type `npm install is-even` - there's just a jungle of transitive dependencies that can be traced back to one of jonschlinkert's many packages, which then circles back to something inane as `is-even` or `ansi-red`.

I once ran a simple grep in some of my node projects - most of them had a jonschlinkert package in node_modules, certainly not through any (direct) choice of my own.

Re:4B If Statements by spacechild1 on Thursday December 28, 2023 @06:07AM (#38792228)
Check out this very useful utility: https://github.com/mitsuhiko/is-jonschlinkert :)
Re:4B If Statements by bryancoxwell on Thursday December 28, 2023 @06:15AM (#38792280)
I love the release notes:

> It exists.

Re:4B If Statements by password4321 on Thursday December 28, 2023 @11:30AM (#38795171)
Possibly related: https://github.com/SukkaW/nolyfill vs. ljharb and nodejs 4
Re:4B If Statements by runarberg on Thursday December 28, 2023 @12:59PM (#38796281)
I recently came across this issue (https://github.com/import-js/eslint-plugin-import/issues/213... and https://github.com/import-js/eslint-plugin-import/issues/181...) and man that person has really found him self a hill.

What is a bit worrying though is that he is an active member and contributor to TC-39. Meaning that this kind of community hostility is very much alive among the people who rule JavaScript.

Re:4B If Statements by Ataraxic on Thursday December 28, 2023 @01:33PM (#38796781)
View their obstinance: https://github.com/nvm-sh/nvm/issues/794

8 years later and despite much support for the `.node-version` file.

Someone else started using the .node-version file years ago, and because all open source packages won't form a committee to standardize this file, nvm will not support it.

They have a lot of hills. JS Private Properties was another.

Re:4B If Statements by wk_end on Thursday December 28, 2023 @02:21PM (#38797385)
Very often when I’m digging around GitHub Issues because of some bug or quirk or insanity in the JS ecosystem (which is often) I see someone spout the worst possible take - often being kind of a jerk about it - and when I look to see who’s responsible, very very often, ljharb’s name pops up. Often.

Dogpiling on someone deep in an HN comments tree isn’t exactly the classiest thing but…never having interacted with him myself, I’ve been harbouring this low-grade antipathy towards him - nothing unhealthy, just a groan whenever I see his name on GH - for years now, and it’s cathartic and almost gratifying, given his prominence in the community, to feel seen like this. Thank you.

Re:4B If Statements by runarberg on Thursday December 28, 2023 @02:56PM (#38797848)
I was doing some snooping around and found this earlier discussion https://news.ycombinator.com/item?id=37602923 from September 2023 (234 points, 110 comments), which I had missed at the time, very related to this current subthread, and includes posts such as these (https://news.ycombinator.com/item?id=37604635).

I think we as a community really need to have a conversation about ljharb and his role in the future of our industry. If he was only a library maintainer, that would be one thing, we could just move on, find workarounds, alternatives, etc. But his involvement in TC-39 makes him one of our rulers in a non-democratic structure. That makes this different.

Re:4B If Statements by Aeolun on Thursday December 28, 2023 @06:11PM (#38799904)
To be fair, the ESM switch has been botched beyond compare.

It’s like they didn’t want to become Python 2/3, and then did the absolute worst possible alternative.

It is beyond frustrating that it’s up to individual package authors whether or not their package supports ESM or CommonJS.

And yeah, it’s a pita when one of your downstream dependencies decides to go ESM only, and breaks your entire friggin chain of stuff that depends on it being CommonJS.

Re:4B If Statements by runarberg on Thursday December 28, 2023 @06:55PM (#38800227)
I agree. Mistakes were made and migration has been unnecessarily hard. This particular issue doesn’t even affect me. I simply turned off `no-unresolved`. TypeScript handles a lot better anyway (even with jsdoc type annotations).

But what is the issue here is the stubbornness of the maintainer and his unwillingness to accommodate a very sizable portion of his user base. The industry is moving on, and as a TC-39 member he should be aware of where the community is moving as well as show some empathy with his users.

Re:4B If Statements by fmx on Thursday December 28, 2023 @06:12AM (#38792259)
I see, thanks. I guess that answers one question, but raises another: why have his packages depend on more of his packages? If his goal was to be included in as many node_modules directories as possible, and handlebars-helpers was already included what's the point of pulling in is-odd/is-even, too?
Re:4B If Statements by ncruces on Thursday December 28, 2023 @06:40AM (#38792456)
Makes is-odd/is-even popular; many downloads; raises their (and his) profile.
Re:4B If Statements by peteradio on Thursday December 28, 2023 @07:30AM (#38792807)
He could sell rights to the repos and disavow any knowledge of its maintenance while maintaining the link in his own repos. When those sold rights are used to commit some crime he has plausible deniability as anyone else but got a payday. If you try spinning off the subpackage just prior to a sale then it shows some sort of intent.
Re:4B If Statements by umanwizard on Thursday December 28, 2023 @11:21AM (#38795011)
Is there any evidence that he has ever done anything like this, or that he plans to? Or is this just pure speculation?
Re:4B If Statements by peteradio on Thursday December 28, 2023 @12:04PM (#38795549)
I didn't declare he's done this only that it is a vulnerability of depending on those packages.
Re:4B If Statements by plufz on Thursday December 28, 2023 @08:51AM (#38793456)
Might be this from his GitHub bio “Several years ago, just before my 40th birthday, I switched careers from sales, marketing and consulting to learn how to program” Good way to get more eyeballs…
Re:4B If Statements by fmx on Thursday December 28, 2023 @11:56AM (#38795455)
Ah yes, that actually explains a lot! Thanks.
Re:4B If Statements by tshaddox on Thursday December 28, 2023 @09:42AM (#38793888)
Here we are all talking about him now!
Re:4B If Statements by Levitz on Thursday December 28, 2023 @11:07AM (#38794826)
Would it be considered bad practice or in poor taste to make pull requests in projects with the sole objective of implementing is-even natively?

Thinking of being the change I want to see in the world.

Re:4B If Statements by verandaguy on Thursday December 28, 2023 @12:52PM (#38796174)
It’s probably contextual but I’d say it’s in poor taste to use them in the first place. Removing them is a net benefit imo.
Re:4B If Statements by divbzero on Thursday December 28, 2023 @06:26AM (#38792364)
I did learn one new thing from browsing the is-odd source code: Number.isSafeInteger(n) checks that n falls within the [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER] interval.

  ...
  if (!Number.isSafeInteger(n)) {
    throw new Error('value exceeds maximum safe integer');
  }
  ...
Re:4B If Statements by skitter on Friday December 29, 2023 @10:48AM (#38806173)
Shouldn't this simply return true instead of throwing?
Re:4B If Statements by brainzap on Thursday December 28, 2023 @07:24AM (#38792754)
the bigger joke is that programming language have no built in
Re:4B If Statements by fifilura on Thursday December 28, 2023 @07:35AM (#38792829)
Huh? Did you miss the modulo operator?
Re:4B If Statements by kristopolous on Thursday December 28, 2023 @07:55AM (#38793005)
It wouldn't have 200k downloads a week unless there was a large number of programmers who didn't know how to do it.

I mean we're talking FizzBuzz secret sauce here. This must be total black magic for a catastrophic percentage of programmers

Re:4B If Statements by RugnirViking on Thursday December 28, 2023 @08:16AM (#38793150)
A more catastrophic number of programmers a) dont know how dependencies work and b) think everyone else are idiots.
Re:4B If Statements by kristopolous on Thursday December 28, 2023 @12:15PM (#38795681)
Maybe the person you're talking to on hn isn't a total moron.

Perhaps, I solidly understand how dependencies work and in this case my observation is correct

Someone made the decision to use that and someone thought using stuff made by a person's who makes those kinds of decisions was a good idea and so on.

You can git blame dependencies all the way down and research the parties involved. I've done it, built tools for it even.

A stack of people who make bad decisions doesn't make good software.

Re:4B If Statements by robertlagrant on Friday December 29, 2023 @04:53PM (#38810675)
More likely the author made another, more useful, package that uses it.
Re:4B If Statements by arzig on Thursday December 28, 2023 @09:08AM (#38793597)
I have not read the source but I had always assumed that this was the lovingly crafted effort of someone who is intimately familiar with the js standard making sure that some hypothetical expression like ![1] is neither odd nor even. Surely the idea that modulo is beyond developers is too horrifying to contemplate.
Re:4B If Statements by umanwizard on Thursday December 28, 2023 @11:24AM (#38795070)
Here you go:

    /*!
     * is-odd <https://github.com/jonschlinkert/is-odd>
     *
     * Copyright (c) 2015-2017, Jon Schlinkert.
     * Released under the MIT License.
     */
    
    'use strict';
    
    const isNumber = require('is-number');
    
    module.exports = function isOdd(value) {
      const n = Math.abs(value);
      if (!isNumber(n)) {
        throw new TypeError('expected a number');
      }
      if (!Number.isInteger(n)) {
        throw new Error('expected an integer');
      }
      if (!Number.isSafeInteger(n)) {
        throw new Error('value exceeds maximum safe integer');
      }
      return (n % 2) === 1;
    };
It does some checking the `value` is an integer in the safe range, which doesn't even seem right to me. Why shouldn't you be able to call this on integers outside the save range?
Re:4B If Statements by addaon on Thursday December 28, 2023 @11:50AM (#38795375)
All non-safe integers are even, yes?
Re:4B If Statements by johnfn on Thursday December 28, 2023 @02:00PM (#38797140)
(10e15 + 1) % 2 === 0
Re:4B If Statements by fifilura on Thursday December 28, 2023 @10:01AM (#38794009)
Sad but true. For JavaScript these kind of functions can actually be useful because of all the quirks. If that was the GPs hint then I can understand.
Re:4B If Statements by SkyBelow on Thursday December 28, 2023 @01:21PM (#38796589)
Given the lack of integers and my hesitancy to trust modulo for non-integer variables, I don't know if I would trust it. You would need to add some safety checks, but either you create an is_even/is_odd function that has safety checks, or you have to rely on developers adding in the checks anytime the number might have been in close proximity to a floating point number.

Something as simple as this can end up being neither even or odd.

    (0.1 + 0.2) * 10
Re:4B If Statements by charlieyu1 on Thursday December 28, 2023 @03:03PM (#38797937)
It is not just modulo, it also test for whether the input is a number or integer. It also has one dependency, is-number. And isOdd(“3”) returns true.

Basically it helps dealing with all the typing problems of Javascript, and also fitting into functional programming paradigms.

Re:4B If Statements by ownlife on Thursday December 28, 2023 @03:21PM (#38798119)
If you need to know if a number is even or odd then you should convert it to an int natively anyway.
Re:4B If Statements by paulddraper on Thursday December 28, 2023 @02:00PM (#38797134)
Often the is-even package will be imported by another (less ridiculous) package of the same author.
Re:4B If Statements by MyFirstSass on Thursday December 28, 2023 @06:19AM (#38792303)
Seriously fuck this dude leeching on the open source community.

He's not even a technical guy but has a background i marketing and is directly trolling various Github issues :

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

I've always wondered why node-modules and npm required such an insane amount packages so quickly, and now i know why, people like him that use their 10.000 ridiculous packages to boost their career or do whatever self serving community destroying thing they can think off that day.

There really should be a way to ban people doing this shit.

Re:4B If Statements by yreg on Thursday December 28, 2023 @07:08AM (#38792649)
The author hasn't forced you to import their package. What's there to ban apart from maybe polluting the common namespace?
Re:4B If Statements by posix86 on Thursday December 28, 2023 @08:23AM (#38793208)
It's more a statement about the community than him imo. Or maybe about what npm allows to be published. Nobody forced you to use is-odd, yet it's downloaded 200k a week, why? Because js' developer community doesn't know any better
Re:4B If Statements by kardos on Thursday December 28, 2023 @12:20PM (#38795759)
A lot or these downloads may be CI systems running automatic tests.
Re:4B If Statements by darkwater on Thursday December 28, 2023 @12:50PM (#38796148)
They clearly are, but this still means a not negligible amount of softwares have those packages in their dependencies.
Re:4B If Statements by geodel on Thursday December 28, 2023 @11:13AM (#38794913)
Exactly right. Its clever way of deflecting blame that whole community should share by piling on this particular person.
Re:4B If Statements by ycombobreaker on Thursday December 28, 2023 @12:40PM (#38796030)
This really sounds like victim-blaming. The community is vulnerable to somebody publishing asinine modules, which should be addressed. However, this individual is still the perpetrator.
Re:4B If Statements by sam_bristow on Thursday December 28, 2023 @01:45PM (#38796947)
Maybe someone needs to do a website in the same spirit of https://youmightnotneedjquery.com except youmightnotneedjonschlinkert.
Re:4B If Statements by whstl on Thursday December 28, 2023 @09:28PM (#38801188)
Notice that most dependents of his tools are: 1) his own project, 2) abandoned beginner projects.

As some people mentioned, most of the usage of is-even is by tools made by this person.

But the other part is that, he made quite a few development tools for beginners that scaffold new projects and pull lots of his packages as dependencies (especially the handlebars helper), which heavily inflates the number of "Dependents" in NPM.

The other issue is that, in the past, he managed to include some of his less-useless packages in some semi-popular tools.

Re:4B If Statements by bee_rider on Thursday December 28, 2023 @11:22AM (#38795027)
I mostly write in languages without package managers so it is possible that my expectations are just wrong, but is there no way of showing your dependency graph when using npm?
Re:4B If Statements by christophilus on Thursday December 28, 2023 @02:03PM (#38797176)
Here are some popular ones. Now, in two of these cases, they can be dev-dependencies, but even there, it makes me angry, since all of those deps have to be downloaded to my machine, and can run any random code they want at install time (which is why Node projects should always be run in some kind of sandbox).

https://npm.anvaka.com/#/view/2d/jest

https://npm.anvaka.com/#/view/2d/tailwind

https://npm.anvaka.com/#/view/2d/aws-sdk

Re:4B If Statements by throwitaway1123 on Thursday December 28, 2023 @04:35PM (#38798964)
> can run any random code they want at install time (which is why Node projects should always be run in some kind of sandbox).

You can install with the --ignore-scripts flag. Or set the option globally in your npm config file.

Re:4B If Statements by umanwizard on Thursday December 28, 2023 @11:28AM (#38795134)
Isn't the post you linked to about a different person?
Re:4B If Statements by paulddraper on Thursday December 28, 2023 @02:02PM (#38797161)
> There really should be a way to ban people doing this shit.

???

There is. It's called "doing nothing."

It takes work to add a dependency to your project; they don't spring out of nothing.

Re:4B If Statements by AussieWog93 on Thursday December 28, 2023 @07:28AM (#38792793)
This is the first time I'm hearing about this guy, but not sure why there's so much hate.

It looks like he came from a non-technical background, and is trying to make the language more noob friendly.

Compare the pair:

if isEven(n) { }

if (n % 2) == 0 { }

I guarantee you my wife would have no idea what the second snippet even means.

Re:4B If Statements by numpad0 on Thursday December 28, 2023 @08:25AM (#38793222)
if !(n & 1) {} // rightmost bit(LSB) is always `true` for odd integers
Re:4B If Statements by btdmaster on Thursday December 28, 2023 @09:07AM (#38793584)
For code golf purposes, ~n&1 works fine
Re:4B If Statements by extrememacaroni on Thursday December 28, 2023 @09:05AM (#38793566)
AussieWog93 should marry this guy instead.
Re:4B If Statements by cperciva on Thursday December 28, 2023 @03:39PM (#38798307)
// FIXME: This breaks on negative numbers on ones-complement machines
Re:4B If Statements by MrJohz on Thursday December 28, 2023 @09:00AM (#38793530)
There's an argument to be made for writing functions like `isEven` and using them instead of n%2. There's an argument that the JS standard library, or other comprehensive util libraries like Lodash or Underscore should include these functions.

The problem here is introducing separate dependencies for each of these tiny functions. Dependencies are code that you haven't written, but are still your responsibility. For a lot of things, that's a good tradeoff: if you don't have the expertise in a specific area, or if you can offload work to a dependency that you trust, that's great. But for micro dependencies like this, it's usually a bad deal - you don't get anything in return (seriously, how hard is it to write your own isEven function?) but you have to rely on a third party to be secure, to not push anything accidentally broken, to not change the API, etc.

(I think it's also worth pointing out that your wife is not a paid programmer. Software development should be accessible, but this isn't the only goal, and I think it's reasonable to assume that most programmers either understand the n%2 idiom, or know enough to be able to find help on the subject.)

Re:4B If Statements by buttercraft on Thursday December 28, 2023 @10:26AM (#38794308)
The hate is deserved. This person lacks ethics.
Re:4B If Statements by wvh on Friday December 29, 2023 @09:14AM (#38805077)
Most professions require some sort of degree or license before you get to practice it. If your wife wants to develop software, she should learn the basics. Especially when her code is included in larger projects and ecosystems.

I think the criticism comes from the fact it is hard to avoid driving over badly designed bridges or avoid wasteful dependencies in the Javascript ecosystem due to the way the package management is organised, and it is felt this specific person contributes a lot to that problem.

I have no knowledge of this person, but I often avoid Javascript and NPM for exactly that reason. I'm hopeful of Deno though to fix some of that mess.

Re:4B If Statements by umanwizard on Thursday December 28, 2023 @07:52AM (#38792979)
It seems very uncharitable to describe someone as a “spammer” because their philosophy on the proper size of units of code reuse is different from yours.
Re:4B If Statements by Y_Y on Thursday December 28, 2023 @10:29AM (#38794344)
It seems overly charitable to me to frame the dispute in those terms. You and I might differ as to the appropriate amount of vermouth in a martini or pineapple on a pizza and I won't worry much about it, within reason.

There's a limit though! I think up to about 10% pineapple by weight is reasonable for a Hawaiian, if you choose 0 or 20% then we'll have no issue. If you went to 30% I don't think I could stop myself writing a libellous remark on hn. Anything about 50% and I would be morally forced to denounce you to the proper authorities. About 80% is where the nightmares begin.

Re:4B If Statements by hex4def6 on Thursday December 28, 2023 @02:38PM (#38797602)
At a certain point, isn't it just grilled pineapple with pizza crumbs?
Re:4B If Statements by pc86 on Thursday December 28, 2023 @10:33AM (#38794392)
Even if you think having a dependency load `is_even()` is a good thing, surely you can see how it's pretty hard to defend having a completely separate and nearly identical `is_odd()` rather than just `!is_even()`
Re:4B If Statements by Exoristos on Thursday December 28, 2023 @07:40PM (#38800502)
The argument is that non-programmers like his wife don't understand e.g. `!`.
Re:4B If Statements by pc86 on Saturday December 30, 2023 @09:25AM (#38815479)
I think if you're installing npm packages and writing code you're a programmer whether you want to be or not.
Re:4B If Statements by shp0ngle on Thursday December 28, 2023 @09:17AM (#38793679)
You may not like it, but this is what 10x performance looks like
Re:4B If Statements by joenot443 on Thursday December 28, 2023 @09:40AM (#38793880)
> Several years ago, just before my 40th birthday, I switched careers from sales, marketing and consulting to learn how to program, with the goal of making the world a better place through code [1]

It checks out, sales/consulting folks are pretty infamous for their tendency to abuse metrics. The metric here is npm downloads and Github stars.

The strategy does mean that he's _technically_ not inaccurate in claiming this on his LinkedIn -

> NASA, Microsoft, Google, AMEX, Target, IBM, Apple, Facebook, Airbus, Mercedes, Salesforce, and hundreds of thousands of other organizations depend on code I wrote to power their developer tools and consumer applications.

I encountered this type a lot in college consulting groups, it's a little funny seeing one make their way to the OSS community.

[1] https://github.com/jonschlinkert

Re:4B If Statements by whaleofatw2022 on Thursday December 28, 2023 @10:51AM (#38794617)
Yeah but this might make him the Patient Zero for modern tech influencing and blogspam.
Re:4B If Statements by galangalalgol on Thursday December 28, 2023 @12:06PM (#38795568)
Anyone know if this has spread to crates.io yet? I see plenty of name squatting, but I haven't run into real crates trying to insert themselves into everything. Namespaces are sorely needed, including some semi-official ones. candi::rand would be reasonable for candidates to enter std. Watching the battles over tokio getting into candi would be fun.
Re:4B If Statements by internetter on Thursday December 28, 2023 @10:30PM (#38801502)
> Watching the battles over tokio getting into candi would be fun.

What would be the argument for this? It's my understanding that the lack of a default runtime is considered a strength

Re:4B If Statements by jd24 on Thursday December 28, 2023 @01:46PM (#38796970)
> To date, I've created more than 1,000 open source projects

This dude is counting each one as a project hahaha

Re:4B If Statements by jv22222 on Thursday December 28, 2023 @02:49PM (#38797753)
It reminds me of graffiti tagging!
Re:4B If Statements by buttercraft on Thursday December 28, 2023 @02:06PM (#38797200)
It's the truth but not the whole truth
Re:4B If Statements by pc86 on Thursday December 28, 2023 @10:30AM (#38794358)
So what excuse do the people installing these packages have?
Re:4B If Statements by mbb70 on Thursday December 28, 2023 @10:34AM (#38794403)
Another classic from jon is the venerable https://www.npmjs.com/package/isobject coming in at 30,000,000 weekly downloads for

`function(val) { return val != null && typeof val === 'object' && Array.isArray(val) === false; }`

But honestly, having seen "TypeError: Cannot read properties of null" enough times, I give it a pass.

https://npm-stat.com/charts.html?author=jonschlinkert paints a pretty crazy picture

Re:4B If Statements by orenlindsey on Thursday December 28, 2023 @10:42AM (#38794495)
That's hilarious. The best part is that he didn't even try to make good packages (not that hard) but just took the lazy route.
Re:4B If Statements by geodel on Thursday December 28, 2023 @11:12AM (#38794894)
Well one reason could be this software proverb: Good programers are lazy programers.
Re:4B If Statements by mkgeorge7 on Thursday December 28, 2023 @01:21PM (#38796596)
I'm relatively new to the world of node. Is there anything objectively wrong or should I say nefarious with that this Jon person is doing? I guess, what's the issue here, from your perspective, if he's creating package (that albeit are simple) but some some amount of utility?
Re:4B If Statements by lolc on Thursday December 28, 2023 @02:35PM (#38797570)
In my view it is objectively wrong to create trivial npm packages yes. If we look at the npm ecosystem as a commons, that person is polluting it. Of course you could say it's namespaced to one account, so what's the harm? In my view, plenty:

- package searches will show these packages due to the inflated usage from transient deps.

- installs are slower due to the package noise.

- increased attack surface when they are used

- cultural normalization of throwaway packages

Probably more.

Re:4B If Statements by johannes1234321 on Thursday December 28, 2023 @03:43PM (#38798347)
Each dependency causes work for any serious use. You got to check license, got to check for updates, risk supply chain attacks (package disappearing, package replaced with bad code, ...) etc. which causes longer term cost.

In addition abstraction of trivial checks, makes it harder to see the limitations of said routine. How well does it work on numeric strings? How well on large numbers where float properties cause issues?

Re:4B If Statements by Jasper_ on Thursday December 28, 2023 @01:47PM (#38796991)
My favorite is the existence of both https://github.com/jonschlinkert/ansi-gray and https://github.com/jonschlinkert/ansi-grey that do the exact same thing.
Re:4B If Statements by johnfn on Thursday December 28, 2023 @02:03PM (#38797178)
It's weird to me that in every other comment thread on Hacker News, people say "good software should do one thing and do it well". And then the topic moves to NPM, and suddenly everyone loses their mind?
Re:4B If Statements by throwitaway1123 on Thursday December 28, 2023 @04:04PM (#38798592)
This is part of the UNIX philosophy, but sometimes this gets taken way too far. There is of course the UNIX command "yes", which literally just prints the character "y" over and over again (to skip interactive prompts).
Re:4B If Statements by ericbarrett on Thursday December 28, 2023 @05:30PM (#38799546)
GNU yes will actually repeat any string—the default is of course "y". So it's very handy for scripting, and not really as single-purpose as you'd think.
Re:4B If Statements by throwitaway1123 on Thursday December 28, 2023 @05:58PM (#38799808)
Yeah it's definitely useful. Still a bash one liner though:

  function yes { while true; do echo "${1:-y}"; done }
Re:4B If Statements by rini17 on Friday December 29, 2023 @03:28AM (#38802809)
also, it's actually faster than reading /dev/zero if you need some filler data hahahaha
Re:4B If Statements by jrockway on Thursday December 28, 2023 @02:48PM (#38797736)
A little copying is better than a little dependency.
Re:4B If Statements by lolc on Thursday December 28, 2023 @02:38PM (#38797605)
Haha ok do something substantial! It's implied.
Re:4B If Statements by chrismorgan on Thursday December 28, 2023 @03:21AM (#38791235)
Actually it’s not good enough there because JavaScript numbers are f64 rather than u32. Even if you only support the safe integer range (beyond which the answers become somewhat meaningless), that’s 2⁵⁴, more than four million times as large as 2³². Not sure how big the machine code would be, but I’m guessing it’ll just add 4 bytes (40%) to each case, so you’re up to something like 224 exibytes. And that’s when you’re being lazy and skipping the last ten bits’ worth. If you want to do it properly, multiply by another thousand. Or maybe a little less, I haven’t thought too deeply about NaN patterns. Or maybe just infinite if it supports bigints.
Re:4B If Statements by deepsun on Thursday December 28, 2023 @04:30AM (#38791665)
But we can probably compress the data very well (e.g. "double delta" is always zero), and then decompress only needed parts.
Re:4B If Statements by vineyardmike on Thursday December 28, 2023 @04:39AM (#38791718)
This still requires reading through it all in memory at run time. Maybe we can optimize it with a JIT -what if the package called the ChatGPT api to get the the python code that generates the machine code just for the number queried?
Re:4B If Statements by Someone on Thursday December 28, 2023 @04:34AM (#38791692)
But you can create a self-modifying function that, ‘for speed’, adds each case when it is called.

The initial function should start with checking for special cases NaN, infinities, 0 and -0, then do (may not be valid JavaScript)

  if((x++ === x) && (x—- === x)) printf("even\n");
to handle cases over 2^54 or below -2^54, then do

  isOdd = true
  neg = x
  pos = x
  while(true) {
    if(neg++ === 0) break;
    if(pos-- === 0) break;
    isOdd = !isOdd
  }
to determine whether x is odd or even in isOdd. Doing the self-modification is left as an exercise.

This is good defensive programming. It avoids doing a tricky division by 2.0 that might be buggy (I don’t think https://en.wikipedia.org/wiki/Pentium_FDIV_bug was affected, but who knows what other FPUs do?)

Re:4B If Statements by chrisandchris on Thursday December 28, 2023 @03:07AM (#38791149)
The funniest (or best part) about those two packages is that is-even has a dependency to is-odd and does just negate the output of is-odd.
Re:4B If Statements by jl6 on Thursday December 28, 2023 @03:23AM (#38791247)
It’s true, the great thing about clean, reusable, modular code like this is that you can compose both of these packages to make a is-even-or-odd package.
Re:4B If Statements by lvncelot on Thursday December 28, 2023 @05:14AM (#38791960)
Well first you need to obviously build an OR package, part of your suite of logical operator packages, all depending on your battle-tested, high performance XOR package.
Re:4B If Statements by wiseowise on Thursday December 28, 2023 @05:19AM (#38791986)
Groundbreaking!
Re:4B If Statements by kparaju on Thursday December 28, 2023 @12:37PM (#38795972)
Re:4B If Statements by layer8 on Thursday December 28, 2023 @05:51AM (#38792140)
If would be even funnier if is-odd would simultaneously do the same thing in reverse.
Re:4B If Statements by cyco130 on Thursday December 28, 2023 @05:16AM (#38791972)
But of course WebAssembly is the future. So we should reimplement it in WASM.
Re:4B If Statements by christophilus on Thursday December 28, 2023 @05:38AM (#38792073)
Every time I see these packages mentioned, I’m reminded of an interview with Joe Armstrong. In it, he said, (paraphrasing from memory) “Wouldn’t it be interesting if a language had a global, flat registry of functions that anyone could pull from and contribute to? That way, bugs are fixed in one place, there’s less reinvention of the wheel, things get more correct over time, and programs just become a simple composition of standard functions.”

I may be misremembering his meaning, but I remember thinking it was an interesting idea. It wasn’t obviously a terrible idea. I thought it would be like the Clojure standard library on steroids, especially if it was coordinated and vetted by a decent team.

But alas, NPM has proven it otherwise.

Re:4B If Statements by divbzero on Thursday December 28, 2023 @08:20AM (#38793185)
NPM doesn’t capture the full benefit of an open registry of functions because, while anyone can fork and create an alternative @christophilis/is-even or @divbzero/is-even, there is no good way for developers to pick the best version of is-even.

Maybe if NPM required all package maintainers to use a namespace, the global is-even package name could resolve to the most-used fork.

So for an import like:

  import isEven from 'is-even'
You could install a specific fork:

  npm install --save @christophilus/is-even
Or default to the most-used fork:

  npm install --save is-even
In both cases, package.json would only contain namespaced dependencies and npm outdated could flag if a different fork is more commonly used.
Re:4B If Statements by harperlee on Thursday December 28, 2023 @05:45AM (#38792100)
I don't think NPM has proven that idea infeasible, just that it may not be a good idea to depend on third-party content that may change under your feet, on such a fine-grained level.

But have a look at the Unison language https://www.unison-lang.org/docs/the-big-idea/ , that has such global registry but addresses each function by a hash of its syntax tree, and thus sidesteps the issue.

Re:4B If Statements by ncruces on Thursday December 28, 2023 @06:45AM (#38792485)
How are bugs "fixed in one place" that way?

You either accept updates of third party packages, with little to no vetting of your own, and get fixes "for free" or… you don't.

There's no middle ground: the only way to save effort is to trust others.

Re:4B If Statements by MisterTea on Thursday December 28, 2023 @11:59AM (#38795489)
NPM is a worse idea than Joe's as Joe was talking about a single community vetted monorepo. Not a free for all of individual repos.

With Joe's idea everything is up front and part of the language and not a bulletin board of packages near the checkout line at the git supermarket. This way simple stuff like isint() can make its way into the languages official standard library. This should eliminate the uncertainty of 3rd party packages maintained by a random number of individuals that can be taken down or tainted at any time.

Re:4B If Statements by remexre on Thursday December 28, 2023 @10:18PM (#38801440)
I wonder if it might be practical to bootstrap such a thing off of Wikifunctions, with a process to vouch for a function as "important enough to merit inclusion" and tooling to ensure that the Wikifunctions implementations actually agree, plus something to synthesize/translate a first-pass implementation in the desired language?
Re:4B If Statements by AQuantized on Thursday December 28, 2023 @06:45AM (#38792489)
To be fair, for all its pitfalls, NPM does provide a limited version of that idea to millions of codebases.
Re:4B If Statements by ksherlock on Thursday December 28, 2023 @11:02AM (#38794760)
This Joe Armstrong quote sums up NPM:

"You wanted a banana but what you got was a gorilla holding the banana and the entire jungle."

(originally on object oriented programming)

Re:4B If Statements by lbruder on Friday December 29, 2023 @08:17AM (#38804550)
the idea sounds great, but there would have to be something in place to prevent it from degrading into a Wikipedia-style turf war, with people trying to protect "their" code against changes...
Re:4B If Statements by mickael-kerjean on Thursday December 28, 2023 @05:41AM (#38792082)
I did a nullll package [1] whose only purpose is to export a null and takes 400MB in memory but somehow it got flagged in HN [2]. With 41 stars on github and 100% test coverage [3], it was clearly production ready.

[1]: https://github.com/mickael-kerjean/nulll

[2]: https://news.ycombinator.com/item?id=17072675

[3]: https://github.com/mickael-kerjean/nulll/blob/master/test.js

Re:4B If Statements by lvncelot on Thursday December 28, 2023 @06:12AM (#38792260)
That try-catch block[1] is a thing of beauty.

[1] https://github.com/mickael-kerjean/nulll/blob/master/index.j...

Re:4B If Statements by tiagod on Thursday December 28, 2023 @06:36AM (#38792428)
Shame it was flagged. Would've been handy for a project I was working on. Had to work around not having a performant null
Re:4B If Statements by divbzero on Thursday December 28, 2023 @06:12AM (#38792262)
Amazingly, following “don’t repeat yourself” in its purest form, is-even depends on is-odd:

  /*!
   * is-even <https://github.com/jonschlinkert/is-even>
   *
   * Copyright (c) 2015, 2017, Jon Schlinkert.
   * Released under the MIT License.
   */

  'use strict';
  
  var isOdd = require('is-odd');
  
  module.exports = function isEven(i) {
    return !isOdd(i);
  };
Re:4B If Statements by goalieca on Thursday December 28, 2023 @08:55AM (#38793488)
If this code runs on hundreds of millions of phones and computers, npm seems horrible for the environment! Not only because of runtime, but because we’re talking so much just to host and serve these modules!
Re:4B If Statements by fritzo on Thursday December 28, 2023 @12:19PM (#38795744)
These packages are performance art, and shall not be judged by efficiency metrics.
Re:4B If Statements by darkwater on Thursday December 28, 2023 @12:55PM (#38796215)
I bet a dollar you started writing "performance" and then rewrote it as "efficiency" :)
Re:4B If Statements by fritzo on Thursday December 28, 2023 @01:50PM (#38797025)
Good guess, but sorry :) You can pay at https://github.com/sponsors/fritzo?frequency=one-time
Re:4B If Statements by asylteltine on Thursday December 28, 2023 @12:09PM (#38795614)
That’s right. Npm and the entire node ecosystem is just terrible. Specifically because you can get a production ready package from even Google, and you know it’s going to have some random useless package in the chain somewhere.
Re:4B If Statements by jrpelkonen on Thursday December 28, 2023 @06:18AM (#38792296)
Implementing the comparisons by hand seems difficult and primitive. May I suggest introducing some helpful sub-packages and building the solution on top of those. For instance, is-odd would be implemented by using is-one, is-three, is-five, is-seven, etc.
Re:4B If Statements by leeoniya on Thursday December 28, 2023 @06:21AM (#38792317)
and is-one should be implemented by negating is-two, is-three, and so forth
Re:4B If Statements by paddy_m on Thursday December 28, 2023 @08:00AM (#38793052)
I read some text where a cheme was implemented such that numbers were `2 = 1+1`, `3 = 2+ 1`...
Re:4B If Statements by jcparkyn on Thursday December 28, 2023 @08:19AM (#38793173)
Re:4B If Statements by ta8903 on Thursday December 28, 2023 @10:41AM (#38794494)
>Succ Peano

...

Re:4B If Statements by remexre on Thursday December 28, 2023 @10:13PM (#38801417)
The standard joke about my university's grad-level programming languages course is that its formalization unit does a great job of identifying undergrads by discussing Peano naturals and Hoare logic in the same lecture...
Re:4B If Statements by jbboehr on Thursday December 28, 2023 @03:44PM (#38798352)
Perhaps Nock:

https://developers.urbit.org/reference/nock/definition

> The reader might wonder how an interpreter whose only arithmetic operation is increment can ever be practical.

> The short answer is that a Nock interpreter doesn't have to use the algorithm above. It just has to get the same result as the algorithm above.

Re:4B If Statements by avinassh on Thursday December 28, 2023 @08:01AM (#38793062)
I did something similar six years ago called gg-flip for npm - https://github.com/avinassh/gg-flip

It was submitted in HN too - https://news.ycombinator.com/item?id=16194932

Re:4B If Statements by jgalt212 on Thursday December 28, 2023 @08:25AM (#38793227)
I'd fire someone who imported those packages.
Re:4B If Statements by atleta on Thursday December 28, 2023 @08:39AM (#38793355)
I haven't heard about him but checking the source tree of our 2 front-end apps and his 'is-number' package (which his is-odd depends on), seems to be imported by quite a few other packages.

Now looking at the source, that package may make sense if figuring out whether something is a number type in JS is really that cumbersome. (Though I'd expect that there is a more generic package that covers the other built-in types as well.)

Also since isNumber treats strings that can be converted to a number, a number, it can yield weird results since adding two strings will naturally just concatenate them. So e.g.:

    const a = '1'; 
    isNumber(a); // returns true
    const b = a + a; // Now you have a string in b: '11'

Of course, it's standard JS stupidity (and 2*a would be 2, and 1+'1' and '1'+1 would both be '11'), but then maybe stating that '1' is a number is not the right response. However, the package was downloaded 46 million times last week and that seems to be so low only because of Christmas. The previous weeks averaged around 70M. And most of these are dependencies, like in our projects, I'm sure.
Re:4B If Statements by geodel on Thursday December 28, 2023 @11:10AM (#38794866)
Big fan of code reuse. Small packages providing single unique functionality is the way to program modern systems. It has to be right if bright minds in NPM / Rust community follow this approach.
Re:4B If Statements by ape4 on Thursday December 28, 2023 @12:20PM (#38795748)
I was wondering what the code looked like...

    'use strict';
    
    const isNumber = require('is-number');
    
    module.exports = function isOdd(value) {
      const n = Math.abs(value);
      if (!isNumber(n)) {
        throw new TypeError('expected a number');
      }
      if (!Number.isInteger(n)) {
        throw new Error('expected an integer');
      }
      if (!Number.isSafeInteger(n)) {
        throw new Error('value exceeds maximum safe integer');
      }
      return (n % 2) === 1;
    };
Re:4B If Statements by cchance on Thursday December 28, 2023 @12:21PM (#38795778)
I mean... when you look at it like that, at least it's got the error checking integrated as well... tho the fact it pulls in is-number is fucking hysterical lol
Re:4B If Statements by kparaju on Thursday December 28, 2023 @12:36PM (#38795960)
Re:4B If Statements by jkrubin on Thursday December 28, 2023 @12:27PM (#38795851)
Theoretically only one 40gb file would be needed. AFAICT almost every odd number is not even (I cannot say "all" bc I have not checked every integer yet).
Re:4B If Statements by blowski on Thursday December 28, 2023 @03:45PM (#38798360)
That's what unit tests are for, right?
Re:4B If Statements by dfee on Thursday December 28, 2023 @02:35PM (#38797566)
The implementation of is-even is mind blowing (numbing?).

    'use strict';
    
    var isOdd = require('is-odd');
    
    module.exports = function isEven(i) {
      return !isOdd(i);
    };
good thing it declares its dependencies properly!
Re:4B If Statements by xorvoid on Thursday December 28, 2023 @02:56PM (#38797854)
Even better if it built-on-install by executing another script to generate everything (naturally using %) New nerd game: enshitification inverse golf.
Re:4B If Statements by akoboldfrying on Thursday December 28, 2023 @07:14PM (#38800346)
Interesting that there are so many more weekly downloads for is-odd. This seems to suggest that there are many more odd numbers than even.

(Alternatively, perhaps odd numbers are actually much rarer, leading to them having a higher market value, and thus more interest in discovering them.)

Re:4B If Statements by Benjaminsen on Friday December 29, 2023 @01:55AM (#38802372)
The isEven package uses the isOdd package…
Re:4B If Statements by xstas1 on Friday December 29, 2023 @10:51PM (#38812686)
I wonder what will happen if the author of isOdd optimizes their code by using the isEven package