# Code Smell 214 - Duplicate Parameter Names

> TL;DR: Turn on Strict Checks

# Problems

- Unexpected errors

- Ambiguity

- The Least Surprise Principle violation

- Portability

# Solutions

1. Enable [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode)

2. Use role-naming arguments

# Context

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

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/d7f79fb931bf07d11b28a4f6ca4d2239)
```javascript
function addNumbers(a, b, a) {
  console.log(a + b);
}

addNumbers(2, 3, 4);

// Outputs 7 (2 + 3 + 2)
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/1fc2681a474de57d2b124b709df9137a)
```javascript
"use strict";

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

# Detection

[X] Automatic 

By enabling strict mode, the compiler will warn us

# Tags

- Naming

# Conclusion

Enable the stricter modes you can find on your compilers.

Try to [fail fast](https://maximilianocontieri.com/fail-fast) and catch errors as early as possible and leave the hard and dumb work to the tools.

# Relations

%[https://maximilianocontieri.com/code-smell-188-redundant-parameter-names]

%[https://maximilianocontieri.com/code-smell-65-variables-named-after-types]

# More Info

[Sonar Source](https://rules.sonarsource.com/csharp/RSPEC-3872)

[Mozilla Org](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode)

%[https://maximilianocontieri.com/fail-fast]

# Disclaimer

Code Smells are my [opinion](https://maximilianocontieri.com/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned).

# Credits

Photo by [Caroline Veronez](https://unsplash.com/@carolineveronez) on [Unsplash](https://unsplash.com/photos/bbjmFMdWYfw)
    
* * *

> 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_ 
 
%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]
