Wednesday, April 8, 2009

Work in progress: No More JavaScript

I Love JavaScript. I Really do!
I've known it for about 10 years now, and wrote a good tens of thousands of code lines.

Until that one day, when we decided to use our compiler technology to generate the JavaScript code from the C# code.
Pros:
+ No more syntax errors
+ No more ugly coding style
+ No more using obscure JSON objects to store data
+ Structured language (C#).
+ C# type system that includes inheritance, interfaces, generics), method overloading.
+ Pretty and solid code
+ Powerful (JS Code can still be written if you want, and there are a few hacks to be more powerful should you require that).
+ Compressible code
+ Less maintenence
= Debugging (the generated code structure make it very readable).
Cons:
- One might argue that the development cycle will take more time. In reality, the cycle is much shorter, since most of the syntax problems are done at compilation time.
- Everything has to be typed. This include 3rd party libraries. I will get back to that shortly.
- The type system is not standard. Then again, every JS library has its own way of writing code.

But now and then, I want to build this cute little website, where I can do pretty simple things. To keep it lean and mean, I often choose to write some JS code by myself. After all, how much code will you need for this project. Well, as it turns out, I'm always underestimating. And then I turn to big, established libraries, such as Prototype and YUI. But they require memorizing and being very close to the reference documentation, if you want to get something done.

This brings me to the breaking point - the IDE. I use Visual Studio for writing JavaScript. I am very familiar with it, and very productive most of the time. Debugging is great (IE only, though), but it can be better with JavaScript. Due to the over-powerful nature of the language, nothing is simple when you want to get Autocomplete for a member of a variable ; or when you call an API that can get either a string or an
element or whatever. Some properties are offered on Mozilla only; some events are IE-specific. What's missing is a solid structure for the unstructured language. Order in the chaos.

So I came to the inevitable conclusion - No More JavaScript.

No More Javascript. The sound of these words make be both terrified and relieved. I now realize that this has been the one thing that held me back on so many projects. JavaScript will become the Assembly language of the web. Bookmark these words!

I've decided to do whatever I can to spread the love with this kind of technology. My long-term plan is to give it as open source and support the major JS libraries. Unfortunately, the current compiler technology is proprietary and uses 3rd-party licensed libraries. I am looking for alternatives.

For the short-term, I'm currently spending time on converting the YUI interface to C#. This takes a LOT OF TIME, but i'm really happy with the results. My goal is to build a website that's completely written using C#, but still uses the cross-platform power and wide community support of YUI. For the time being I'm moonlighting, which makes me excited and happy! And when I'm happy, I buy domains.

Cheers!
-Alon.

1 comment:

habeanf said...

Very cool.. looks like GWT but for c#
You should look at how GWT lets you define stubs for asynchronous client-server communication and the JSON RPC interface. I suggest you apply the same ideas to your product.
Also you could get ideas from optimizations they do.
Same goes for pyjamas (python to js)

Looks like you guys are taking off.. good luck!

Amir