r/learnpython • u/TheGrapez • Nov 05 '20
How does one learn to make well-structured programs? Mine are dumpster-fires.
So I just (kind-of) finished reading Automate The Boring Stuff With Python, and for the past month I've felt like a big-brained super-hero automating myself out of a job (Data Analyst).
The problem is, I feel I missing something along the way. I don't understand the proper way to use functions, what a class is, why people have multiple files in a program, how/why people use GitHub...probably some other things I haven't discovered yet.
They all seem to be related to organization? Is there a "How To Structure Your Python Stuff With Python" book?
478
Upvotes
3
u/Dogeek Expert - 3.9.1 Nov 05 '20
The first step you can take in improving code quality is to install a linter, such as pylint, flake8, pycodestyle or pyflakes. A linter will tell you what your formatting mistakes are. That won't help you with organisation though.
The next step you can take is to learn how to use git. Git is a very powerful tool, but many people don't use it to its full capabilities. I come accross plenty of repos on github or gitlab with only one active branch. Make several branches ! It never hurts.
Finally, how to structure your project. It varies from project to project (some frameworks have specific folder structures). The basics of it though, are :
The
srcdirectory can also be named after your project. It's where your code lives. Thedocsdirectory is where your documentation is. Using a documentation generator like the ever popularsphinxmodule helps there. Then you have thetestsfolder. This last folder is for unit tests, which you can pretty easily write with the unittest module of the standard library in python.