Declaring too many functions can make Javascript code complex

Software EleganceCode Complexity

Why you should care

A JavaScript file should not declare an excessive number of functions since a higher number of functionalities declared in a module increase the complexity of this module and slows down the effectiveness of the code.

Too many functions can also lead to bigger file sizes which leads to reduced compactness of the code.

Business Impacts

Further increasing the complexity of the code can harm the business-applications of the code in terms of overall productivity and it’s speed.  Code that is incredibly complex might not grow and evolve.


CAST Recommendations

CAST recommends limiting the number of literal functions assigned to global variables as well as lowering the amount of declaring global functions.  It is fine to incorporate inner functions and literal functions without assigning them to global variables to ensure the code can provide accelerated progress for the portfolio.


Style Guide

How we detect

This code insight is defined in the alarm model of the javascript langiuage, but following items should be counted :

  • global functions declarations
  • literal functions assigned to global var.

Are not concerned :

  • inner functions
  • literal functions (if assigned to local var)
  • anonymous functions (if assigned to local var)



About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.

See featuresHow it works