Skip to content

Instantly share code, notes, and snippets.

@lahwran
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lahwran/2b60c1aa3f890a636b0f to your computer and use it in GitHub Desktop.
Save lahwran/2b60c1aa3f890a636b0f to your computer and use it in GitHub Desktop.
My edit/application of pep20. in the original form, pep20 might as well be scripture - these are transformations to it based on my experience, not based on arbitrary interpretation.

All of these are "as long as not at huge expense to the others"; any would be bad on their own.

(in machine-learning-nerd terms, read these as a series of objective functions, and evaluate code based on these as something approximately like the sum of squared errors function. In non-machine-learning-nerd terms, one should try to minimize how much code breaks each of these rules individually. They are not priority sorted.)

  • Beautiful is better than ugly - while this is hopefully obvious, looking better is an acceptable thing to aim for.

  • Explicit is better than implicit - only delegate to implicit things that are sufficiently common to not be confusing.

  • Simple is better than complex - do make things implicit that will be obvious anyway.

  • Flat is better than nested - especially in directory structure and code depth; try to minimize indent.

  • Sparse is better than dense - don't be afraid of writing more stuff, as long as that stuff is semantically simpler. Don't try to pack it all in to the same spot.

  • Readability counts - the code has to be made and fixed by humans, even if just once.

  • Special cases aren't special enough to break the rules as often as your intuition says they are.

  • If they have to fight, practicality beats purity; avoid scenarios where you must choose one.

  • Errors should never pass silently - you can't fix it if you don't know it misbehaved.
    -> it follows from this that misbehavior that can be detected before the program runs should be!
    python violates this very badly.

  • Unless explicitly silenced; some error states in one part of the code are not errors in the context of the whole.

  • In the face of ambiguity, refuse the temptation to guess.

  • There should be one - and preferably only one - obvious way to do it.

  • Now is better than never; don't try to make something perfect the first time.

  • Although never is often better than right now: yaks need not apply.

  • If the implementation is hard to explain, it's almost certainly a bad idea.

  • If the implementation is easy to explain, it isn't necessarily a bad idea.

  • Namespaces are a really great idea -- let's do more of those!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment