mercredi 30 juin 2021

Do “Clean Code”'s function argument number guidelines apply to API design?

I am a newbie reading Uncle Bob's Clean Code Book.

It is indeed great practice to limit the number of function arguments as few as possible. But I still come across so many functions offered in many libraries that require a bunch of arguments. For example, in Python's pandas, there is a function with 9 arguments:

DataFrame.groupby(by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=<object object>, observed=False, dropna=True)

(And this function also violates the advice about flag arguments)

It seems that such cases are much rarer in Python standard libraries, but I still managed to find one with 4 arguments:

re.split(pattern, string, maxsplit=0, flags=0)

I understand that this is just a suggestion instead of silver bullet, but is it applicable when it comes to something mentioned above?

Aucun commentaire:

Enregistrer un commentaire