[dgplug-users] [OT] Object Calisthenics in Python

Arnau Orriols arnauorriolsmiro at gmail.com
Thu Jun 12 06:07:02 PDT 2014


> For Python we follow PEP-8 [1]. If you are in doubt
> always remember:
>
> "Simple is better than complex." :)

I couldn't agree more. I always try to apply as much as possible to
the PEP8. But I was talking in a sense of the design of your code more
than its layout, issue which PEP8 does not address, at least
explicitly (please, correct me if I'm wrong!)

I do think the Zen of Python actually focus on design, only that it
does it in a much more philosophical way.

Take for instance the rule number 2, "Don't use the ELSE keyword".
Would "Simple is better than complex" apply here, as "Don't try to be
too smarty writing a fancy "Null Object Pattern" just to get rid of a
fucking ELSE in your conditional flow"? Or rule number 1 "One level of
indentation per method", which suggests you to just create another
method any time you need to add a level of indentation (because of an
if, or a loop...). It really struck me that none really seemed to
understand why I was worried about the harm to simplicity it could
cause this high level of indirection.

Anyway, as a side note, I've been searching for a while some source
that gives me some written snippets that illustrates the meaning of
the different statements of the Zen. If anyone knows of any, it would
be very appreciated :)


> It, PEP8, is also integrated in a lot of scripts and whatnot making it the best for use, I already have it as
> a plugin for vim for example and it tells me when I do something outside the guidelines which
> sometimes makes me change the snippet or other times simply ignore it because I know better
> (kidding but sometimes you can’t follow it even if you want to).

Interesting plugin, thanks Armaggedon! I've been using flake8, very
handy tool that searches in your code for any line not applying to the
PEP8. But a plugin for vim, that's even handier, I'll give it a try :)

Arnau.


More information about the Users mailing list