Is JavaScript really this complex?

Leonardo Pessoa
Leonardo Pessoa
Published in
4 min readMay 23, 2016

This morning I woke up to this post in which an infographic suggests JavaScript is the most complex modern programming language. Is it? First and foremost I need to declare I’m not some JavaScript enthusiast but as I started analysing the infographic I was amused by the criteria used to give that title to the language.

Analysing projects

The surveyor declared to have analysed “over 400 billion lines of code across thousands of projects” to reach their verdict. Here I’m assuming all statistical work has been done correctly such as balancing the number of projects found for each language (ensuring I’m not analysing more projects or LoC of one language than of another), so I’m not discussing this matter.

But their first criterion, cyclomatic complexity, caught my eye. Why? Because this complexity measure can greatly vary by the knowledge of developers to the choice of projects. An inexperienced programmer can write the same code as an experienced one but possibly the later code will bear a bigger cyclomatic complexity than the former. Imagine now a bigger project with dozens (possibly hundreds) of hands over time. The cyclomatic complexity can describe how a particular implementation of a project is complex at a given time. Code can be changed and this complexity can improve or decline over time. Thus I believe this part of the infographic only states that over the time of the survey a lot of JavaScript code was maintained by programmer with little experience with it. And this may be accounted by the fact that JavaScript just recently became a front-end language (which other languages such as Java and C++ have by and large).

Next the surveyor ranks the languages by the amount of questions about them on a popular forum among developers. It is a simple measure but again misused. This information cannot be used to declare a language complex because programmers need the most help with it. It only informs us it is being used and needed by a larger amount of programmers than others languages. Again this may easily be due to the fact of JavaScript recently becoming the choice for front-end programming while other languages have an already consolidated knowledge.

Lastly the surveyor ranks as expressiveness the amount of LoC changed, on average, each time a new commit is made. That definitely cannot be called “expressiveness” because commits are made with both when errors are found and fixed and when requirements to the application change. Not only the LoC changed can be greater due to changes in requirements in yet unstable projects (older projects based on Java or C++ tend to be more stable and require less maintenance) but also due to optimisation in these projects.

Thus the only reason JavaScript can be called complex in this survey is for being relatively new in front-end open-source projects. Has any project in Swift been evaluated?

Language complexity is relative

Under these criteria any new language that becomes popular among programmers will become the most complex modern language. Is this correct? One could name a number of ways to declare a language as complex, i.e. you could have the same programmer writing the same code over multiple programming languages and evaluate their opinion on which one is the most complex but that would be biased by their previous knowledge. It would thus be a only a matter of preference.

I’m to believe one could only evaluate the complexity of a language evaluating the language itself and not constructions using that language. If I were asked to decide which language is more complex I’d evaluate things like:

  • how many “duplicated” statements it has, such as guard in Swift that could easily be replaced with an if statement in every case
  • how may multiple uses for a statement, like for in Swift in which the keyword can be used to declare two statements with different syntaxes (this is scheduled to be unified in the future)
  • the ability to extends (add methods and/or properties to) existing classes, like in Swift and Ruby, increases or decreases language complexity?
  • in this matter, the amount of different constructs (classes, enums, delegates, extensions, etc.) increases or decreases complexity?

This is all subjective. In the end this is all just like trying to decide which real world language is more complex by the size of their texts, number of mistakes people do and how popular they are. Can we really declare German is more complex than Dutch? Or Portuguese?

--

--

Leonardo Pessoa
Leonardo Pessoa

architecture student (5/10) · designer · developer · geek