JavaScript As A Real Programming Language

I’ve long talked trash about JavaScript (why use Java-like syntax for a scripting language? why not use one of the myriad other existing, stable, fast scripting languages?), but necessity has forced me to take a second look, and I’m finding a fairly reasonable, capable programming language in JavaScript.

In the Web 1.0 days you had behavior on the server, presentation on the browser. HTML was easy enough for anybody to pick up, Web sites were ugly, and interactivity on the client (browser) was minimal. In short, it was heaven.

Today’s Web is different. It’s client-server, where the client can be, and often should be, sophisticated. The client manages state and has programmatic behavior, just like a desktop app, but is written in CSS and JavaScript.

That, to a back-end guy like me, is bad news.

The good news is that JavaScript is not nearly as bad as originally thought. Most people (myself included) don’t ever learn it – they just pick up enough to hack together a widget or two and get a terrible impression of the language.

It is a bit of an odd language. There are various inconsistencies and syntax aberrations. It can’t decide if it’s class based or prototype based.

But it has lots of niceties: functions are first class objects. Arrays and Hashes (both of which are actually just Objects) are capable and behave as you’d want them to in a scripting language (allowed mixed types, etc). Closures are not only supported (ooh, aaah), but are an important part of how you use the language.

Sure, I’d take any of the other popular scripting languages over JavaScript any day, but JavaScript is the de-facto language for Web clients, so it is necessary to learn it. If you’re going to learn it, approach it as an actual programming language, as opposed to something you can hack DOM with, and you’ll be much happier. Simon Wilison’s “A Re-Introduction to JavaScript” is a wonderfully complete yet concise introduction, and he recommends a few books for further study.

I just noticed James Bennet’s JavaScript Knowledge Gap post that talks to some of the same issues. He brings up some excellent points, including yet a further reason to learn JavaScript: it’s a ludicrously widely-deployed language.

1 Comment so far

  1. Pooya on February 22nd, 2007

    Who would’ve though Javascript was actually a real language and pretty simple too, the naming certainly doesn’t help. I’ll second the reccomendation of “A Re-introduction to Javascript”, there should be an intro like this for every programming language.

Leave a Reply