re: Object Oriented Tricks: #3 Death By Arguments VIEW POST


I think it's acceptable to use many optional arguments and booleans in languages that support named arguments (like Python). It's essentially natural support for the builder approach:

progressDialog.show( title="My title", message="Hello", indeterminate=false, cancelable=true, cancelListener=listener )

In lieu of named arguments I also like using an enum instead of a boolean.

//yucky boolean
show( "Message", true )

//with an enum
show( "Message", dlg_cancellable )

It's also forward compatible with adding more options to the function.

I don't necesarily agree that a boolean always implies two different functions. Quite often a boolean triggers only a minor change in the algorithm. It's often better for documentation and discoverability to just have the one fucntion with an option isntead of two differently named functions.

Code of Conduct Report abuse