(JS) is simply amazing. People invent all kinds of nifty tools and
extensions. But with that comes fragmentation and the proliferation of
JS frameworks has turned JS into an assembly of incompatible
sub-languages. In contrast, Java has standardized the following six
things and JS should do the same. After listing them, this post points
out consequences and future developments.
- Standardized inheritance: Java has acceptable inheritance built into the language (although primitives are a nuisance and traits or mixins would be nice). In JS, if you want to do inheritance, getting by with just the language is painful. Thankfully it is easy to extend it and that lead to some very nice inheritance APIs. But there are simply too many of them.
- Standardized modules (packages): Similarly to inheritance, JS can be extended easily, but there is no common standard. CommonJS might find some mid-term traction, though.
- Standardized type information: I am not using the term “type annotations”, in order to avoid confusion with Java’s annotations. Having type information is natural in Java, because it is statically typed. JS is a more dynamic language and does not strictly need it. However, many APIs do include types as comments or in external specs. For example, Mozilla uses Web IDL in specs such as the IndexedDB API. It would be nice to have the standardized option for adding this kind of information so that tools have something to work with. Static analysis, e.g. done via DoctorJS, can infer many types, but I would still often add this information explicitly.
- Standardized API comments: Java has JavaDoc, JS has several competing standards.
- Standardized unit testing: JUnit is the dominant standard for unit testing in Java, while almost every JS framework comes with its own implementation.
- Standardized runtime library: While Java’s runtime library is not perfect, having it is great. JS should have more standardized APIs and save JS frameworks from reinventing the wheel.
Which of the above points present long-term problems? I expect (1) and (2) to eventually become language features, but it would still be nice if everyone could agree on standards until then. (3) might make it as type guards into JS Harmony. (4), (5) and (6) can only be tackled via standardization.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)