Maintaining large JavaScript applications

Most people think that it is extremely difficult to maintain large JavaScript applications. And I tend to agree with them, maintaining large JavaScript apps is nearly, if not entirely, impossible.

Only JavaScript applications?

It's fair to say that maintainability directly relates to the complexity, scale and code quality of the application itself. If it's difficult to write, it will most likely be difficult to maintain.

There are plenty of maintainable large-scale .NET and Java applications out there. Yet in my experience, there are just as many unmaintainable ones as well. Complexity and magnitude of a project are certainly factors. But the developers' experience, the development process and the technical architecture are equally important, if not more important.

It is true that some features of the JavaScript languages make it more difficult to create maintainable architectures. Dynamic types. anonymous functions and global scope are just a few examples. But creating maintainable architectures in JavaScript is not impossible. You just need the correct toolset and experience amongst your developers.

Larger than life

What is a large application? Sure, huge numbers of lines of code in your application classify it as a 'large' application. But I've seen small applications that were written so badly, that it took hours to just understand it's basic functionalities. And I'm not talking about just JavaScript applications at the moment.

You should never write 'large applications'. You should write small, maintainable modules; that are simple to test, read, write and understand. And if you do that correctly, it doesn't really matter what technology stack you use. If you write SOLID code, you will be able to maintain it. In all technologies, in every team, in every language.

Maintaining JavaScript applications

Make no mistake, maintaining JavaScript applications is harder than maintaining applications created in Java or C#. But if you take the following points into account, you should be fine:

  • Always split code into smaller and reusable pieces. Better yet, use frameworks that enforces you to do so. Always write SOLID code.
  • Write unit tests and/or E2E tests
  • Never, and I mean never, store variables in the global scope
  • Use code quality tools like JsLint or JsHint
  • Make team-wide-rules about code structure and syntax rules
  • Automate as much as possible
  • Don't use thousands of small libraries and frameworks for simple features. If you do, you'll have to maintain and upgrade each library individually!
  • Use a package manager
  • Keep it simple! For example, don't use inheritance in JavaScript like you would in C# or Java. Don't do the 'animal > mammal > cow' model.
  • Learn the basics of Node; Grunt (or Gulp) in particular

You might enjoy

Today, at the end of 2014, I'm looking back at the past months and reflect on the stuff I've…

Say you want to bind a string to an element in Angular. No real problem, you just use expressions…

Tim Sommer

I'm a Web Developer with +7 years of experience in the .Net framework, with a focus on HTML5 and JavaScript.

Belgium, Antwerp
comments powered by Disqus
Member of The Internet Defense League