Wednesday, October 5, 2011

JavaScript, why?

I don’t understand why people like JavaScript. It’s like liking PHP. They’re gross languages that have horrible inherent limitations and are certainly not as easy to use (while still allowing complexity) as they should be.

JavaScript doesn’t even have an integer primitive. I don’t understand how one could possibly think that double-precision floating points are enough. They’re slow.

JavaScript converts hashmap (object) keys to strings. This makes them useless (and slow) as general purpose maps.

What’s up with the syntax? It’s like someone took C syntax and made it evil. Since 4. is a valid literal in C (and so it is in JavaScript too), you can’t do 4.toString(). Instead, you have to do 4..toString() or (4).toString() (though the former is preferred). But 4. isn’t even necessary, because 4 == 4. — all numbers are floats, unlike C, where 4. is a double and 4 is an integer.

Now, I don’t mind that JavaScript is similar to C in a few ways. That’s good. I also don’t mind the object model. It could be done better (see Lua), but as it is right now is definitely useable. I don’t mind Node.js, which seems to be quite popular — it’s great that people have an interest in evented/asynchronous programming. It’s an interesting area. Node isn’t the end-all solution though. It’s definitely far from perfect.

However, I’m not really a huge fan of dynamic typing. It’s easy, sure, but it’s also easy to miss bugs. I’m not a fan of C/++’s static typing either (though it was somewhat necessary at the time). Instead, a strong type inference system would be good, like Scala, Haskell, and many other languages (especially functional languages).

This would change JavaScript too much though. The object model, as it is, is not very compatible with a strong type inference system.

I think we need a replacement for JavaScript on the web. Better yet, how about some kind of bytecode JIT with a standard calling convention? A JavaScript compiler could then target this JIT. This would allow a large variety of languages to be used on the ‘net.

Anyway, there’s my rambling for the day.


Notes

  1. devyn posted this