Code Smell 57 - Versioned Functions

mcsee

Maxi Contieri

Posted on January 20, 2021

Code Smell 57 - Versioned Functions

sort, sortOld, sort20210117, workingSort, It is great to have them all. Just in case

Problems

  • Readability

  • Maintainability

Solutions

  1. Keep just one working version of your artefact (class, method, attribute).

  2. Leave time control to your version control system.

Sample Code

Wrong

findMatch()
findMatch_new()
findMatch_newer()
findMatch_newest()
findMatch_version2()
findMatch_old()
findMatch_working()
findMatch_for_real()
findMatch_20200229()
findMatch_thisoneisnewer()
findMatch_themostnewestone()
findMatch_thisisit()
findMatch_thisisit_for_real()
Enter fullscreen mode Exit fullscreen mode

Right

findMatch()
Enter fullscreen mode Exit fullscreen mode

Detection

We can add automatic rules to find versioned methods with patterns.

Like many other patters we might create an internal policy and communicate.

Tags

  • Versioning

Conclusion

Time and code evolution management is always present in software development. Luckily nowadays we have mature tools to address this problem.

Relations

Credits

Photo by K8 on Unsplash

Original idea


That's why I write, because life never works except in retrospect. You can't control life, at least you can control your version.

Chuck Palahniuk


This article is part of the CodeSmell Series.

💖 💪 🙅 🚩
mcsee
Maxi Contieri

Posted on January 20, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Code Smell 57 - Versioned Functions
codenewbie Code Smell 57 - Versioned Functions

January 20, 2021