Author phr
Recipients phr, r.david.murray, rhettinger
Date 2009-10-16.21:44:10
SpamBayes Score 6.38793e-10
Marked as misclassified No
Message-id <>
David, I'm not on that mailing list so hadn't seen the earlier
discussion.  I sympathasize with Raymond's YAGNI argument because I'm
comfortable with reduce(max,seq,0); but then I remember there was once a
movement to remove the "reduce" function from builtins, which would have
broken that idiom.  I also understand that not everyone is comfortable
with that style.  I recently had to hand over some code to another
programmer where I had used that idiom, and in the course of adding
comments to the code in preparation for the handover, I found myself
writing quite a few words about why I'd used "reduce" that way, so I
figured that "explicit is better than implicit" suggests adding default
or initial args to the max function, just like "reduce" already has (I
figure that max on a sequence is a special case of reduce).

My proposed python implementation:

def mymax(*args, **kwargs):
  if len(args) > 1: return max(*args)
  if len(args) == 0: raise TypeError, "mymax needs at least one
positional arg"
  if 'initial' in kwargs: return reduce(max,args[0],kwargs['initial'])
  return reduce(max,args[0])
Date User Action Args
2009-10-16 21:44:12phrsetrecipients: + phr, rhettinger, r.david.murray
2009-10-16 21:44:12phrsetmessageid: <>
2009-10-16 21:44:11phrlinkissue7153 messages
2009-10-16 21:44:10phrcreate