cover-img

Code Smell 21 - Anonymous Functions Abusers

Don't abuse closures and functions. Encapsulate them into objects.

30 October, 2022

5

5

0

TL;DR: Don't abuse closures and functions. Encapsulate them into objects.

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

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

Credits

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.

5

5

0

Maxi Contieri

Buenos Aires, Argentina

🎓Learn something new every day.📆 💻CS software engineer 👷coding👨🏽‍🏫teaching ✍🏾writing 🎨Software Design 🏢SOLID 🌉TDD 👴Legacy 💩Code Smells

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.