How many times do we see lazy argument names?
TL;DR: Name your arguments according to the role and not the accidental position
Problems
Readability
Intention Revealing Names
Solutions
- Use meaningful names
Context
When writing methods, we usually don't stop to find decent names.
We never refactor the obvious, neither.
Sample Code
Wrong
class Calculator:
def subtract(self, first, second):
return first - second
class CalculatorTest:
def test_multiply():
assert equals(first, second)
Right
class Calculator:
def subtract(self, minuend, subtrahend):
return minuend - subtrahend
class CalculatorTest:
def test_multiply():
assert equals(expectedValue, realValue)
Detection
[x] Manual
We can warn for forbidden words like 'first' and 'second' as argument names.
Tags
- Readability
Conclusion
Always follow rule suggesting parameter.
Name your collaborators according to the role.
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 65 - Variables Named After Types
Maxi Contieri ・ Apr 2 '21
More Info
![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)
What exactly is a name - Part II Rehab
Maxi Contieri ・ May 23 '21
Credits
Photo by Priscilla Du Preez on Unsplash
Final source code is the real software design.
Jack Reeves
![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)