DIP 1020--Named Parameters--Community Review Round 2

rikki cattermole rikki at cattermole.co.nz
Wed Sep 11 11:49:20 UTC 2019


On 11/09/2019 8:16 PM, JN wrote:
> On Wednesday, 11 September 2019 at 05:37:57 UTC, rikki cattermole wrote:
>> This is a known code smell with a known solution: refactoring.
>>
>> I will posit that if you have code that has long parameters lists 
>> often, either you have a lot of technical debt or you are writing code 
>> that lends itself to introducing technical debt often.
>>
>> For me at least, when I have long parameter lists, they typically 
>> involve math and are called in about one or two places at most and 
>> quite importantly all done within the same module. I do not believe 
>> that this warrants a language feature in of itself but I can be 
>> convinced that there are problems that lend itself to long parameter 
>> lists that are often solved.
> 
> Long parameter lists usually aren't a code smell, and personal opinions 
> and preferences are not enough to refute it. The alternative to long 
> parameter lists is the Builder OOP pattern, which also usually isn't a 
> code smell. Some records/objects just have many members and it doesn't 
> make sense to split them up into smaller groups.

There are quite a few people who believe as I do that long parameter 
lists are a code smell or at the very least indicative that there 
probably is a problem with the data abstraction.

Maybe not convincing for part of a DIP (its not part of DIP 1020 after 
all), but I would hope that we can agree that this opinion is not 
limited to just a few people.



Chapter 24 of Code complete second edition: Reasons to refactor.

"Well-factored programs tend to have many small, well-defined routines 
that don't need large parameter lists. A long parameter list is a 
warning that the abstraction of the routine interface has not been well 
thought out."


The closest thing I can find in my writing solid code book for C is 
"Don't write multipurpose functions. Write separate functions to allow 
stronger argument validation." but I am not sure it applies (but it 
might do in some contexts).


https://stackoverflow.com/questions/439574/whats-the-best-way-to-refactor-a-method-that-has-too-many-6-parameters

http://www.tusharma.in/smells/LPL.html

https://medium.com/@KonfHub/refactoring-long-parameter-list-in-constructors-java-e9c9f2cb1fb


More information about the Digitalmars-d mailing list