
Posted on • Edited on • Originally published atmaximilianocontieri.com
Code Smell 57 - Versioned Functions
sort, sortOld, sort20210117, workingSort, It is great to have them all. Just in case
Problems
Readability
Maintainability
Solutions
Keep just one working version of your artefact (class, method, attribute).
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()
Right
findMatch()
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
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.
Top comments(3)

- LocationGaithersburg MD
- Workcomputer networking researcher at NIST
- Joined
What if:
- It's a C function, where optional arguments are not supported.
- A new version of the function adds an extra argument.
- Old version cannot be deleted because it would break dependants.
The only way is to keep both old and new functions.
Real example:pipe and pipe2 in Linux syscall

- LocationEnd of line!
- EducationMSc
- Joined
That doesn't change the fact that it is a code smell. Sometimes language or runtime restrictions make code smells unavoidable.

- LocationBuenos Aires
- EducationComputer Science Degree at Universidad de Buenos Aires
- PronounsHe/Him
- WorkSenior Software Engineer at Avature
- Joined
Many bad languages introduce unavoidable code smells
We should be aware of them
For further actions, you may consider blocking this person and/orreporting abuse