On Thu, Sep 16, 2010 at 6:02 AM, Michael Powe <mich...@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
tables.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor