Pythonic style
Steven D'Aprano
steve at pearwood.info
Fri Apr 29 05:59:11 EDT 2016
On Fri, 29 Apr 2016 10:48 am, Gregory Ewing wrote:
> MRAB wrote:
>
>> Is it worthy of being in the Zen of Python?
>
> +1. Maybe something along the lines of:
>
> Dunder methods are for defining, not calling.
> Unless you're a dunderhead[1].
>
> [1] Meant in the sense of an enthusiast, cf. gearhead.
I think that the advice to not call dundermethods directly is excellent
advice, but it doesn't belong in the Zen. Look at the Zen: it's all pretty
abstract:
Beautiful is better than ugly.
Explicit is better than implicit.
etc. There's very little[1] concrete advice in the way of specificities such
as:
- don't use floats for money;
- use namedtuple for the equivalent of a C struct or Pascal record;
- composition should be preferred over inheritance;
etc. "Don't use dunders" is much closer to the second, more specific type of
advice which doesn't really fall into the Zen's bailiwick.
Better suited for the Zen would be:
"Not everything needs to be a one-liner."
which is nicely abstract and also completely useless for deciding which
things should and shouldn't be, as good koans ought to be.
[1] By which I mean none.
--
Steven
More information about the Python-list
mailing list