Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewstokeley/f32a96d84a9b50f2bcf9e9371fdf679f to your computer and use it in GitHub Desktop.
Save matthewstokeley/f32a96d84a9b50f2bcf9e9371fdf679f to your computer and use it in GitHub Desktop.
Cyclomatic complexity and lexical scope in JavaScript.
Cyclomatic complexity and lexical scope in JavaScript.
Arrow functions, the equivalent of prototypally-inherited invoked bound functions, and modules, specifically the implementation of the ECMA spec designed from the competition between AMD and Commonjs implementations, radically altered default practices for handling global namespace collisions, variable design considerations and mutation strategies. This progression to discrete functions and native encapsulation can be thought of in terms of the principle of reducing cyclomatic complexity. The depth of lexical record is reduced at every function invocation, the global namespace is obviated, reducing IIFE’s and revealing modules that increase scope depth, and design choices increase given immutable variable declaration to reduce closures - design systems utilizing revealing module-enabled chaining syntax and object-oriented prototypal JavaScript are unaffected. Cyclomatic complexity is considered detrimental in method design because of memory constraints imposed by accessing parent scope and in this way shares concerns that led to the introduction of immutable data structures - cyclomatic complexity and immutable object strategies can be considered mutually bénéficient concerns undergirding the changes and improvements in es2015+ in order to reduce both cyclomatic and systematic complexity - systematic complexity alone is estimated to account for $59 billion in losses in the U.S. economy every year, and the reduction of cyclomatic complexity mostly utilizes proposed strategies for reducing systematic complexity with the major exception of explicit native state handling strategies (see previous blog post for more).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment