Hacker News new | ask | show | jobs
by uncleyo 1838 days ago
I wonder if JS could benefit from a system similar to Rust editions (https://doc.rust-lang.org/edition-guide/introduction.html). Requiring assertion like "This code was written in 2021, no MooTools here" seems like a reasonable ask to access new features in the standard library.

I know it may sound similar to what X-UA-Compatible did, but that was really horribly implemented and vendor specific...

2 comments

That sounds more like Python's from future import behaviour.

What Rust does about this specific problem is that nobody else gets to mess with your stuff. For the exceptional case of the built-in types the core and I believe also std (the standard library) are allowed to define things for those types but nobody else can.

So you can't add an is_stupid() const boolean method for the char built-in that classifies Unicode scalar values by whether they are (in your opinion) stupid or not.

You could invent your own trait named Stupid with the is_stupid() method, and you can implement that trait on the built-in char type, but only people who explicitly want your Stupid trait get this behaviour. They aren't infected just by happening to use some other features you implemented.

I think something like this was proposed actually, but was thought to potentially fragment the web too much.

I wonder if it would also mean an inherently more complex runtime with correspondingly complex debugging. At the moment you have a single JS environment you run and debug in. If we began tiering it by versions, what would that look like for day to day development? You’d no longer track just browsers but versions of JS running in each.