PyWart: os.path needs immediate attention!

Terry Reedy tjreedy at udel.edu
Sat Jul 30 15:48:21 CEST 2011


On 7/29/2011 8:50 PM, Steven D'Aprano wrote:

> Guido has a rule of thumb: "No constant arguments". Or another way to put
> it: if a function takes an argument which is nearly always a constant
> (usually, but not always, a flag) then it is usually better off as two
> functions.

I do not really understand his 'rule'*. The stdlib has lots of functions 
with boolean flags and params which default to None and are seldom 
over-ridden.

* Which is to say, it feels more like his gut feeling applied on a 
case-by-case basis than an actual rule that anyone could apply in any 
objective manner.

> Especially if the implementation looks like this:
>
> def get_thing(argument, flag):
>      if flag:
>          return one_thing(argument)
>      else:
>          return another_thing(argument)

If the rule is limited to this situation, where no code is shared, it 
seems pretty sensible.

> Argument flags which do nothing but change the behaviour of the function
> from Mode 1 to Mode 2 are an attractive nuisance: they seem like a good
> idea, but aren't. Consider it a strong guideline rather than a law, but
> it's one I would think very long and hard about before violating.
>
> But having said that, I'm currently writing a library where nearly all the
> functions violate the No Constant Argument rule. (The API isn't yet stable,
> so I may still change my mind.) Make of that what you will.

See * above ;-).

Terry Jan Reedy





More information about the Python-list mailing list