On TypeScript

Children bikes are equipped with detachable training wheels. Training wheels are very helpful on the initial stages, when you have to accustomize yourself with the speed you’re moving around, and how to get on or off the bike, and how to brake, and how to turn, and how to avoid obstacles, and how to check environment around you before you make a sharp brake or turn. But when it is time to approach the actual bike usage pattern – getting to the actual bike speeds – you have to detach the training wheels and learn how to balance.

I have almost similar feelings about statically typed programming languages. They are great for exactly four things:

  • Learning the frameworks and APIs (due to auto-completion features)
  • Protecting yourself from typos
  • Achieving maximal run-time performance
  • Allowing more automatic refactorings

Run-time performance is rarely important in the world of app development (remember my RAD vs CS article?). Automated refactorings are very rarely needed in the modern web development, where 95% of apps are rarely allowed to grow older than a year. That’s more an attribute of enterprise software having decades of legacy code. As for the first two advantages, they are indeed great for the novice programmers, or for programmers switching platforms and languages.

And this is what TypeScript is all about, and therefore I believe it could be a help for programmers who want to migrate from statically typed languages to JavaScript. Its creator Anders Hejlsberg (who also created Delphi and C# before) gave a talk about it on the //build conference:
http://channel9.msdn.com/Events/Build/2012/3-012
And I believe this talk is every second worth to watch. The thing is that Hejlsberg doesn’t really appreciates all advantages of the dynamically typed languanges, only makes this talk more interesting and sometimes funny. For example, as he presented the type inference of the process function, I couldn’t resist opening the TypeScript playground in another browser window, and typing

function process(a: bool) {
  if(a)
    return 1;
  else
    return "haha";
}

This has been marked as an error in TypeScript. This and also many other examples can show you that if you use TypeScript, you will actually be forced to reason about the source code as if you’ve had used C#. And this means you’ll lost some of the advanced JavaScript features – those wonderful dynamic features that would bring you up to the actual speed.

In any case, I can’t deny that auto-completion would be a great help for me to learn, say, jQuery or Node.js, or WinRT frameworks, if I needed to. I also like the look and feel of the TypeScript syntax, which is in parts quite similar to C#; actually, some of the TypeScript features I wanted to have in the C#, for example type checking based on object structure (so that I could pass anonymous objects to functions expecting named types), or the notion of interface as the combined structure of all interface definitions from all included source files.

TypeScript is also a perfect example of the New Microsoft. It is free. It is open source. It embraces open standards (EcmaScript). It doesn’t bind you to any other MS products (although it is integrated with Visual Studio, nothing prevents, say, Eclipse or JetBrains to integrate with it too). This is not the first such example and not the last one, and this change has happened not this year, and not in the previous year. This has changed at least 5 years ago. I just wonder when the geeks will realize that. Until that, the New Microsoft will remain an insider tip.

Leave a Reply

Categories

Archive