Wednesday, May 24th, 2006
Script# Prototype: Microsoft’s GWT
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
-
-
using System;
-
using ScriptFX;
-
using ScriptFX.UI;
-
-
namespace HelloWorld {
-
-
public class HelloWorldScriptlet : IScriptlet {
-
-
private Button _okButton;
-
private TextBox _nameTextBox;
-
private Label _helloLabel;
-
-
private XMLHttpRequest _request;
-
-
public void Start() {
-
-
}
-
-
private void OnOKButtonClick(object sender, EventArgs e) {
-
-
_request.Onreadystatechange = Delegate.Unwrap(completedCallback);
-
_request.Open("GET", "Hello.axd?name=" + _nameTextBox.Text, /* async */ true);
-
_request.Send(null);
-
}
-
-
private void OnRequestComplete() {
-
if (_request.ReadyState == 4) {
-
_request.Onreadystatechange = null;
-
-
string greeting = _request.ResponseText;
-
_helloLabel.Text = greeting;
-
}
-
}
-
}
-
}
-













You guys discussed abstracting JavaScript away recently:
http://ajaxian.com/archives/google-web-toolkit-the-correct-level-of-abstraction
and Dimitri Glazkov sums up my opinion very well:
http://glazkov.com/archive/2006/05/23/TheAgonyofaThousandPuppies.aspx
BTW. The last couple of comments I’ve submitted to your site has produced an error page with this message: “[code=SERVER_RESPONSE_CLOSE] The server closed the connection while reading the response. Contact your system administrator.”
Problems with your Ajax? ;-)
if only they supported the lambda functions that C# 3 supports :) that would be insanely sexy
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).
A lot of shit, seems like peoble are scary with JS..
James Tauber releases an early version in Python language too: Primitive Python Version of GWT Working
This tool is no more useful than the Google Java-to-Javascript compiler, as it also does not offer source code for the compiler.
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.
Cheers,
:)))
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 ;)
[...] 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. … [...]
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.
oh. it seems like Script# exists on the net for year… but I got to know about that yesterday :(