Microsoft TypeScript: Can the father of C# save us from the tyranny of JavaScript?
Summary: Anders Hejlsberg, the father of C#, has a new project. But can it win over developers outside of the Microsoft camp?
I'm not a great one for heroes, but the few I do have includes Anders Hejlsberg. He's the architect of C#, a technology that I've used virtually every day in the past eleven years of my career as a professional software developer. It's the technology that's touched my life the most, enabling me to get a deep sense of personal satisfaction out of my job and career. I wouldn't be surprised if other software developers who work day-in-day out with C# feel the same fondness for it as I do for it.
C# and .NET were hugely important for Microsoft. Back in 2001, the developer story on Windows was an utter mess. An almost indescribable hodgepodge of messy hacks and broken approaches. C# and .NET created a staging post for those targeting the Microsoft stack to gather and regroup before heading off on a journey that on aggregate measures in millions of man-years across the community as a whole. Collectively, we gathered, we changed direction, and all set out together.
But with TypeScript the world is very different. This isn't one man's vision of how to change the products of one company with the objective of selling more of that one company's product. This is about how to change JavaScript - a tool that reaches way outside of Microsoft's sphere of influence and into the heart of the open development community.
Objects
It's commonly regarded - perhaps by people who don't know the language well - that JavaScript's object-orientation story is lacking. Approaching a JavaScript activity with the intention of applying OO thinking is a good way of getting your heart broken.
From first principles, OO is attractive because if you're trying to build a complex system it's easier in terms of mapping requirements into work items, structuring code, sharing work out in large teams, surfacing meaning during maintenance, and so on. If you want to do complex work, you don't want to use JavaScript.
Or so you'd think. The reality is that JavaScript seems to bend and flex this logic almost as if rather than being developed by humans thinking human thoughts, it was accidentally left behind by visiting aliens. People do manage build amazingly complex things with JavaScript despite its total lack of sympathy for OO. Its inherent flexibility makes it work even when you think it can't possible.
So how does TypeScript work? All you have to understand for this article (and I'll do another that looks into the mechanics) is that TypeScript is a superset of JavaScript that lets developers add strong-typing and OO. It's designed to be very sympathetic to JavaScript - there's no attempt to replace, or subsume the language. It's not an "extend, embrace, and extinguish" strategy. It's solely designed to move the story on.
At its most basic, it's just "syntactic sugar". Sprinkle it onto common or garden JavaScript and you'll get code that's easier to read and easier to work with on larger projects.
What you also get is IntelliSense. Having spent today working on a PhoneGap project with a basic text editor and no IntelliSense I'm reminded that building complex code without it is irritating at best, unproductive and costly at worst.
So back to Anders. Let's look at three of his home runs. Firstly Turbo Pascal, the one in which he takes Pascal and reinvents it to make it work really well and have developers fall in love with it. Then Delphi, the one in which he takes Visual Basic and reinvents it to make it work really well and have developers fall in love with it. Then C# … you get the idea.
Anders's gift is in looking at where developers are, seeing where they need to get to, and then building a tool that lets them get there. TypeScript is his vision that says where JavaScript developers today isn't a happy place, and goes on to say that their happy place is where decent OO tooling lies.
The challenge
TypeScript will live or die in the open source community. (This isn't 2002.) To that end, I reached out to Miguel de Icaza, an individual with open source chops like few others.
First thing he reflected on was that out-of-the-box what was released today works on OS X. (You can install it in Node.js using the Node Package Manager.) He also went on to talk about how it's open source (it uses the Apache License 2.0). Engagement is also good - the language specification (PDF) is online, and there are managed forums. The initiative is being done entirely in the community, for the community.
In our conversation Miguel told me that "the language architect needs to play an active role". This is one of the things I'm worried about with Anders - rightly or wrongly he's spent a lot of time doing deep thinking within an organisation that's mostly closed-source. (Incidentally Miguel was confident that a mindset adjustment to being more open wouldn't be a problem.) However, I'm going to need to see Anders come out on Twitter and really start communicating as well as all the Microsoft people who are on Twitter do.
Miguel he cited concerns as to whether the "existing JavaScript community is ready to embrace component-based systems". So it's this idea that if OO is so important in JavaScript, why doesn't it exist yet?
On that same topic, Miguel said that "successful open source projects are ones that fill a need". Again, why is OO not in JavaScript already? If it's needed, why has an existing open source project not filled the gap?
I should say that Miguel was general positive about the project, he mentioned only one misstep which was that "the web developers of the world got half the benefits". And I think this is a pretty big misstep. If you're building web apps that run on anything other than Windows, you're likely using a Mac and most likely not using Visual Studio. You need the Visual Studio plug-in to get the IntelliSense. All you get without Visual Studio is the strong-typing. You don't get the productivity benefits you get from IntelliSense.
Conclusion
If it was anyone other than Anders Hejlsberg doing this, I wouldn't even have bothered to write this article. He gives it credibility. The basic open source execution steps are all there - license, source code, willingness to discuss, multiple platforms - tick, tick, tick, tick. The lack of IntelliSense on non-Microsoft tools is an error, and it would have been easy enough to add these to Eclipse and other IDEs.
But this single question remains - if object-orientation in JavaScript is so important, why don't we already have it? It's not like JavaScript is a peculiar, niche thing.
What do you think? Post a comment, or talk to me on Twitter: @mbrit.
Kick off your day with ZDNet's daily email newsletter. It's the freshest tech news and opinion, served hot. Get it.
Talkback
OO... Why don't we already have it?
The biggest concern about this is Microsoft! I fully expect to find their grandmother under the bus along with Silverlight!
Will they stay the course, even when the ride gets bumpy? Who knows, or better yet, who trusts them to do it?
Truly Open Source === Vendor Agnosticism
Objective-C
C# is for fools
Why is he going back trying to reinvent the wheel again?
Microsoft should STFU and take COM / VB seriously!
LOL!!!!
Modern VB is a great language
But, of course, I cut my teeth on C and C++; VB is still somewhat foreign to me (when people read any VB I write, they can tell I grew up in the land of squiggely brackets and semi-colons).
yep great...
oops. :)
Absolutely
Absolutely
VB
OS2 Warp was great for users
Very True
over the years companies gathered a lot of toolsets, ActiveX components and interfaces which makes VB powerful and not the core VB as C# probably outsmart VB if you compare the core.
True that microsoft has completely abandonment COM and marooned small companies which relied on it and lots of investments.
VB and VB.NET
VB.NET is a completely different story. It's basically a C# dressed into an ugly cloth of VB syntax. It's almost as powerful as C#, but no one programs in it any more and I don't see any reason to use this artificial hybrid when we have a beautiful C# - which became even more beautiful when it got functional features (lambda expressions, LINQ, etc.)
I'm kind of skeptical on attempts to generate JavaScript from object-oriented languages like Java, C#, or Scala. JavaScript has different ideology behind it - inheritance through prototypes. Douglas Crockford explains it in a best possible way http://www.crockford.com/.
CoffeeScript is an exception
"I've never found these "language X to JavaScript" tools to be worth using. Debugging, quality of code generation, interfacing and using native JS libraries, etc., etc. mostly get compromised. CoffeeScript is an exception, because it is a new syntax for JavaScript, not an entirely separate and unrelated language.
If you need to use JS (or another language for that matter), embrace it and learn it."
You are stuck with old habits
That reminds me a conversation I overheard last year during a Sharepoint 2010 session. Two old chaps complained that SQL is too clumsy they could do the same using Clipper in no time (an 198x compiled language of dBase3). Morality: when you don't accept that you are a dinosaur, you tend to self-congratulate in consolation.
You are stuck with incorrect assumptions
seriously??
mixed feelings so far
My first concern, though, is that JavaScript is not an OO language. It can be done, and done well, but it always feels like bending the paradigm. JS began as a sort of "scriptlet" language that could be used to decorate bits of HTML markup. This role of augmenting markup hasn't gone away; it has become more central to JavaScript's role than ever.
If JavaScript adheres to any particular paradigm, it's more functional than OO. JQuery has really moved the language in that direction over the last several years. That shouldn't be an obstacle for TypeScript, though; C# has evolved its own powerful functional tools, including LINQ, generic delegates, event handlers, tasks, and its new asynchronous programming model. Anders Hejlsberg has led all of this evolution of C#, and I have no doubt that these aspects of C# will inform the development of TypeScript as well.
My second reservation is based simply on the range of quality of existing JavaScript code. There are certainly many outstanding JavaScript developers, but there are also many horrifyingly bad ones, who know and care nothing about OO or any other paradigm. Along with this is the problem of legacy code. TypeScript as a language is not enough. It has to integrate well with test frameworks and a practical knowledge base for working with legacy applications.
The tooling issue leaves me wondering what Microsoft can bring to the table that's really new. Visual Studio, especially when enhanced with the ReSharper plugin or equivalent tools such as Telerik's JustCode, is already the best development environment for JavaScript that I know of. That includes Intellisense, auto-completion, refactoring support, and extensive support for code cleanup of common problems such as unused or uninitialized variables, scope issues, missing semicolons, dead or unreachable code, etc. So, really, what's going to be new and different beyond strong typing?
Syntactically and structurally, can TypeScript take us the next steps beyond Doug Crockford's distillation of JavaScript's "good parts"?
What is the added value of TypeScript?
Javascript by itself is very flexible and unstructured, it is easy to create a mess with it. You really need tooling and frameworks to keep your Javascript projects structured and maintainable. Things I really need when working on larger Javascript projects:
- Debugging tools.
- Package management.
- Libraries and frameworks to keep the code structured and manageble.
- Type annotation & code documentation. When working on larger projects with more people, one of the things I indeed miss in Javascript itself is variable type annotation. The things you typically like about strict typed languages: the ide/compiler warns you about improper method calls like wrong parameter types, helps overloading required functionality from super classes, interfaces, etc.
Point is, the tooling for this is already there, and is getting better and better:
- Browsers have better and better debugging tools, and debugging gets implemented more and more in IDE's.
- We have NPM for package management, very easy, works great.
- There are great MVC frameworks out there, and great libraries such as jQuery, making it easier to create larger projects and reuse common functionality.
- Variable typing can be solved using annotations. This serves two purposes: IDE's can utilize these annotations for code inspection, and it encourages you to document your code. This also keeps the variable typing at an optional, supportive, "meta" level, instead of requiring a new language for that.
Have a look at the WebStorm Javascript IDE. It comes with type checking (using jsdoc style annotations), code inspection, auto completion, debugging, and comes integrated with github and node.js, etc. It is really amazing and brings Javascript programming to a whole new level.
Anyway, leaves the question open to me what TypeScript really adds besides syntactical sugar.
syntactic sugar: tastes great!
I'd much rather have strong typing than annotations; to me, that is not "syntactic sugar." Strong typing enforces good practices; annotations do not. (And annotations, like all comments, can lie.)