On 2020-07-11 09:54:33 +1200, dn via Python-list wrote:
> Questions:
> 
> Is the idea of limiting the number of parameters passed across an interface
> a real concern or somewhat an affectation?
> 
> Is three, five, seven, ... a valid limit (or warning-signal)?
> 
> Do you have a personal or corporate style or 'standard' to limit parameter
> lists to seven parameters, or some other number?
> 
> Given that Python enables labeled arguments ("keyword arguments"), does the
> concern really only apply to 'us' in terms of numbers of "positional
> arguments"?

Keyword arguments greatly ameliorate the problems I have with long
parameter lists. While I think that calling a function with 7 positional
parameters is pretty much unreadable, with 7 named parameters (or maybe
2 positional and 5 named parameters) it doesn't bother me much. The
definition of the function might have even more parameters, as long as
most of them are optional and have sensible defaults (subprocess.Popen
with 20 parameters (if I counted correctly) is pushing it, though).


> Why not simply create and pass a collection (to suit the 'standards
> committee') and be done. What's the big deal, don't have time to waste,
> bureaucracy (!)...
> 
> What about the similar Q+D solution using a class?

That's what I often do. The main reason is that often a lot of those
parameters are repetitive. So instead of passing the same 7 parameters
to every function, I create a "Context" or "Job" class with those 7
fields which I then pass to each function. So it not just looks tidier,
it also reduces the risk of inconsistencies.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | h...@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment: signature.asc
Description: PGP signature

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to