… things you wish you’d known… Will you be so kind to share those?
I’ve done quite a bit of Python development and published a few packages to PyPi, but I’m learning new things every day. I’d love to share a few thoughts
General software advice
- The best way to learn any language is to use it.
- If you’re starting out, I highly recommend using a light text editor: emacs/vim/sublime/atom. Integrated development interfaces (IDEs) like PyCharm/Eclipse/Spyder have fantastic features, but I usually find these cumbersome when I’m trying to focus on learning something new.
- “Clean Code” and “Clean Architecture” are primarily written with Java development in mind, but most of the advice applies to general software engineering.
Some languages require you follow specific patterns (looking at you, Java) and the compiler will reject your code otherwise. Python tends to leave you free to follow any object-oriented/functional/whatever design pattern you wish.
However, this freedom also leads to non-obvious things you have to learn along the way. Try to answer these two questions (hint: in Java the answers are obvious):
- What is the difference between
def _foo(): and
- What does “
if __name__ == "__main__":” do and why is it at the bottom of a file?
Reading other people’s code and checking against styleguides (PEP8, Google) are the main two ways I picked up on these sort of conventions.
Tools to make development easier
black: Automatic code formatting.
pdb: Debug by dropping breakpoints in your code:
import pdb; pdb.set_trace()
pylint: Help catch bad practices (unused variables, shadowing effects)
sphinx: Whenever you’re reading online Python documentation, it was probably generated with this tool. I’ve found that knowing some of the conventions of the generator have helped me better understand where to find documentation.
venv: Virtual environments for managing Python dependencies on your various projects.
This is extremely general advice, so there’s a lot this does not cover: libraries, import conventions, scripting vs. packaging, unit/integration/functional testing, CI systems, code coverage, version control, code optimization, C bindings. But many of these will also be specific to the problems you’re interested in solving.
If it’s helpful, I have a medium-sized Python library I’ve been hacking on in my free time. I’d be happy to answer questions about development choices, project organization, or any related questions on Python more generally.