Python Worst Practices

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Feb 25 18:54:22 EST 2015


Mark Lawrence wrote:

> http://www.slideshare.net/pydanny/python-worst-practices
> 
> Any that should be added to this list?  Any that be removed as not that
> bad?


I have no idea about Python worst practices, but I think using some sort of
Powerpoint slide is surely one of the worst practices in general. In my
browser, I see the title "Python Worst Practices". There's a Next Slide
button, but clicking it does nothing.

Down below, there is what appears to be a transcript, but it is full of
extraneous and unnecessary fluff (nearly every line has a leading "Daniel
Greenfeld @pydanny") and the formatting is destroyed.


Worst practices:

- Using assert for error checking, instead of explicit tests.

- Overuse of regexes. If the only tool you have is the regex 
  hammer, everything looks like a nail.

- Underuse of regexes: failing to use a regex when one is called 
  for is not quite as bad as the regex hammer, but still.

- Python is not Java.

http://dirtsimple.org/2004/12/python-is-not-java.html‎
http://dirtsimple.org/2004/12/java-is-not-python-either.html


Most worst practices are independent of the language. Regardless of whether
they are writing Python, C or Ocaml, too many programmers make these deadly
programming sins:

- Too much coupling. Possibly the Mother Of All Sins, many other
  sins are variations of this: spaghetti code, ravioli code, global 
  variables, etc.

- Premature optimization. Which usually means, optimizing without
  measurement. If you just *assume* this code is "faster", chances
  are excellent that it is actually slower.

- Overuse of 1-character or excessively generic variable names.

- The other extreme: extremely_long_variable_names_for_no_good_reason.

- Variable names (including functions and classes!) that aren't
  self-explanatory.

- Misusing Hungarian notation. Or failing to use it when appropriate.

http://www.joelonsoftware.com/articles/Wrong.html

- Violating the Rule of Demeter: don't talk to the dog's leg, talk to 
  the dog. Or another way to put it: don't let the paper boy reach
  into your pocket for money.


And very possibly the worst practice of all:

- Failing to understand when it is, and isn't, appropriate to break
  the rules and do what would otherwise be a bad practice.





-- 
Steven




More information about the Python-list mailing list