> I really think that the needs of server side code are different enough than the needs of client side code that we’re better off drawing from Python and Ruby than from Dojo and jQuery. This sentence sounds ok until Python and Ruby are held as the apparent gold standard of server development. That's not really the case, I think?
CommonJS is hurting JavaScript
51–60 of 134 posts
Re: CommonJS is hurting JavaScript
#52That's all well and good, but what about those of us that already have a mountain of Jest tests with mocks that aren't supported in ESM mode? https://github.com/jestjs/jest/issues/9430 I've definitely worked around my fair share of CommonJS issues but until ESM "just works" I'm slightly pained by how aggressive the tone of this article is.
Re: CommonJS is hurting JavaScript
#53Does anyone have a detailed understanding of why CommonJS (and its async incarnation, AMD) were not adopted by browsers? I do much like the `import` syntax personally and its a little cleaner to read, but CommonJS and AMD were the undisputed winners of the module format until ES Modules were born. Not that I have a problem with ES Modules, I don't, however I am interested in what was so insufficient about the precedi…
A bare-bones implementation of AMD could be put together with less than a kilobyte of JavaScript (this is what we used at Mozilla for a minute circa 2012). Meanwhile, the ECMAScript folks were working on ES6, which was going to have a module system. Why would the browser build in support for a highly-opinionated system that you could implement yourself so trivially, all while a TC39-blessed standard was in the works?
> what I "imagine" browsers doing with CommonJS is making the `require` calls async in the background (IE non visible to developers) so they can resolve the modules then parse the code
That's not possible. You need to run the code to know what's being required: if I call `require('./' + getModuleName())`, you don't know what's being required until `getModuleName()` is evaluated. So you actually need to start running the JS. You need to pause execution of the code calling `require()` (a la `alert()`), and then you can download and parse the required module. When the file is downloaded, you can parse and execute the imported module. Each file would need to be downloaded/parsed/executed _synchronously_ in the order that each `require()` happens in: it's only async in so far as the JS pauses execution and picks up later.
> This isn't terribly different from how import statements work today.
Not so. You can find and resolve `import` statements (note: not `import()` calls, though these return Promises) without executing a JS file. You can parse the imports out of a file in one pass and fetch/parse/repeat for each import in the dependency tree before anything starts executing. Since "native" imports are static and declarative, you can resolve all of them without ever executing any code. And any dynamic imports return promises that the programmer needs to explicitly handle the behavior of at runtime.
> just improve the existing format
1. You'd have to kill dynamic imports (passing anything other than a string literal to `require()`, which would be impossible to do without breaking compatibility and couldn't be polyfilled.
2. AMD allowed a callback syntax for `require()` (it came out years before promises), which is cumbersome. Adding promises later would be challenging and leave technical debt.
Re: CommonJS is hurting JavaScript
#54Re: CommonJS is hurting JavaScript
#55[flagged]
Every time this is mentioned, the person is heavily downvoted. But if you were here in the 2000, that's exactly what happened. In fact, this very article starts with "JavaScript, the undisputed king of web development, is being sabotaged — not by a rival language or a revolutionary new technology, but by its own baggage from the past.". That's the first sentence. Nobody wanted to work with JS, it was used to make sno…
Re: CommonJS is hurting JavaScript
#56[flagged]
Every time this is mentioned, the person is heavily downvoted. But if you were here in the 2000, that's exactly what happened. In fact, this very article starts with "JavaScript, the undisputed king of web development, is being sabotaged — not by a rival language or a revolutionary new technology, but by its own baggage from the past.". That's the first sentence. Nobody wanted to work with JS, it was used to make sno…
Re: CommonJS is hurting JavaScript
#57[flagged]
Every time this is mentioned, the person is heavily downvoted. But if you were here in the 2000, that's exactly what happened. In fact, this very article starts with "JavaScript, the undisputed king of web development, is being sabotaged — not by a rival language or a revolutionary new technology, but by its own baggage from the past.". That's the first sentence. Nobody wanted to work with JS, it was used to make sno…
Pleased to meet you! Isomorphic code bases are a case to use a single language, which before WASM, is Javascript & Typescript. I may prefer to use something different with WASM, which has even more interoperability than JS, becoming a bigger part of the ecosystem, but so far it would be Assemblyscript to more easily migrate my existing codebase. Assemblyscript has a Garbage Collector, so I may choose Rust or Zig if I don't want the GC. Rust probably has the most momentum, so despite the complexities, verbosity, & loss of productivity working with Rust, that may be a better choice when working with WASM. I would prefer Zig over Rust & Assemblyscript over both in cases of app development...but breadth & depth of the ecosystem matters.
I wouldn't touch PHP, Python, Ruby if I had a between using Typescript...as PHP, Python, & Ruby lack a decent static type system.
> Nobody wanted to work with JS, it was used to make snowflakes on your home page on Xmas at best.
I disagree. Javascript is a prototype based language, which provided opportunities for composition over inheritance. JS supported closures from it's beginning while other popular languages did not (well Ruby had limited support for closures). Inheritance & other OO concepts now considered harmful were prevalent with Java, C#, Ruby, Python, etc.
Sure, we could have used LISP instead, but for some reason LISP did not gain traction. JS was the closest programming to LISP which had popular appeal.
I suggest that JS changed the general programming ecosystem in profoundly positive ways & I, for one, preferred developing in JS over the other popular alternatives when I could.
To further bolster the case for JS, Typescript was built as an extension on top of JS, proving you can have the dynamic prototype based runtime with a powerful static type system.
Re: CommonJS is hurting JavaScript
#58I think there should be more praise on these guys for what they accomplished given the state of JavaScript when they started. They saw a problem and came up with a solution. Was it perfect? No, but it's not this abominable creation.
Much like John Resig's work on jQuery nudged JavaScript forward, so did the work on CommonJS/Node.
Re: CommonJS is hurting JavaScript
#59The problem with Javascript modules = Everyone will be forced to run a full web server to do anything (to handle CORS restrictions). We all lose the ability to simply have a local index.html file, and have it Just Work (TM): This ability is amazing for demos, fast iteration, onboarding new devs and developing without a ton of layers of js ecosystem machinery. Deno doesn't care about retaining this level of developer…
If you are same origin, you do not require CORS to use type=module. Also type=module works on HTML pages served from file:// (file:///.../index.html).
Re: CommonJS is hurting JavaScript
#60[flagged]
Every time this is mentioned, the person is heavily downvoted. But if you were here in the 2000, that's exactly what happened. In fact, this very article starts with "JavaScript, the undisputed king of web development, is being sabotaged — not by a rival language or a revolutionary new technology, but by its own baggage from the past.". That's the first sentence. Nobody wanted to work with JS, it was used to make sno…
I think the ecosystem needs love again, because outside of Fastify I feel like server side JavaScript that isn't targeting a Lambda or Cloudflare worker type environment is a little spare of good options.
That said, Fastify is pretty amazing, and if you use graphql the main GQL servers are usually Apollo (JS based) or GraphQL Yoga (Also JS based), and they're really good.
One area that intensive JavaScript needs work on though is Machine Learning / Scientific computing. `number`, `BigInt` and `Math` aren't enough here. We need more built-ins added to the language around this (particularly around `Math`) IMO