Skip to main content

Code Smell 99 - First Second

Published 1 min readMarkdown
Part of seriesCode Smells
Code Smell 99 - First Second

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

  1. 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)
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

More Info

Credits

Photo by Priscilla Du Preez on Unsplash


Final source code is the real software design.

Jack Reeves


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.

No comments yet. Be the first to comment.

Code Smells

Part 1 of 50

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.