cover-img

Code Smell 17 - Global Functions

Global function bring a lot of coupling. Don't use them.

21 October, 2022

3

3

0

Discouraged by Object-Oriented Programmings, Many mixed languages support it. And developers abuse them.

TL;DR: Global function bring a lot of coupling. Don't use them.

Problems

Coupling

Readability

Maintainability

Testability

Solutions

Wrap the function in a context object.

Examples

External Resources Access, Database access, Time and Operating System resources.

Sample Code

Wrong

Right

Detection

Many modern languages avoid them. For the permissive ones, scope rules can be applied and automatically checked.

Tags

Global

Conclusion

Structured programming considers global functions harmful. Yet, we can observe some bad practices cross paradigm boundaries.

Relations

Singleton and Classes are global points of access.

More Info

Credits

Photo by Mae Mu on Unsplash

The road to programming hell is paved with global variables.

Steve McConnell
This article is part of the CodeSmell Series.

3

3

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.