Analytics Vidhya
Published in

Analytics Vidhya

Writing Clean and Modular Code

Helpful tips on making sure you’re code is the best it can be!

Let’s help each other be the best programmers we can be. Credit for the image here

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.

Image found here: https://blog.jetbrains.com/wp-content/uploads/2015/02/pycharm-refactoring4.png

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.

The site is free! You just enter in your code, click the ‘check code’ button, and results will appear as above. This is beneficial to see exact lines and columns of your code that need to be cleaned up!

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!

Short clip of clean code from my Github here implementing a Binary Search Tree :)

--

--

--

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Recommended from Medium

Setting up Ingress on Minikube

Why Legacy System isn’t going anywhere (yet)

Shortcut Keys for Jupyter Notebook

AWS CLI:

Site Reliability: 5 Engineering Tenets

How to Use the Whatsapp Business API

Git and GitHub In One Go!

A hackathon at Botify

Three Botify Engineers working on their laptops next to each other.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ashley Gaskins

Ashley Gaskins

Data Science student looking for Data Science/Engineering opportunities!

More from Medium

Parametrize the right way in pytest

Only need to commit certain files to Github? .gitignore to the rescue

Application Frameworks- NoSQL and Git

Dynamic Programming On Grids