The Little Book of Python Anti-Patterns and Worst Practice
Free

The Little Book of Python Anti-Patterns and Worst Practice

By QuantifiedCode
Free
Book Description

Welcome, fellow Pythoneer! This is a small book of Python anti-patterns and worst practices.

Learning about these anti-patterns will help you to avoid them in your own code and make you a better programmer (hopefully). Each pattern comes with a small description, examples and possible solutions. You can check many of them for free against your project at QuantifiedCode.

Read online.

Table of Contents
  • Why did we write this?
  • Who are we?
  • How is this book organized?
  • References
  • Licensing
  • Contributing
  • List of Maintainers
  • Index Of Patterns
    • Correctness
      • Accessing a protected member from outside the class
      • Assigning a lambda expression to a variable
      • Assigning to built-in function
      • Bad except clauses order
      • Bad first argument given to super()
      • else clause on loop without a break statement
      • __exit__ must accept 3 arguments: type, value, traceback
      • Explicit return in __init__
      • __future__ import is not the first non-docstring statement
      • Implementing Java-style getters and setters
      • Indentation contains mixed spaces and tabs
      • Indentation contains tabs
      • Method could be a function
      • Method has no argument
      • Missing argument to super()
      • Using a mutable default value as an argument
      • No exception type(s) specified
      • Not using defaultdict()
      • Not using else where appropriate in a loop
      • Not using explicit unpacking
      • Not using get() to return a default value from a dict
      • Not using setdefault() to initialize a dictionary
    • Maintainability
      • using wildcard imports (from ... import *)
      • Not using with to open files
      • Returning more than one variable type from function call
      • Using the global statement
      • Using single letter to name your variables
      • Dynamically creating variable/method/function names
    • Readability
      • Asking for permission instead of forgiveness
      • Comparing things to None the wrong way
      • Comparing things to True the wrong way
      • Using type() to compare types
      • Not using dict comprehensions
      • Not using dict keys when formatting strings
      • Not using items() to iterate over a dictionary
      • Not using named tuples when returning more than one value from a function
      • Not using unpacking for updating multiple values at once
      • Not using zip() to iterate over a pair of lists
      • Putting type information in a variable name
      • Test for object identity should be is
      • Using an unpythonic loop
      • Using map() or filter() where list comprehension is possible
      • Using CamelCase in function names
    • Security
      • use of exec
    • Performance
      • Using key in list to check if key is contained in list
      • Not using iteritems() to iterate over a large dictionary
    • Django
      • Maintainability
      • Security
      • Correctness
      • Performance
      • Migration to 1.8
    No review for this book yet, be the first to review.
      No comment for this book yet, be the first to comment
      You May Also Like
      Also Available On
      App store smallGoogle play small
      Categories
      Curated Lists
      • Pattern Recognition and Machine Learning (Information Science and Statistics)
        by Christopher M. Bishop
        Data mining
        by I. H. Witten
        The Elements of Statistical Learning: Data Mining, Inference, and Prediction
        by Various
        See more...
      • CK-12 Chemistry
        by Various
        Concept Development Studies in Chemistry
        by John Hutchinson
        An Introduction to Chemistry - Atoms First
        by Mark Bishop
        See more...
      • Microsoft Word - How to Use Advanced Algebra II.doc
        by Jonathan Emmons
        Advanced Algebra II: Activities and Homework
        by Kenny Felder
        de2de
        by
        See more...
      • The Sun Who Lost His Way
        by
        Tania is a Detective
        by Kanika G
        Firenze_s-Light
        by
        See more...
      • Java 3D Programming
        by Daniel Selman
        The Java EE 6 Tutorial
        by Oracle Corporation
        JavaKid811
        by
        See more...