News for hackers. Stuff that matters.
Re:How Python virtual environments work by Nadya on Monday March 13, 2023 @07:19PM (#35144635)
Weirdness? `require` was Node weirdness because Javascript lacked imports/exports at the time. The ES6 syntax is remarkably better, allows imports to be async, and doesn't need to run the code to see what should be assigned to `module.exports` allowing it to be statically analyzed which allows tree-shaking. Node's CJS syntax will only work for Node requiring that you transpile and bundle it for browsers. The ES6 syntax will work for Node and the browser.

I see anyone sticking with CJS syntax the same way I see Python devs who continue writing 2.7 code by choice in new projects and not because they are maintaining older projects.

Re:How Python virtual environments work by hot_gril on Monday March 13, 2023 @07:37PM (#35144876)
I call `import` weird because there are several different ways to do the same thing, listed at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... and summarized under "there are four forms of import declarations." Four! And I always forget the different ways they work.

Sure tree-shaking and browser support are nice, but they didn't have to make the syntax this complicated to achieve that. Not an issue with other languages.

Re:How Python virtual environments work by Nadya on Monday March 13, 2023 @09:39PM (#35146172)
* * *
Re:How Python virtual environments work by hot_gril on Monday March 13, 2023 @11:38PM (#35147134)
Your explanation makes sense, but imo the import syntax shouldn't even require (no pun intended) an explanation.

The bigger thing is, I'm subject to however the deps I use want to export things, so they use a mix of those. Maybe in some cases you have to use `require` even if you don't want to, I forget.