DEV Community

loading...

Code Smell 59 - Basic / Do Functions

mcsee profile image Maxi Contieri ・1 min read

sort, doSort, basicSort, doBasicSort, primitiveSort, superBasicPrimitiveSort, who does the real work?

Problems

  • Readability

  • Bad Naming

  • Low Cohesion

  • Single Responsibility Principle

Solutions

  1. Use good object wrappers

  2. Use dynamic decorators

Sample Code

Wrong

Right

Detection

We can instruct our static linters to find wrapping methods if they follow conventions like doXXX(), basicXX() etc.

Tags

  • Declarativiness

Conclusion

We came across this kind of methods some time in our developer life, We smelled something was not OK with them. Now is the time to change them!

More info

What is in a name

Wrapper Function

Decorator

Credits

Photo by Roger Bradshaw on Unsplash


The primary disadvantage of Wrap Method is that it can lead to poor names. In the previous example, we renamed the pay method dispatchPay() just because we needed a different name for code in the original method.

_ Michael Feathers_

Discussion (0)

pic
Editor guide