I've been playing around tonight with Nikhil Korthari's new Script# language plug in and I think for the first time am seeing the light at the end of the tunnel here. What this tool does is take compiled C# code using specialized .NET libraries that describe the capabilities available and crank out browser independent JavaScript code in the form of a class.
It's a shame that this so closely follows Google's release of their Google Ajax Toolkit which takes a similar approach of using Java code to generate JavaScript and will invariably have some people screaming – rip off. Still I think this is a cool idea that provides some really interesting possibilities especially in light of ATLAS for the future.
Nikhil's stuff is pretty raw at this point and it doesn't have a lot of functionality (and some odd behaviors like renaming your members to enforce JavaScript naming conventions?), but I played around with a few basic scenarios that deal with making some remote XmlHttp calls and retrieving validation data and returning the results back. It works beautifully and it's quick and easy to write code. You get Intellisense on the C# code you generate and the compiler does compile time type checking to verify typesafety and other syntactical errors. The compiler generates an assembly and a .JS file, but the actual JavaScript is loaded at runtime through assembly resources. A server control library provides the support services that makes the generated JavaScript type(s) available to your page and handles loading the script resources both for your generated code and the core library which looks at the moment to be a small subset of the ATLAS runtime.
Now before you get too excited – no, you don't get the idea that the CLR is running on the client. So no, you can't start running Windows Forms like code in the browser. Instead this mechanism basically maps JavaScript and DOM functionality to a couple of .NET assemblies that provide the core logic you can code against it with C#. It's a very limited subset of C# no doubt, but it's C# and provides Intellisense and compile time error checking. The compiler turns the code into .NET IL code and part of the compile process then parses that IL code into JavaScript.
Right now there's not a lot there – a couple of basic controls (TextBox, Label, Button) and an XmlHttp object so you can make easy AJAX callbacks. What's also there is the ATLAS like extender functionality, where you assign a standard DOM control to a 'framework' control that provides the core functionality. If you want to find out more check out Nikhil's Post that shows both the C# and generated JavaScript and walks you through the mechanics of the process. It's straight forward. I was able to get everything up and running with my own class in a few minutes...
What does it mean?
I'm still mulling around the implications of this in mind, but I think I see where this is heading and I like where it might be going (if I'm right). It looks to me like this sort of script implementation provides a powerful abstraction layer that is needed somewhere in the Microsoft ATLAS stack anyway.
To date this abstraction layer has been XmlScript which is embedded on the client side. If you've been following some of my thoughts on ATLAS a while back you probably know that I was rather put off by the XmlScript syntax which is unintuitive and to 'scattered' where too many choices need to be made in different seemingly unrelated places. Xml and markup are just bad choices for describing behavior in my opinion at least in human usable form (a designer or generator might help but that's not happening now).
Well, let's back up and think about an abstraction layer built using this script engine using this sort of Script# or similar technology! You can now write your code using compiled C# that runs against runs against specialized libraries – in this case the ATLAS client and Server libraries. The libaries now become the abstraction layer that can parse the syntax the actual user sees into what the underlying JavaScript code or libraries require – namely the fairly complex AJAX client side BCL wanna be implementation <g>.
All components consist of some client library code (just like we have now with all the Atlas Component implementations) and .NET assembly implementations of those same components to provide the mappings for compilation. The .NET code is basically a façade for the JavaScript libraries.
I think THAT right there is something that has tremendous value. With something like this it becomes possible to build a fairly complex library and expose it through the much more accessible interface of a .NET library with full Intellisense support and compilation safety and still have good usability of it out of the box, which seems to be the biggest problem we face with ATLAS at the moment. It also will let ATLAS get away with working without extensive new tool support – these components don't require a full new designer etc. merely some add-in components for Visual Studio. It seems like a big win situation.
It'll be interesting to see where Microsoft takes this if anywhere. Right now it's Nikhil's pet project. Nikhil seems to be a one man show over at Microsoft to crank out tools that rock the MS boat. Cheers to you Nikhil, keep it coming!