JavaScript: A tool too sharp?


But, Roy Osherove believes so.  When I first started JavaScript, I thought so too.  My problem was that I approached JavaScript from the eyes of a C# developer.  But C#, JavaScript is not.  So what are the main gripes of JavaScript?

  • No tooling
  • No refactoring support
  • No navigation support
  • It’s not C#

One solution is to use something like Script# to generate JavaScript from C#.  This is similar to the approach of the Google Web Toolkit, with the exception that GWT has a whole ecosystem to basically be able to develop Swing-like applications on the web.

But something like Script#?  If you’re looking to program C# on the web, that’s the way to go.  But it’s a little unfortunate, as JavaScript is a very powerful language with features you simply can’t find in many other places.  The arguments against are very similar to what I’ve heard about other dynamic languages, yet the Rails developers seem to be productive.  Why is that?

My opinion is that it’s simply a very different mindset working in a dynamic language.  And before libraries like jQuery that really used JavaScript like it should, it was a lot more difficult to do interesting things.  I can’t imagine giving up features like prototype for generics.  In fact, I’d much prefer prototypes to generics, it’s just more powerful.  So how do we close the gap?

First, drop any assumption on how developing JavaScript should be.  It’s not a static language like C#.  It’s a dynamic, scripted language, not a static, compiled one.  Next, if you already know OOP, dive into some great JavaScript resources:

JavaScript is a beautiful little language, but it is not a forgiving language.  If you’re a procedural developer, or don’t know OO too well, JavaScript will eat you up.  Working with a language that has functions as first-class citizens actually changed how I use C#, and it would be rather unfortunate to skip the JavaScript experience in favor of a static language.

So what’s missing in my JavaScript experience?

For one, I still don’t see a great TDD story.  Most of the TDD examples I see go against a static, fake HTML page, which I don’t really see that proves anything.  I know how to TDD C# code, but it’s still not the same experience doing JavaScript.  Roy does have a great point, that your JavaScript files can get out of control.  It’s hard to find great canonical examples of how to develop and organize a solid scripted website.  I see a ton of small examples, but nothing on par of the DDD examples out there.  But given a little patience and some good reference material, JavaScript is one of those languages that can really open your eyes on what is possible beyond the barriers of C#.

Late-Bound Invocations with DynamicMethod