Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Code Smell 57 - Versioned Functions
Maxi Contieri
Maxi Contieri

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

  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 modeExit fullscreen mode

Right

findMatch()
Enter fullscreen modeExit 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 byK8 onUnsplash

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
yoursunny profile image
Junxiao Shi
stallion coder; push-up specialist
  • Location
    Gaithersburg MD
  • Work
    computer 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

CollapseExpand
 
elmuerte profile image
Michiel Hendriks
I shouldn't have written all of those tank programs.
  • Location
    End of line!
  • Education
    MSc
  • Joined

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

CollapseExpand
 
mcsee profile image
Maxi Contieri
Learn something new every day. - I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
  • Location
    Buenos Aires
  • Education
    Computer Science Degree at Universidad de Buenos Aires
  • Pronouns
    He/Him
  • Work
    Senior Software Engineer at Avature
  • Joined

Many bad languages introduce unavoidable code smells

We should be aware of them

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Learn something new every day. - I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
  • Location
    Buenos Aires
  • Education
    Computer Science Degree at Universidad de Buenos Aires
  • Pronouns
    He/Him
  • Work
    Senior Software Engineer at Avature
  • Joined

More fromMaxi Contieri

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp