Writing Clean and Modular Code
Helpful tips on making sure you’re code is the best it can be!
What do you think it means to have clean and modular code?
Modular code is having code that is broken into functions and modules. Having functions and modules makes coding easier because you can call on the function later without having to repeat and rewrite lines of code.
One important step in having clean code is to refactor it! This is a process that happens after you initially write your code. Look it over and see if you can clarify or simplify it. Why? To reduce workload in the long run. It’s easier to maintain and reuse, and it helps you become a better developer.
Use meaningful and descriptive names for clean code. Remember DRY — don’t repeat yourself! You can use is_ or has_ to help with descriptions and show type. Use your white space properly. Keep spacing and indentations consistent. A great online tool to use is Pep8Online.
Below is an example of some of my clean and modular code. Feel free to check out my Github page for more tips, projects and guides on coding in Python. Happy coding!