10
hinst
4y

Coworker writes functions accepting 8+ arguments, thinks it's ok

Comments
  • 4
    More variability!
  • 4
    As a member of the society of Variadic Functions, I can identify with this rant...
  • 5
    "You're allowed to write functions with 1, 2, 3 or infinite arguments, but nowhere in between."
  • 1
    Has he implemented 8 parameter-related error codes also?
  • 2
    Ugh. I was guilty of this at one point, too. I had a constructor with like 20 params. I have no idea why I thought it was a good idea. 🤦🏻‍♀️
  • 1
    named or optional parameters though?
  • 0
    @Root Everyone had, that's how you get experience. Plus you get haunted by it...
  • 0
    @calmyourtities I kinda see your point here but still... Bad practice.
  • 0
    @wicho how is having 8+ parameters bad practice if you have named or optional parameters
  • 0
    @calmyourtities That means your function is doing too much and/or its context is to open.
    I think it breaks the "do one thing and do it well" philosophy.
    Also that's why you have object attributes and all that sweet POO stuff.

    Not written in stone, I look forward to read your opinion
  • 1
    @wicho actually, i’m more referring to object constructors rather than functions. i agree in most cases functions should have few parameters. in flutter a fair amount of classes have constructors with 15 or more arguments, and they work well in my opinion. in the backend however, unless it’s a config function, most functions should have less than 5 parameters.
  • 0
    @calmyourtities I agree, but you can always abstract it enough to have max 3 params. But it is the same as db normalization too much or too little is a matter of context or situation.
Add Comment