Script# at MIX11

Followup to my talk at MIX11 - Script#: Compiling C# to JavaScript, along with links to sample code and slides.

At MIX11 last week, I presented the Script#: Compiling C# to JavaScript using Visual Studio.

As full-fledged script-based development becomes widespread with the HTML5 wave, a couple set of interesting questions emerge - what are the development tools you and your team uses to productively author and manage a code base? Shouldn’t you write code in a model that is optimized for development and productivity and let a compiler do its magic and produce code that is optimized for deployment and runtime?

Script# allows you to write your code in C# and compile it down to deployable JavaScript, it also unlocks the power of C#, Visual Studio and existing .NET tools for scripting scenarios.

Development with Script#

In my demo, I highlighted some of these tooling experiences (things like refactoring, static analysis, unit testing and IDE tools). I also demo'd how you can get started with the traditional "hello world" scenario and how you can continue to use frameworks like jQuery, as well as write your own jQuery plugins using Script#.

I have published the code and slides. I will be blogging a more detailed post on each demo over the course of the next few blog posts, so stay tuned.

Script# has been used successfully to develop various applications. These include Bing maps, Bing mobile, and the Messenger/Web IM integration within Hotmail.

Bing Maps Bing Mobile Web IM in Hotmail

If you’re building an application using Script#, I'd love to hear about it, and reference it in an upcoming revamp of the project's site.

You can now download the latest release of Script#, v0.7 off the Script# project site. It comes with the ability to consume generic types, a new script loader, and improved asp.net mvc integration, as well as nuget support to get you started on that. As always I look forward to hearing from you on your use of Script#.

Posted on Tuesday, 4/19/2011 @ 6:11 AM | #Presentations


Comments

9 comments have been posted.

Amit

Posted on 4/20/2011 @ 8:27 AM
Hi Nikhil,

Script# looks really great. But do we have support for calling any jquery plugins. E.g. jquery.imgareaselect.js. How can we write a wrapper for that. Is there any tool which can compile a js plugin to create a c# wrapper.

Nikhil Kothari

Posted on 4/20/2011 @ 12:30 PM
@Amit
You can use jQuery plugins with script# - for example, out-of-the-box there is support for the jQuery BBQ and templating plugins. There is nothing automagic to build the wrapper, but it isn't rocket science either.

I'd suggest checking out the sources on http://github.com/nikhilk/scriptsharp to see the code for those plugins as examples... and furthermore if you do build any, perhaps share them as well. Hopefully that sets up a pattern of the community helping itself, and overall will ensure everyone doesn't have to build a wrapper from scratch every time for every plugin.

phil

Posted on 4/22/2011 @ 12:37 AM
Hi

When willthere be language support for c#4? All the sweet syntax sugar that makes C# outstanding, is not yet supported. Writing code in Scriptsharp looks more like writing .net 1.1 Code to me(Now with generics its a little more pleasant ;P). Im really anticipating you finally releasing the source code, and so maybe advancement goes faster in the future.
What do you think about SharpKit(which is open source and free now), which does the same and has full C#4 support? Their source on google code doesnt seem to be complete either and their .cs files are bloated and roughly about 2000 lines long each with lots of commented out methods.

I also really wonder how the ms teams went with script# for building things like maps and bing mobile and stuff. How did they organize the code and most importantly what did they say about the missing "var" statement? :D
Also what about debugging? Wouldnt it be possible to actually debug against the .net dll, maybe using proxy types that do js calls against the browser? This would also greatly enhance prouctivity(I hate to debug js in IE).

Nikhil Kothari

Posted on 4/22/2011 @ 1:39 AM
@phil
I too would like to see more support for language constructs from newer c# versions, and am evaluating couple of different approaches in terms of how the script# compiler is built (the current approach is to parse c# source code). Both of those approaches require some underlying foundation work that isn't ready yet. As those become ready, and I pick one, I will start opening up the source code. Opening up the source code to compiler before, and then doing a major shift in approach isn't going to be helpful.

While that is happening, the current focus is to first optimize the generated script further, as that results in better runtime characteristics (size, perf etc.) and in some ways is more interesting to teams using script#. As for teams using script# without c# 4 support, the productivity wins with using the overall approach far outweigh the pain from absence of specific language constructs.

Debugging - yes, theoretically its possible to build what you're referring to. It would be a nice subproject of its own, and perhaps something the community can get started. :-)

phil

Posted on 4/30/2011 @ 6:15 AM
Hi
I see your priorities. This seems to stand on much better fundamentals than other similar projects imo, and its an important project, just about to really start off.
I wonder what compiler approaches you are thinking about, i would think of the 3 possibilities of either directly parsing source code, parsing the il(like in jsc), or using some external ast provider or whatever(like "Compiler as a service" in the coming .net rewrite of the c# compiler)?
After I just started with Sharpkit, seeing it doesnt feel like its exactly brilliant, I might have a look at script# again, maybe I get it to work this time. :D

Kevin Happe

Posted on 5/13/2011 @ 2:49 PM
I would like to use Script# with a classic asp app that we have that has a lot of active x controls. Can you go into more detail on what I need to do be able to use an ActiveX control with Script#. The ActiveX tree is very simular to a tree control. Looking at the readme.pdf, do I need to create a sealed class the exposes the inteface(properties and methods) that are in the ActiveX control?

Thanks
Kevin

DBJDBJ

Posted on 6/2/2011 @ 4:37 PM
Interesting.
But why C#? Why not starting from JSCRIPT.NET ? Is it because it has no equivalent support in VisualStudio as C# enjoys ?

Furthermore. Adding S# functionality to the jscript.net compiler would not be that hard. Me thinks ?

Nikolai Evseev

Posted on 7/5/2011 @ 9:27 AM
Nikhil,
I am trying to find a reason to justify the use of script#. So far, the only reason I could see - is the lack of JavaScript knowledge in the development team. Otherwise, I see the project as another unnecessary complex layer in the development workflow.
Also, how compliant script# is with ECMA? how do you maintain the compliance with new developments in JavaScript? JScript?
What level of support is provided for industry-level applications?.....I have more questions....
Thanks

Nikolai

MDR

Posted on 2/17/2012 @ 6:10 PM
I am curious if you are following Roslyn and whehter there any plans (or possibility) to leverage this to add more features to Script #
Post your comment and continue the discussion.