DEV Community

loading...
Cover image for Code Smell 17 - Global Functions

Code Smell 17 - Global Functions

mcsee profile image Maxi Contieri Originally published at mcsee.Medium ・1 min read

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

Problems

  • Coupling

  • Readability

  • Maintainability

  • Testability

Solutions

  • Wrap the function in a context object.

Examples

  • External Resources Access, Database access, Time and Operation 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

Discussion (0)

pic
Editor guide