Better Programming

Advice for programmers.

Follow publication

Want To Improve Code Readability? — Here Are 5 Rules

Code readability is a feature of your application (even if your users don’t see it)

RayRay
Better Programming
Published in
5 min readNov 17, 2020

Pair of glasses sitting on a laptop
Photo by Jesus Kiteque on Unsplash.

I have five rules to improve code readability. I’ve learned them in all kinds of projects, teams, and organizations. I hope that you can pick some things from this article to improve your code readability.

TL;DR

To all of you searching for quick tips without reading everything, read the TL;DR version below:

  1. Reuse what will be used more than once.
  2. Readability and maintainability over a generic solution.
  3. Make modules, classes, or components as small as possible.
  4. Have rules and guidelines for your code.
  5. Code like you’re in a team — even a one-person team.

1. Reuse What Will Be Used More Than Once

Most developers know what D.R.Y. means (Don’t Repeat Yourself). D.R.Y. can help you prevent code duplication.

Why write a function over and over again? You should write it once and reuse it in multiple places. If you need to change that code, you only have to look in one place instead of copy-pasting a bug fix in multiple places.

But be aware that you will introduce complexity with D.R.Y. because, in the end, things will be reused more and more.

The importance of writing tests when reusing parts of your code will be very clear when you start changing that code.

2. Readability and Maintainability Over a Generic Solution

Reusability, readability, and maintainabilities are each other’s friends and enemies simultaneously. When you start applying D.R.Y. to your code, you introduce complexity. When you introduce complexity, the readability grade can go down.

So don’t start with a generic solution when building features. Start simple! The first time can’t be perfect.

You can reuse parts of the application through iterations but still guard the readability and maintainability.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

RayRay
RayRay

Written by RayRay

I’m a 🇳🇱 Tech Lead (frontend) who writes about AI | JavaScript | TypeScript | Vuejs | Design Systems | NuxtJS | CSS | https://www.youtube.com/@devbyray

No responses yet

Write a response