Compiling to JavaScript: TypeScript vs. Haxe
lars_doucet writes: Released in 2012, Microsoft's TypeScript is perhaps the best-known "compile to JS" language, but it wasn't the first. One of the earliest was Haxe, whose JS target first appeared in 2006. In his illuminating article, TypeScript vs Haxe, Andy Li gives an excellent rundown of the two languages' various merits, but the bottom line is: "Existing JS developers will favor TypeScript as they are more similar in many ways. They can utilize their existing skills immediately. Non-JS developers with backgrounds like Java/C# or even from the functional programming world will appreciate Haxe more since it fixes a lot of weirdness of JS." The full article includes an excellent rundown of the type systems, syntax, scope handling, compilers, and overall language design philosophy.
Compiling to JS is like having a shit for dinner, you're doing it wrong.
How is that web assembly project coming along? It seems like a perfect fit for alternative languages like this instead of having to compile to JS. I think it will be a nice day when developers can choose a web language based on its merits rather than its ubiquitous nature.
Irony: Agile development has too much intertia to be abandoned now.
If I had to compile to JS I like to think I could use emscripten, but not being involved in such a project I'm not sure how well it works. When it's supported by the browser, it's designed to strip away most of the layers of crap we've put between ourselves and the machine. IIRC, you can get half the speed of native C by running C compiled to JS this way. Once again though, the browser has to support it. I think in theory it can support any language that LLVM supports on the front end; but I think they've only tested it with C and C++.
Anyway, if you're starting a new project I don't see why you'd want to use a language designed just for compiling to JS when you could use something more general purpose that will potentially run very fast with the proper compiler.
For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
Haxe isn't very high-profile, but Typescript is an important language, if only for the fact that it is starting to drive the design of ECMAScript. Typescript has recently become a strict superset of ECMAScript functionality, and Typescript has become the new testing ground for features before they get incorporated into ECMAScript. (This may not always be true, because Typescript is developed by Microsoft, but it seems to be true at least for now. You know to sit up and start paying attention when Google decides to rebase one of their strategic platforms -- Angular -- on a Microsoft technology.)
Um, I know that ECMAScript "IS" Javascript. Typescript is becoming much bigger than Microsoft itself. The only Microsoft products I have ever been interested in using before Typescript are their keyboards and mice. Typescript is, quite shockingly, actually really, really good, and Microsoft, even more shockingly, is suddenly becoming a really good citizen in the open source / Free software world, at least as far as some projects are concerned, and the stuff they're putting out there is really good. (See also: Visual Studio Code.)
Microsoft have also, quite suddenly and inexplicably, become extremely open about the development process of some of these newer open source projects, and they are working with, and responding to, other key players in the open source ecosystem. (Google adopted Typescript for Angular2, and Microsoft merged Angular's "AtScript" extensions into Typescript, and made Typescript a strict superset of ECMAScript 7, in order to satisfy Google's requirements, and to make Typescript a better player in the Javascript world. Microsoft was a key presenter at, and participant in, ng-conf 2015. etc. etc.
There are also PureScript, Scala.js and of course ClojureScript.
I know this is going to get a lot of hate, but JavaScript is really not as bad as people make out. There are some stupid design decisions (mostly around scoping and built-in type consistency) but once you know what these are it is pretty easy to work with them. The main problem I think most people have is that it does not really offer any sort of hand-holding in terms of how you should structure your program. But in a way it is quite beautiful how you can create usable frameworks for OO, imperative, or functional programming with the same language. The problem I mostly see is that people get stuck with a poor design decision, but rather than having to re-factor their object structure (like C# would force you to do), they can just hack in a solution that breaks basically every principle of good programming imaginable. They then dump this solution on the world and declare it is because JavaScript sucks. The real issue is that they are bad programmers who came up with a poor design and then used the (somewhat excessive) flexibility of JavaScript to get them out of a corner. Same thing has happened in C/C++ for years.
I really don't think JavaScript should have become the language of the web, but competent programmers shouldn't listen to all the hate that gets spread around. It is a decent way to introduce yourself to a lot of new programming concepts if you've come from a static OO language background. Once you understand some fundamentals CoffeeScript, TypeScript etc are pretty straight forward and their applicability is obvious.
For what it's worth, if you are doing large programs then something like TypeScript can be very useful. The problem it solves is really an issue with dynamic languages in general though, rather than JavaScript. There are ways to create large maintainable code bases with a dynamic prototypical language, but sometimes the classic OO model just fits a problem better.
If you think this is would be a good thing, try Nim, formerly known as Nimrod. Abstraction level between C and C++ and it compiles to JS. Apparently carries less runtime baggage than emscripten.