
Be consistent with the parameters you use. Code is prose.
TL;DR: Don't confuse you readers. Keep the order.
Problems
Readability
Consistency
Solutions
Refactor and change parameters order.
Use named parameters
Sample Code
Wrong
function giveFirstDoseOfVaccine(person, vaccine) {
//
}
function giveSecondDoseOfVaccine(vaccine, person) {
//
}
giveFirstDoseOfVaccine(jane, pfizer);
giveSecondDoseOfVaccine(jane, pfizer); //Unnoticed mistake
Right
function giveFirstDoseOfVaccine(person, vaccine) {
//
}
function giveSecondDoseOfVaccine(person, vaccine) {
//
}
giveFirstDoseOfVaccine(jane, pfizer);
giveSecondDoseOfVaccine(jane, pfizer); //jane is immunized
Detection
- Some very smart linters may be able to compare arguments and hint for possible mistakes.
Tags
- Readability
Conclusion
This is a very simple smell.
Readability is very important to avoid mistakes.
Relations
Credits
Photo by Lance Grandahl on Unsplash
Computers are good at following instructions, but not at reading your mind.
Donald Knuth
This article is part of the CodeSmell Series.
About the author
I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.
Comments
Join the discussionNo comments yet. Be the first to comment.
Code Smells
In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most are just clues. They are no hard rules.





