py-tips-n-tricks

Python best practices, tips, tricks, recommendations and general programming practices





Also check nerds-jargon-jungle slides


Made with reveal.js

Note

  • Hold down the alt key (ctrl in Linux) and click on any element to zoom towards it. Click again to zoom back out.
  • Press Shift + ← / → Jump to first/last slide
  • Press CTRL + Shift + F Search on all slides. Found words/phrases will be highlighted. Press Enter to jump between slides with found words/phrases.
  • At any time press `Shift+?` to see the help overlay with keyboard shortcuts

One virtual environment per project

Isolation. You don't want to mess up the system Python
Different projects have different dependency versions

Structure your code and projects

Package and module structure gives an overview about the project
Modular design == better re-usability

Utilize the capabilities of your editor

Efficient and fluent development
There's plenty of tools to make your daily programming easier, why would you not use them

5 Tips To Achieve Low Coupling In Your Python Code

source YT video
  1. Avoid deep inheritance relationships
  2. Separate creating resources from using them
  3. Introduce abstractions
  4. Avoid inappropriate intimacy
  5. Introduce an intermediate data structure

Testing

If it can break, it should be tested. This includes models, views, forms, templates, validators, and so forth
Each test should generally only test one function
Keep it simple. You do not want to have to write tests on top of other tests
Run tests whenever code is PULLed or PUSHed from the repo and in the staging environment before PUSHing to production

When upgrading to a newer version of library or web framework

  • upgrade locally
  • run your test suite
  • fix bugs
  • PUSH to the repo and staging, and then
  • test again in staging before shipping the code