One of the things I hate most about programming is messy code. For example:
Indenting is a big problem in some people's code, as seen in the example above. Bad indenting makes code look ugly and unreadable. The standard indent is 4 spaces, but if you can pick your own indent size (it's not that important of a convention anymore). The important thing to remember is to always be consistent with tab size and indent your code properly.
Spacing is how you put spaces in the code itself. Just as important as indenting is good and consistent spacing. Again, it's all up to you but I like to space my code like this:
Variable and Function Naming
A very important part of code formatting is how you name your variables and functions. It might not seem like a very big deal, but naming variables names that make sense often makes code easier to read and debug.
One common thing that people do is name all of their variables in for loops
i. You don't actually need to name it
i because it is just a normal variable. Name it whatever makes sense to the thing you are iterating through.
When picking a variable name, keep in mind the case you are using. There are two main ways to name variables,
snake_case. Everybody has their own preferences and I prefer naming my variables using
snake_case. Pick a case, and stick to it throughout all of your code. Be consistent with your naming conventions.
Not many people comment in code. I have no idea why, I do it all the time and it is very helpful. Commenting is important for easy-to-read code, whether you forgot how one part works or if somebody else is trying to understand your project. It also makes code look better imo
Always make your comments about what the code does and not how it works. Example:
Also always comment in the imperative tense,
Get file extension and not
Gets file extension.
Now since you have read this tutorial, you are a god at formatting good job
cough cough @AtticusKuhn cough cough
With ides like pycharm the ide will throw a bunch of errors in red on the right hand side for indentation problems. the program will still run but the big red font basically forces you to format your code properly. nothing beats the sweet satisfaction of having no red or yellow dashes beside your program with that big green tick.