Script#: Write Your Javascript in C#
21-Feb-07
Javascript. A word that invokes feelings both marvelous and dreadful. On the one hand, it’s a powerful scripting language, and in modern browsers there’s a whole heckuva lot we can build with it. As far as the actual language goes, though, there’s lots to be desired. Utilizing OOP in Javascript is a pain in ass at best (remember prototype chains in Actionscript 1.0?), and language constructs are minimal - the lack of syntactic sugar in javascript could possibly be better called Syntactic Tabasco - it’s there, it’s hot, and it just doesn’t make things sweeter (yes, I do love Tabasco, but I don’t generally put it on my cupcakes, if you know what I mean).
Enter Nikhil Kothari’s Script# (that’s pronounced Script Sharp, for those of you who either aren’t musically inclined or live under a rock, take your pick).
Script# brings the C# development experience (programming and tooling) to the JavaScript/Ajax world.
The Script# compiler is a C# compiler that generates JavaScript as its output instead of IL. A key goal of the compiler to produce readable JavaScript (as if you had authored it by hand), and would be comfortable deploying into real apps. Hence the translation works from C# source directly into JavaScript without an intermediate IL layer. The compiler can also produce equivalent, but much more compact script for use in release mode deployment. The compiler does not introduce any additional levels of abstraction, thereby allowing you full control of what your application does. In essense the best of script with the best of C#!
I’m hoping to get a chance to play with this in the next little (short) while, but from what I’ve seen it’s pretty damned cool. Just having the compile step is pretty schweet - I’m a big fan of compiler errors over runtime errors, and runtime errors in Javascript are usually pretty painful (granted, that’s dependent on the browser, and there are lots of tools out there that make it better, but anyway…this is my blog, not yours - feel free to espouse “Notepad only Javascript development” on your own blog; for me, I’ll at the very least be using Notepad2).
And, of course, you already know I’m a big fan of C#.
Links:
Script# Project Page
Introduction to Script#
Script# and LINQ





She’s had a rough couple years.