4 ms·
I wonder why nobody has created a version of JavaScript that just throws exceptions for all the WTF cases? That is, it would basically be a mode like 'use stri
by chubot 9y ago
I wonder why nobody has created a version of JavaScript that just throws exceptions for all the WTF cases? That is, it would basically be a mode like 'use strict-at-runtime'; .
This would be incompatible, but it would be a useful development aid. Surely most frameworks like React and Angular avoid these corners of the language, and they could be trivially modified to run on such an interpreter? It would improve their code quality.
I know this would be a large amount of work, but it doesn't seem that huge compared to all the other JavaScript infrastructure out there (parsers, transpilers, etc.). There are more independent JavaScript interpreters written than interpreters of any other language, AFAICT. At least before ES6, writing a JS interpreter was a one-talented-person project, not a huge team project like a JIT.
I guess one reason is that the DOM and node.js bindings aren't easy to reproduce. But I would think people still run their unit tests in a limited environment and it would be useful for some code. It could even be based on narcissus -- JavaScript in JavaScript?
- baddox 9y agoI think the most common way to accomplish that idea is to run a linter. Linters should be able to statically catch most of the unsafe operations you're probably describing.
- chubot 9y agoYeah, that's probably true -- linters do an OK job at attacking this problem. But then there are still people complaining about JS semantics... I think there is a gulf between what tools professional JS programmers use, and what tools X programmers use when they write JavaScript, where X != JavaScript.
- baddox 9y agoI think most JS fans these days recognize the inherent problems with JS, and work around them with best practices (on the lenient side) or linters and more advanced preprocessors like type checkers (on the strict side). At the end of the day, by far the main advantage of JS is the fact that there are mature and reliably-updated implementations with a relatively easy and open distribution platform on virtually every modern computing device (browsers and the World Wide Web). Some of the other fundamentals of the language are nice (particularly first-class functions), while the bad fundamentals (particularly the hopelessly messy type coercion) are now well-recognized and hopefully avoided through various techniques.
- erokar 9y agoProbably because the WTF cases are exaggerated. After a couple of months coding JS you will know it well enough so it doesn't bite you. It really is a non-issue for people who work with it daily.
- chubot 9y agoI agree it might not be an issue for professional programmers, given the right tools. But there are plenty of people who would recommend Python over JS as a first programming language for exactly this reason. Python gives better error messages and has fewer WTFs. I think JS could be a good teaching language if it were not for the confusion over types, which is an important thing for a beginning programmer to understand.
- wldcordeiro 9y agoTypeScript, Flow? That's kind of what you're asking for.
- always_good 9y agoActually just basic linting.
- tomatsu 9y ago> why nobody has created a version of JavaScript that just throws exceptions for all the WTF cases? Google experimented with something they called "strong mode". Classes were read-only, accessing nonexistent properties was an error, and things like that. I liked it. Unfortunately, the experiment didn't go anywhere and strong mode was removed from Chrome. Dart is somewhat similar, though. It got more straightforward semantics than JS and most of those WTF things are an error.
- scottmf 9y agohttps://github.com/eslint/eslint https://github.com/eslint/eslint