[Python-Dev] PEP 450 adding statistics module
eliben at gmail.com
Fri Aug 16 06:14:59 CEST 2013
On Thu, Aug 15, 2013 at 7:44 PM, Steven D'Aprano <steve at pearwood.info>wrote:
> On 16/08/13 04:10, Eric V. Smith wrote:
> I agree with Mark: the proposed median, median.low, etc., doesn't feel
>> right. Is there any example of doing this in the stdlib?
> The most obvious case is datetime: we have datetime(), and datetime.now(),
> datetime.today(), and datetime.strftime(). The only API difference between
> it and median is that datetime is a type and median is not, but that's a
> difference that makes no difference: both are callables, and being a type
> is an implementation detail. dict used to be a function that returned a
> type. Now it is a type. Implementation detail.
> Even builtins do this: dict() and dict.fromkeys(), for example. If you
> include unbound methods, nearly every type in Python uses the callable(),
> callable.method() API. I am truly perplexed by the opposition to the median
> API. It's a trivially small difference to a pattern you find everywhere.
Steven, this is a completely inappropriate comparison. datetime.now(),
dict.fromkeys() and others are *factory methods*, also known as alternative
constructors. This is a very common idiom in OOP, especially in languages
where there is no explicit operator overloading for constructors (and even
in those languages, like C++, this idiom is used above some level of
complexity). This is totally unlike using a class as a namespace. The
latter is unpythonic. If you need a namespace, use a module. If you don't
need a namespace, then just use functions. Classes are the wrong tool to
express the namespace abstraction in Python.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev