DEV Community

Cover image for Code Smell 214 - Duplicate Parameter Names
Maxi Contieri
Maxi Contieri

Posted on • Originally published at

Code Smell 214 - Duplicate Parameter Names

Two arguments of the same type. Two equal names

TL;DR: Turn on Strict Checks


  • Unexpected errors

  • Ambiguity

  • The Least Surprise Principle violation

  • Portability


  1. Enable strict mode

  2. Use role-naming arguments


Most compilers forbid duplicate parameters since they are a common mistake in a large parameters list

Sample Code


function addNumbers(a, b, a) {
  console.log(a + b);

addNumbers(2, 3, 4);

// Outputs 7 (2 + 3 + 2)
Enter fullscreen mode Exit fullscreen mode


"use strict";

function addNumbers(a, b, a) { }
//                          ^
// SyntaxError: Duplicate parameter name not allowed in this context
Enter fullscreen mode Exit fullscreen mode


[X] Automatic

By enabling strict mode, the compiler will warn us


  • Naming


Enable the stricter modes you can find on your compilers.

Try to fail fast and catch errors as early as possible and leave the hard and dumb work to the tools.


More Info

Sonar Source

Mozilla Org


Code Smells are my opinion.


Photo by Caroline Veronez on Unsplash

One of the things I've been trying to do is look for simpler or rules underpinning good or bad design. I think one of the most valuable rules is avoiding duplication. "Once and only once" is the Extreme Programming phrase.

Martin Fowler

This article is part of the CodeSmell Series.

Top comments (0)