[Tutor] "Overloading" methods

Alan Gauld alan.gauld at btinternet.com
Fri Sep 17 01:45:39 CEST 2010

> On Thu, Sep 16, 2010 at 6:02 AM, Michael Powe <michael at trollope.org> 
> wrote:
>> line structures, I had the thought to write methods with 
>> descriptive
>> names that simply returned a generic method that processed the 
>> method
>> arguments. e.g.,
>> def setpattern_iis(self,pattern,parameter) :
>>        type='iis'
>>        return pattern_generator(self,type,pattern,parameter)
>> In this case, creating a regular expression to parse the log lines 
>> for
>> a query parameter.

This doesn't really show that, it shows you calling a function and
returning its result, but we have no way of knowing what that is.

However the concept is sound and quite common in functional
programming where the function which returns another function
is referred to as a higher order function.

>> This is just a bit more "self documenting" than using the generic
>> method with the 'type' argument and requiring the user to enter the
>> type.  At the same time, it allows me to put all the parsing code 
>> in
>> one method.

Going by your example above it only saves one parameter - the
type - and I'm not sure that's so valuable. However without real code
its hard to judge. The concept is sound but like so many things
its possible to abuse it.

You can usually achieve similar ends with classes and/or dispatch


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list