Code Smell 21 — Anonymous Functions Abusers
Functions, lambdas, closures. So high order, nondeclarative, and hot.

Problems
- Maintainability
- Testability
- Code Reuse
- Implementation Hiding
- Debugging
Solutions
- Wrap functions/closures
- 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
This article is part of the CodeSmell Series.