How to write Clean Code

How to write Clean Code

Almost a myth

Introduction

Whatever project you are working on or code snippet you've written, it will require others or the future you to understand what you have written, either to improve on it or get rid of it in a way it doesn't break much.

Though a perfectly clean code is almost impossible, there are a few ways, in which if we write our code, it makes it easier to read, and enable the reader to visualize and better understand the code, Thus reducing time and cost.

Structure

a well-structured code base or code can be the heart of clean code because this creates a flexible architecture. This makes navigating the codebase and debugging super easy.

Improving the code becomes super handy, adding new feature can't get easier and tackling issues become a piece of cake.

Grouping related files into folders and related functions in a file creates a cleaner code and allows a smoother understanding of the code.

Sorting your code alphabetically doesn't count, if they are not related.

Naming

Naming if not over-exaggerated can be the core of clean code. Wisely choosing names, not just variables and functions, but also files and folders.

A well-named code can be understood just by skimming through the code without having to deeply concentrate on understanding what each variable and function does. Good naming automatically creates a better structure.

Explain you code

Most would say comment your code, which is actually the correct term, but keep in mind that you need to explain your code, however, helps your to brain imagine communicating the code with someone else, Thus helping you write better comments.

Comments in your code set the mind of the reader on what to expect or can even help visualize the code without going through the code itself, this also helps future you understand what you've written.

Note: don't write comments which, a small change in code will make it invalid.

Conclusion

It is worth spending the time to write clean code, this speeds up development and maintenance for the long run.

Try as much as possible to plan before hitting the keyboard and avoid writing useless comments, so you don't have to maintain comments as well.

Clean code doesn't mean suppressing your wildest idea or solution to a problem but implementing it in the most human-readable way.

Happy Coding!