Feature:

The Expense of a Line of JavaScript Code

By Alex Craciun

TheServerSide.com

After reading the “ JavaScript: Unscientifically tested to be more annoying and frustrating than Java” article, I realized that others may share my feelings about Javascript, not about the language itself, but rather about matters when dealing with it inside an enterprise like development cost, productivity, maintainability, quality. 

Again unscientifically, a Javascript line of code seems more expensive (a factor of2-3) than the Java equivalent. It seems to me that the Javascript part of the project we build always takes longer. One explanation can be linked to the relative knowledge about the two languages of the developers I work with.

I had this discussion with a guy the other day; he mentioned that he doesn’t understand why he sees lots of job opportunities for Java/.net specialists, but never for Javascript specialist. My explanation to this is that, unless you’re node.js adept, Javascript alone cannot be used to build completely an application. It’s always a language that is complementary in a project that is mainly written in Java, PHP, .net, Ruby or other language. 

Javascript is dynamically-typed

But I think this is not the only explanation. By being a dynamically typed language there is a list of problems that a typed language would not have:

  • The autocomplete does not work correctly forcing you to keep using “Search” to find the possible actions
  • This results in going back and forth to the documentation to see how a library can be used (if you’re lucky and the library has one)
  • The name of variables are much shorter making them less descriptive (because sometimes you have to type them completely – no help from your IDE)
  • No type for a function parameter means no hint for its possible value (Think about enums in Java)
  • No method overload – leaving solutions like jQuery’s plugins where types of the parameters depend on the value of the first parameter – the method name!
  • The refactoring seems almost impossible making the code aging quickly

This list is of course not complete. But anyone of these items makes you spend few seconds more than the same task in Java. Multiplied by the number of times you do it, by the number of developers, equals a lot of time lost!

Project size

Another factor that strikes me is the moment when the people I know start considering a Java or a Javascript project “big”. And this moment is not the same for the two languages:for Java they start considering a project “big” (so they start splitting the project, creating more modules, etc) around 15,000-20,000 lines of code, while the moment appears for a Javascript project already around 5,000-7,000.

As an example, here are two open source projects that I consider “big” (data according to ohloh website

Of course these projects don’t have the same list of functionalities. But this comparison tells you how people perceive the size and difficulty of a project. And can guide you next time you start a project.

28 Nov 2011

Related Content

Related Resources