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.

Acceleration
5362

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.

References

https://www.quora.com/Will-too-many-JavaScript-functions-negatively-impact-performance-How-about-if-there-are-several-AJAX-calls-to-render-the-template

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)

 

5362

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