Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Code Smell 21 — Anonymous Functions Abusers

Functions, lambdas, closures. So high order, nondeclarative, and hot.

Photo by Roman Mager on Unsplash

Problems

  • Maintainability
  • Testability
  • Code Reuse
  • Implementation Hiding
  • Debugging

Solutions

  1. Wrap functions/closures
  2. Reify algorithms in method object / Strategy

Sample Code

Wrong

Right

Detection

  • Closures and anonymous functions are very useful to model code blocks, promises etc. So It’d difficult to tear them apart.

Tags

  • Primitive
  • Abuser

Conclusion

Humans read code. Software works ok with anonymous functions but maintainability is compromised when multiple closures are invoked.

Relations

Object-oriented programming increases the value of these metrics by managing this complexity. The most effective tool available for dealing with complexity is abstraction. Many types of abstraction can be used, but encapsulation is the main form of abstraction by which complexity is managed in object-oriented programming.

Rebecca Wirfs-Brock

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Maximiliano Contieri

I’m a senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan. Maximilianocontieri.com

No responses yet

Write a response