DEV Community

loading...
Cover image for Code Smell 57 - Versioned Functions

Code Smell 57 - Versioned Functions

mcsee profile image Maxi Contieri ・1 min read

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

Problems

  • Readability

  • Maintanability

Solutions

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

  2. Leave time control to your version control system.

Sample Code

Wrong

Right

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

Discussion (3)

Collapse
yoursunny profile image
Junxiao Shi

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

Collapse
mcsee profile image
Maxi Contieri Author

Many bad languages introduce unavoidable code smells

We should be aware of them

Collapse
elmuerte profile image
Michiel Hendriks

That doesn't change the fact that it is a code smell. Sometimes language or runtime restrictions make code smells unavoidable.

Forem Open with the Forem app