Science, engineering, coding and music geek for vocation and profit.
My main areas of interest include machine learning, automation, smart home/IoT, IT security, infrastructure design and devops.
"Long lists of identically typed parameters can be harmful and very error-prone" - I would argue that this can be a quite language-specific remark. Languages like Python or Perl make it easy to use keyword arguments to circumvent the curse of long function signatures:
defstart_camera(device='/dev/video0',resolution=(640,480),color_mode='rgb24',rotation=0,scale=(1,1),# ...
**kwargs):cam=Camera(device=device,...)# ...
# Pick only some of the parameters through named arguments
start_camera('/dev/video1',rotation=90)
Although this can be achieved in languages like JavaScript with key-value objects:
And in Java with, as you said, helper classes - and even though such a mechanism is also available in recent versions of Python (@dataclass) I still prefer the named arguments approach because it makes a method signature really self-explanatory.
I completely agree with the named parameter approach, but I still think a long list of parameters, especially of the same type is still error-prone since you don't have to use the named parameters (I can only speak for Python and JavaScript).
Plus a long parameter list to begin with usually means bad design. But named arguments definitely make it less error-prone should you choose to go down that path.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
"Long lists of identically typed parameters can be harmful and very error-prone" - I would argue that this can be a quite language-specific remark. Languages like Python or Perl make it easy to use keyword arguments to circumvent the curse of long function signatures:
Although this can be achieved in languages like JavaScript with key-value objects:
And in Java with, as you said, helper classes - and even though such a mechanism is also available in recent versions of Python (
@dataclass
) I still prefer the named arguments approach because it makes a method signature really self-explanatory.I completely agree with the named parameter approach, but I still think a long list of parameters, especially of the same type is still error-prone since you don't have to use the named parameters (I can only speak for Python and JavaScript).
Plus a long parameter list to begin with usually means bad design. But named arguments definitely make it less error-prone should you choose to go down that path.