DEV Community

Cover image for Code Smell 99 - First Second
Maxi Contieri
Maxi Contieri

Posted on • Originally published at maximilianocontieri.com

4 2

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)
Enter fullscreen mode Exit fullscreen mode

Right

class Calculator:
  def subtract(self, minuend, subtrahend):
    return minuend - subtrahend

class CalculatorTest:  
  def test_multiply():
    assert equals(expectedValue, realValue)
Enter fullscreen mode Exit fullscreen mode

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.

MongoDB Atlas runs apps anywhere. Try it now.

MongoDB Atlas runs apps anywhere. Try it now.

MongoDB Atlas lets you build and run modern apps anywhere—across AWS, Azure, and Google Cloud. With availability in 115+ regions, deploy near users, meet compliance, and scale confidently worldwide.

Start Free

Top comments (0)

AWS Q Developer image

What is MCP? No, Really!

See MCP in action and explore how MCP decouples agents from servers, allowing for seamless integration with cloud-based resources and remote functionality.

Watch the demo

👋 Kindness is contagious

If this **helped, please leave a ❤️ or a friendly comment!

Okay