Use contextual and local names
TL;DR: Don't repeat your parameters' names. Names should be contextual.
Problems
Duplication
Readability
Solutions
- Remove the repeated part from the name
Context
When using names, we often miss that words are contextual and need to be read as a whole sentence.
Sample Code
Wrong
class Employee
def initialize(@employee_first_name : String, @employee_last_name : String, @employee_birthdate : Time)
end
end
Right
class Employee
def initialize(@first_name : String, @last_name : String, @birthdate : Time)
end
end
Detection
[X] Semi-Automatic
We can check our parameter names and try to find duplication.
Tags
- Naming
Conclusion
Use short and contextual names for your parameters.
Relations
![mcsee](https://res.cloudinary.com/practicaldev/image/fetch/s--by_E26Wt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--XvnZDWAZ--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/366059/69feb7c3-ab01-4bcd-a6f5-ec38e9300da3.jpeg)
Code Smell 87 - Inconsistent Parameters Sorting
Maxi Contieri ・ Sep 26 '21
Disclaimer
Code Smells are just my opinion.
Credits
Photo by Wolfgang Hasselmann on Unsplash
As a rule, software systems do not work well until they have been used, and have failed repeatedly, in real applications.
David Parnas
![mcsee](https://res.cloudinary.com/practicaldev/image/fetch/s--by_E26Wt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--XvnZDWAZ--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/366059/69feb7c3-ab01-4bcd-a6f5-ec38e9300da3.jpeg)
Software Engineering Great Quotes
Maxi Contieri ・ Dec 28 '20
This article is part of the CodeSmell Series.
Top comments (0)