Dreaming of new generation IDE

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Feb 6 00:19:22 EST 2010


En Fri, 05 Feb 2010 19:22:39 -0300, bartc <bartc at freeuk.com> escribió:
> "Steve Holden" <steve at holdenweb.com> wrote in message  
> news:mailman.1998.1265399766.28905.python-list at python.org...
>> Arnaud Delobelle wrote:
>>> Robert Kern <robert.kern at gmail.com> writes:
>>>
>>>> I prefer Guido's formulation (which, naturally, I can't find a direct
>>>> quote for right now): if you expect that a boolean argument is only
>>>> going to take *literal* True or False, then it should be split into
                      ^^^^^^^^^^^^^^^^^^^^^^^
>>>> two functions.
>>>
>>> So rather than three boolean arguments, would you have eight functions?
>>>
>> If there's genuinely a need for that functionality, yes.
>
> So you want a function such as drawtext(s, bold=true, italic=false,  
> underline=true) to be split into:
>
> drawtext(s)
> drawtextb(s)
> drawtexti(s)
> drawtextu(s)
> drawtextbi(s)
> drawtextbu(s)
> drawtextiu(s)
> drawtextbiu(s)

Note the *literal* part. If you (the programmer) is likely to know the
parameter value when writing the code, then the function is actually two
separate functions.
By example, foo.get_path(absolute=True) should be written as
foo.get_absolute_path() and foo.get_relative_path()
It gets worse when one parameter alters the type of the returned value, or
even the number of returned values. This is an actual example:

def build_image(self, zone=-1, return_sizes=False):
     ...
     if return_size:
       return img, sizes
     else:
       return img

image = foo.build_image(3)
but:
image, sizes = foo.build_image(3, True)

It should be split onto two separate functions; in this particular case,
computing 'sizes' required actually drawing the image, so the solution was
to make those 'sizes' attributes of the returned image.

-- 
Gabriel Genellina




More information about the Python-list mailing list