TypeScript is to JavaScript as C++ is to C

Or is it? Do you have an opinion?

I selected this title because that analogy helps me as I’m learning more about TypeScript. It has “truthiness”. But in a good way. It will help you understand the motivations behind TypeScript, and how its syntax and concepts relate to JavaScript syntax and concepts. For example:

  • Every valid JavaScript program is a valid TypeScript program. TypeScript tools understand and parse JavaScript.
  • You don’t have to use all the TypeScript features to get the benefits of some of them. Way back in the early days of C++, developers (myself included) convinced managers that we could use C++ as “A Better C”, without using any of those crazy object oriented features. We could use just some of the syntactic features and write the same old procedural programs we were familiar with.  The same is true with TypeScript: you don’t need to declare interfaces, classes, and Modules. Just use elements of TypeScript that you like, and continue with JavaScript constructs everywhere else.
  • TypeScript integrates with your existing JavaScript investment. Just like C++ programs could leverage C libraries.
  • TypeScript’s features are designed to be consistent with the existing JavaScript syntax and idioms. For example, properties in an object type literal or interface may be designated as required or optional. That optional feature makes typescript more consistent with existing JavaScript style than with static languages.
  • TypeScript’s compilers output is JavaScript. Just like CFront’s output was C.
  • TypeScript’s language features implement many common JavaScript patterns for classes, inheritance, modules. If you subscribe to the idea that Design Patterns indicate missing language features, then TypeScript has those missing features.

It’s “truthiness”, because if you take that concept too literally, it breaks down. TypeScript makes some features easier than in JavaScript, but it doesn’t feel quite as revolutionary as the jump from C to C++ (or maybe I’m just older). TypeScript isn’t changing the techniques used in JavaScript, like the shift from procedural to object oriented programming from C to C++. It is making Object Oriented constructs easier, but they aren’t impossible in JavaScript.

TypeScript is only one of a number of languages whose goal is to improve productivity for JavaScript developers. CoffeeScript and Dart are two other important efforts. I’m also not sure that TypeScript will ever reach the kind of popularity that C++ has enjoyed. I also don’t see TypeScript compilers added to all the popular browser platforms.

What do you think?  Is this a reasonable analogy to help people learn and understand TypeScript? Or is it a bad analogy that will stand in the way of developers learning it?

Created: 9/5/2013 7:06:23 PM

Current Projects

I create content for .NET Core. My work appears in the .NET Core documentation site. I'm primarily responsible for the section that will help you learn C#.

All of these projects are Open Source (using the Creative Commons license for content, and the MIT license for code). If you would like to contribute, visit our GitHub Repository. Or, if you have questions, comments, or ideas for improvement, please create an issue for us.

I'm also the president of Humanitarian Toolbox. We build Open Source software that supports Humanitarian Disaster Relief efforts. We'd appreciate any help you can give to our projects. Look at our GitHub home page to see a list of our current projects. See what interests you, and dive in.

Or, if you have a group of volunteers, talk to us about hosting a codeathon event.