Function "modes" vs. separate functions (was: PyWart: os.path needs immediate attention!)
Andrew Berg
bahamutzero8825 at gmail.com
Fri Jul 29 21:15:35 EDT 2011
On 2011.07.29 07:50 PM, Steven D'Aprano wrote:
> Especially if the implementation looks like this:
>
> def get_thing(argument, flag):
> if flag:
> return one_thing(argument)
> else:
> return another_thing(argument)
>
Well, that would be annoying, but wouldn't it be even more annoying to
do this:
def get_one_thing(arg):
return one_thing(arg)
def get_another_thing(arg):
return another_thing(arg)
> 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.
Creating separate functions for two thing that do almost the same thing
seem more of a nuisance to me, especially if they share a lot of code
that isn't easily separated into other functions.
--
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
More information about the Python-list
mailing list