Anders Hejlsberg Is Right: You Cannot Maintain Large Programs In JavaScript

There’s a quote over on a Channel 9 video of Anders Hejlsberg:

Erik Meijer: Are you saying you cannot write large programs in JavaScript?

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

With a follow-up post on DZone asking if you agree with this quote or not. I haven’t listened to the interview so I honestly don’t know if the quote is taken out of context or not. But honestly, I don’t think it matters if the quote is taken out of context because …

Anders Is 100% Correct

No ifs, ands or buts about it. Maintaining large JavaScript apps is nearly, if not entirely, impossible.

But Derick, You Write Large JavaScript Apps…

No, actually, I don’t.

I write JavaScript applications that appear to be large. They may be large systems, but in reality they are very small applications (“programs” as Anders says). In spite of 5 to 10 thousand lines of JavaScript code per system, easily, my applications follow the secret to building large applications:

“The secret to building large apps is never build large apps. Break your applications into small pieces. Then, assemble those testable, bite-sized pieces into your big application” – Justin Meyer, author JavaScriptMVC

(Quote taken from )

And that’s what I do. I write dozens of small “applications” – modules, really – that are then composed in to larger functional systems at runtime.

Improving Ander’s Quote

Like I said, Ander’s quote is 100% correct. I think Ander’s quote quote can be improved, though.

Did you notice that Justin Meyer’s quote didn’t mention JavaScript at all? The truth is, it doesn’t matter what language you’re writing in. This secret to writing large application is applicable to all of them. It’s why we have functions, objects, modules, classes, and other ways of grouping related sets of functionality and/or data together.

So, Ander’s quote should read:

Erik Meijer: Are you saying you cannot write large programs in [any language]?

Anders Hejlsberg: No, you can write large programs in [any language]. You just can’t maintain them.

Maintaining Large Systems

You’ll have to pardon the link-bait title of this post, and really pay attention to the semantics and language for a moment.

Anders is correct, but not because he is talking about JavaScript. He is correct because it is not possible to maintain large applications in any language / platform / runtime. Write small applications as modules, classes, assemblies, libraries, and/or any other type of modularization technique for your language and runtime environment. Then compose those small “applications” (modules, etc) in to large systems which are easier to write and maintain, in JavaScript or any other language.

$(function(){…}) vs (function($){…})($) or DOMReady vs The Module Pattern