Javascript vs. Actionscript 3

A lot of people disparage Actionscript 3 as a dying or dead language, and heap scorn upon it. However, this is really just a smear campaign started by the sometimes mean-spirited Steve Jobs. Javascript is almost a perfect copy of Actionscript 2, and one by one the JS team has been adding in the missing features that Actionscript 3 added.  One of the most important features added in ES2015 is the module system, and now you can import from different modules, and keep your namespaces separate. Interchangeable parts is one of the two super important features of the next generation of software technology, and modules are essential.

However, I just found an unbelievable JS bug that is on Safari and Chrome. If you are writing some JS, so look out for this one:

lets say you have a standard library module and it defines some functions and constants. But FOOBAR isn’t one of them.

import * as std from './stdlib.js’; 
let z1 = FOOBAR; // compiler finds this error, FOOBAR the local name is not defined yet 
let z2 = std.FOOBAR; // this is a valid module name, but not a known symbol inside the module std, compiler lets it slide 
let z3 = stx.FOOBAR; // compiler catches this error, module name was misspelled.

If you make a typographical error and import a symbol that doesn’t exist, perhaps because you made a small spelling error, the compiler doesn’t catch the undefined name, and treats it like a property that doesn’t exist, which it is not. They forgot that a module name prefix is not an object, and that all imported symbols must be found.

This is a massive error in both Chrome and Safari, i can’t believe they didn’t catch this. It is most unfortunate that the folks at Google and Apple didn’t spend more time with Ada or Modula-2, which not only had modules but separately compilable modules, something that JS doesn’t have. Frankly you cannot have interchangeable parts without separate compilation. I wonder how progressive web apps are going to work completely without addressing some of these issues.

This makes modules incredibly dangerous compared to one big glob of code. The whole point of modules is to split namespaces so you don’t accidentally use a variable that isn’t part of your region of code, so this is tantamount to sabotage of the module system.

This is yet another reason why Javascript is such a piece of crap. The fact that they have't figured this out in 3 years since 2015 goes to show how poorly thought out and implement JS is, and i an many others can't wait for the day when we bury that language!

Writing in Actionscript 3 you get a very solid compiler and toolchain, and AS3 and JS are so close now, you can convert one to the other with mostly just a series of find/replace operations in a text editor. Instead of using TypeScript, i suggest you try Actionscript 3 which retains the type information at runtime, and use AS3 for your mobile and desktop targets, and then convert to JS using a simple script to run in the web. This way you get good protection. TypeScript can't carry the checks into runtime.