Compilers. Compilers? (Message from the CTO, newsletter 52)

Just realized that I hadn’t put last week’s Message from the CTO up as a post. Maybe it was because I was so excited that we’d managed to record it as a video! (And, yes, there are now several videos in the pipeline…)

Compilers, compilers?

Back in the days of yore, pre-Internet, you knew where you stood with compilers. You'd write some code in some quasi-mathematical English, and then you'd let loose a compiler on it to produce a nice object file containing machine code that you then linked with other obj files into a program. Easy, huh?

That must have been some time ago -- I'm showing my age here -- because we've had interpreters for a while where the code gets compiled on the fly into macro instructions that a state machine can execute. We've even had compilers that produce some kind of intermediate language that gets executed by a run-time virtual machine, which is after all a glorified state machine.

But just recently I've been looking into another type of compiler altogether, one that compiles your code into another programming language. Because of my natural bent at the moment, I'm particularly interested in compilers that compile to JavaScript.

One example is Script# which compiles C# code written against a special run-time to the equivalent JavaScript code. The interesting thing about this one is the conversion of a strongly-typed language into a dynamic language.

That's possibly the most extreme case, however there's another that's just as powerful: CoffeeScript. What this one does is it abstracts out all the nasty things about JavaScript, adds a bunch of syntactic sugar, and compiles to very clean JavaScript. Companies like Google are now starting to add debugging information to the compiler output so that you can debug CoffeeScript directly.

I often hear that some people find it hard to write client-side code in JavaScript. I think we're getting to the point where it'll no longer be necessary. JavaScript is becoming the assembly language of the web: write in some high level language, compile to JavaScript, and deploy the files produced as part of your site.

You can watch the video here.

For fun, here’s the CoffeeScript code we showed in the video:

wrap = (originalHandler) ->
  (event, pos, item) ->
    if item
      dataPoint = item.series.data[item.dataIndex]
      originalHandler.call this, event, pos, item  if dataPoint[2]

It’s the equivalent of the last bit of code from this recent blog post of mine.

2 comment(s)

COBOL compilers and the original C++ compilers all did the same a long, long time ago... I think my age is also showing, and I'm only 35!!! (alright, I admit, my first computer had a Z-80 CPU with 32 KB available of memory... OLD!!!)

BTW, I simply can't love CoffeeScript more than I already do!

19 August, 2011

There are multiple Object Pascal projects working in this direction right now as well. Very interesting to track their progress. It's getting a little bewildering at how many ways there are to skin the proverbial cat nowadays...

19 August, 2011

Please login or register to post comments.