Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
The Little Book of Python Anti-Patterns
-
A nice online resource of Python worst practices http://docs.quantifiedcode.com/python-anti-patterns They also have a free automated tool that you can point at any public GitHub repo to find where code might be suboptimal.
A podcast with the authors http://www.talkpythontome.com/episodes/show/18/python-anti-patterns-and-other-mistakes
Yet another example of Python innovation coming from Berlin ;-)
-
I somehow doubt the knowledge of whoever wrote the first page... Most of the suggestions were alright, but a few things were just wrong:
- For
if
conditions it recommends usingif cond is True
orif cond is False
, which is just as wrong asif cond == True
andif cond == False
that it recommends against. - It also mentions
if cond
andif not cond
, but says that those only work ifcond
is a boolean object, i. e.True
orFalse
, which is not true at all - this version works with any object, because all objects have a truth value (usuallyTrue
), unlike theis
test, which only works withTrue
andFalse
exactly, not with other objects with a truth value. - It pretends that
is
andis not
behave likeisinstance
and talks about writingif rectangle is Circle
, which is wrong. This misunderstanding might explain the misconception aboutif
statement conditions.
- For
-
I agree with your comments but the pages are still a great resource along the lines of the Jeff Knupp's book Writing Idiomatic Python.
I avoid using
is
altogether because of the blog post Why you should almost never use is in Python. I useif cond
andif not cond
almost everywhere for all data types because I find it more readable and less error prone. I therefore try to avoid comparing variables directly to True, False, None, '', [], {}, etc in alignment with Jeff Knupp's 5.1.4 Avoid comparing directly to True, False, or None. -
Thanks for pointing this out. It's fixed. Feel free to put any other things you might find into our issue tracker or just open a pull request. Any input is highly appreciated.