2 ms·
I see why this seems like a reasonable thing to ask for, but JS engines tried this and failed hard a few years ago. Google's V8 team (the team that owns Google
by dfabulich 5y ago
I see why this seems like a reasonable thing to ask for, but JS engines tried this and failed hard a few years ago.
Google's V8 team (the team that owns Google Chrome's JS engine implementation) floated a proposal back in 2015 to implement a new JS mode that they called "Strong Mode."
https://docs.google.com/document/d/1Qk0qC4s_XNCLemj42FqfsRLp49nDQMZ1y7fwf5YjaI4/view https://docs.google.com/document/d/1Qk0qC4s_XNCLemj42FqfsRLp...
The idea was that you'd opt-in with a pragma like "use strict", but this time you'd "use strong". Strong mode would include a bunch of restrictions on how you'd write your JS. For example:
- class prototypes would be frozen; it would be forbidden to add properties at runtime, or to `delete` properties from a class
- The "new" keyword would automatically Object.seal() the object
- Arrays are non-sparse
Here's Google's 2016 announcement canceling the "strong mode" experiment.
https://groups.google.com/g/strengthen-js/c/ojj3TDxbHpQ https://groups.google.com/g/strengthen-js/c/ojj3TDxbHpQ
> The main problem here was the interoperability with weak classes: we need to allow inheriting strong from weak classes and vice versa (or even alternating inheritance chains), because ruling that out would severely limit the utility of strong mode. But we could not find a semantics that would work without breaking either weak parent classes or weak child classes. In the end we had to give up on this one.
There were other problems, too, some of which are substantially mitigated now in 2022. Maybe it's worth a try now!
…but if you're hoping to hold up type comments until "strong mode" works, well, I just don't think it's gonna work.
And so, in practice, for the next five to ten years, we're either getting something pretty much like Microsoft's "type comments" proposal, or nothing at all.
- eyelidlessness 5y ago> but if you're hoping to hold up type comments until "strong mode" works, well, I just don't think it's gonna work. I personally don’t want runtime type checking anyway[0]. Apart from my concerns[1], most of which are fairly navel gazey, I support the type comments proposal almost exactly as is. My hope is that if others are successful asking for runtime type checking, they’re also asking for the corresponding performance problems to be addressed in tandem. 0: We already have runtime type checking: type guards. They have the advantage of being optional and explicit, which addresses performance concerns better than anything else I can think of. 1: https://news.ycombinator.com/item?id=30621120 https://news.ycombinator.com/item?id=30621120