Friday Finking: Limiting parameters

Barry Scott barry at barrys-emacs.org
Sun Jul 12 06:10:54 EDT 2020



> On 12 Jul 2020, at 00:15, DL Neil via Python-list <python-list at python.org> wrote:
> 
>> That does not necessarily mean that the function needs to know
>> the particular representation or form of that data.   Let those be
>> objects with getter methods for the data you wish, and have the
>> function document what methods it will attempt to call.   Then
>> any class that provides the expected methods would be suitable.
> 
> +1
> 
> Here, the proposal is not to pass an object per-se, but to pass a function/method ("getter method") which will deliver the requisite data-items?
> 
> So, might we then find that our mailing-label routine includes something like (copy-pasting is NOT proper Python!):
> 
> def mail_label( getter ):
>    ...
>    ( first name, middle initial, last name, house number, street name,
>    apartment number, town, state, country, zip code ) = getter()
> 
> In which case, have we not moved the "very long list" from the function def to a later line within the routine - and how is this in some way 'better'?
> 

This is not the refactor that Roger's excellent rule-of-thumb implies.

Clearly moving the 20 positional args into a tuple is basically the same code,
and the same maintenance problem.

I'd expect to see something like this:

def mail_label( person, address ):
	first_name = person.first_name
	# or if you want a function interface
	first_line_of_address = address.get_first_line()

Barry



More information about the Python-list mailing list