A few posts back I wrote about the Google Web Toolkit, which allows you to code in java, compile it and generate JS code from it. Cool in itself, but now I found something I like even better: Script#. In a way it’s the same as GWT, but with one big difference: you code in C#. Which means you can use Visual Studio. From the website:

Essentially the Script# compiler is a C# compiler that generates Javascript instead of IL. A key driving goal of the design is to produce readable Javascript that you may have authored yourself, and would be ok deploying into real apps. Hence the translation works at the C# level, as opposed to converting from IL to script, and the converter doesn’t add any levels of abstraction itself.

There are a set of C# things that don’t make sense (eg. lock, unsafe etc.) and set of things I don’t support yet (like generics). The converter does however provide support for key C# patterns such as foreach, delegates, and things like Debug conditionals. The associated class library (sscorlib, equivalent of mscorlib) is also tuned to Javascript. It doesn’t contain the same stuff as mscorlib does. The approach I have taken is not to create a converter that converts an arbitrary existing application written in C#, and convert it to Javascript with something like a winforms abstraction layer. Instead, like Atlas, the idea behind Script# is oriented at providing an engineering approach and superior environment to developing applications using HTML/CSS and Javascript in a more productive, scalable and maintainable manner.

There is a small set of Javascript specific things (specifically closures and more functional style programming) that aren’t supported in the conversion. I think there are equivalent alternatives, but I’d be interested in feedback nonetheless. The implementation does allow you to hand-code some Javascript and expose it to the C# code in the form of assembly metadata. This provides a nice out for incorporating something that exists already, or something that needs more hand tuning.

It’s cool. Have to check it out. Download it at: http://www.nikhilk.net/Content/Samples/ScriptSharp.zip

Technorati Tags: ,