On TypeScript and writing maintainable JavaScript programs…

As I’ve mentioned, I’ve been using TypeScript quite heavily for some internal prototyping that I’ve been doing. As such, I’m starting to form various opinions about it, and overall I really like it (which makes sense, given my background). One thing I’ve been thinking about lately, though, is the quote from Anders Hejlsberg that ricocheted around a while back and which obviously prefigured the TypeScript work:

No, you can write large programs in JavaScript. You just can’t maintain them.

Clearly, TypeScript is intended as an answer to this problem, and I’ve found that it definitely helps me keep my program more in line and not have it wander off in some strange direction I didn’t intend. But it also doesn’t “solve” the problem of maintaining large JavaScript programs any more than the invention of the hammer “solved” the problem of building large buildings. If I don’t follow my usual rules of thumb when programming (think about what I’m doing, keep my code clean, review and rewrite, etc.), my TypeScript code becomes spaghetti just as quickly as my JavaScript code ever did.

Ultimately, the problem is that a tool is only ever as good as the person wielding it. In that sense, I disagree with Anders’s sentiment above–I think it’s entirely possible to write very large codebases in JavaScript that are maintainable, it just requires a somewhat higher degree of discipline and effort than in a language like TypeScript. And the delta of effort between the two languages isn’t as high as those of us who work in the language space would often like to believe. If TypeScript catches on (and I hope it does), there’s probably going to be vastly more bad code written in TypeScript than good code. The difference from JavaScript is that it’ll just have more type annotations…

 

Leave a Reply