Wednesday, May 24th, 2006

Script# Prototype: Microsoft’s GWT

Category: .NET, Toolkit

Nikhil Kothari released a prototype of Script#, a toolkit that generates JavaScript code from C# code, similar to the recent Google Web Toolkit.

The fundamental goal was to improve the state of the art in scripting. This goes way beyond the usual things that come to mind at first thought: compile-time checking, and intellisense or statement completion. I do think these are super-useful, and would be valuable in and of themselves. As we worked on Atlas we were also thinking of a great tools experience, and we explored different approaches and technologies for achieving this. Script# is a prototype of one such exploration. It attempts to address some programming environment requirements:

  • A clean language with the natural constructs. Today with script, you can go a long ways in simulating OOP (classes, interfaces, inheritance etc.), but the simulations are thrown at the face of the developer. Various C# constructs such as properties, events, and syntax for defining inheritance go a long way in making the code readable. Similarly modifier keywords like public vs. protected vs. internal, sealed vs. virtual etc. help define a better object model. All of this can be brought into the scripting world.
  • Easier refactoring and exploration. Script development could benefit immensely from the refactoring, and class browsing support already present in the IDE and in tools such as .NET Reflector. Both lend themselves to having a more manageable code base over time.
  • Ability to generate documentation. Again doc-comments from C# and the existing infrastructure could be leveraged here.
  • Ability to customize the script code easily. For example, I’ll show debug vs. release and minimization below. The same idea could apply to building a version of the script that had more error checking or logging built in when you do need to run diagnostics. The approach could also be used to include instrumentation for the purposes of profiling, measuring code coverage, etc. Another interesting aspect of this project is that it will be able to generate script catering to multiple script profiles such as the current Javascript language, as well as Javascript 2 when it appears.

HelloWorld Code

  1. using System;
  2. using ScriptFX;
  3. using ScriptFX.UI;
  5. namespace HelloWorld {
  7.     public class HelloWorldScriptlet : IScriptlet {
  9.         private Button _okButton;
  10.         private TextBox _nameTextBox;
  11.         private Label _helloLabel;
  13.         private XMLHttpRequest _request;
  15.         public void Start() {
  16.             _okButton = new Button(Document.GetElementById("okButton"));
  17.             _nameTextBox = new TextBox(Document.GetElementById("nameTextBox"));
  18.             _helloLabel = new Label(Document.GetElementById("helloLabel"));
  20.             _okButton.Click += new EventHandler(OnOKButtonClick);
  21.         }
  23.         private void OnOKButtonClick(object sender, EventArgs e) {
  24.             Callback completedCallback = new Callback(this.OnRequestComplete);
  26.             _request = new XMLHttpRequest();
  27.             _request.Onreadystatechange = Delegate.Unwrap(completedCallback);
  28.             _request.Open("GET", "Hello.axd?name=" + _nameTextBox.Text, /* async */ true);
  29.             _request.Send(null);
  30.         }
  32.         private void OnRequestComplete() {
  33.             if (_request.ReadyState == 4) {
  34.                 _request.Onreadystatechange = null;
  36.                 string greeting = _request.ResponseText;
  37.                 _helloLabel.Text = greeting;
  38.             }
  39.         }
  40.     }
  41. }

Posted by Dion Almaer at 8:57 am

3.6 rating from 39 votes


Comments feed TrackBack URI

BTW. The last couple of comments I’ve submitted to your site has produced an error page with this message: ” The server closed the connection while reading the response. Contact your system administrator.”

Problems with your Ajax? ;-)

Comment by Dean Edwards — May 24, 2006

if only they supported the lambda functions that C# 3 supports :) that would be insanely sexy

Comment by Allen — May 24, 2006

It’s pretty cool. There are some differences with GWT: first, the generated code is way cleaner and second, Script# doesn’t have the concept of a hosted mode (you can’t run and debug the C# code, although this probably could be added).

Comment by Julien Couvreur — May 24, 2006

A lot of shit, seems like peoble are scary with JS..

Comment by JaViS — May 24, 2006

James Tauber releases an early version in Python language too: Primitive Python Version of GWT Working

Comment by Denstone — May 24, 2006

This tool is no more useful than the Google Java-to-Javascript compiler, as it also does not offer source code for the compiler.

Comment by Average Ajax — May 24, 2006

I agree both hands with Glazkov. Why all they want to hide JavaScript from developer? Is there something to be shamed about?
Note that not only the term Script# mimics C# (and J#), but also namespace ScriptFX (used in generated script) mimics WinFX. I wonder whether it has additional meaning.
The phrase from Some historical context… section:
“I was planning on posting an announcement just last week. It’s very coincidental that the folks at Google have been thinking along similar lines. I guess I should have posted this stuff a few days back :-)”
is my favorite.

Comment by Krzysztof — May 24, 2006

And why not JScript.NET?

Interesting times! Scripting languages go to server-side because they boost productivity; statically-typed languages are used to write browser applications because scripting languages slow down development (no code completion, hard to debug)… JavaScript is to be replaced by JAVA(Script) with all of these JS2.0 features… XForms are abandoned and Ajax UI toolkits emerging. RIA is a buzzword, but no one see that .NET CLR is already at every user machine with IE, and JRE is almost with every user machine… And there are IE HTC and Mozilla XUL that are used only by Dean Edwards to make Mozilla looks more like IE6.0 and to make IE6.0 looks more like Mozilla ;)

Comment by Valery Silaev — May 26, 2006

[…] Script# Prototype: Microsoft s GWTNikhil Kothari released a prototype of Script#, a toolkit that generates JavaScript code from C# code, similar to the recent Google Web Toolkit. The fundamental goal was to improve the state of the art in scripting. … […]

Pingback by Microsoft to Buy Third Screen Media?Wow - Carlo at MobHappy -- Centplus Tech Blog — May 26, 2006

I dont think that anyone is ashamed of Javascript. The point is to make it more accessible and easier to develop by the masses of web developers who are not gurus in Javascript. The tools will generate Javascript eventually and can be good sources of learning. Dismissing tools like this (GWT or Script#) is akin to dismissing IDE’s completely and saying that we should all develop in notepad or vi. No one is forcing anyone to use these tools anyway.

Comment by Benjy — May 31, 2006

oh. it seems like Script# exists on the net for year… but I got to know about that yesterday :(

Comment by Michael Sync — October 18, 2007

Leave a comment

You must be logged in to post a comment.