Code Smell 21 - Anonymous Functions Abusers

Subscribe to my newsletter and never miss my upcoming articles

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


  • Maintainability
  • Testability

  • Code Reuse

  • Implementation Hiding

  • Debugging


  1. Wrap functions/closures

  2. Reify algorithms in method object / Strategy

Sample Code



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


  • Primitive

  • Abuser


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



Photo by Roman Mager on Unsplash

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

This article is part of the CodeSmell Series.

Tapas Adhikary's photo

I am now an official fan of your Code Smell explanations! Great job.

Rodion Borisov's photo

These busters are the most hard to debug! Not like debugging was an option, if code smells very much to begin with 😏

Maxi Contieri's photo


Most debuggers are very dumb related to closures and source code.

I personally prefer unit testing instead of debugging and this is also hard with this smell.