DEV Community

Cover image for How to write clean code

How to write clean code

Programming with Shahan on October 23, 2024

Why Write Clean Code? ⛩️ Imagine if you tried to find something in a messy room—you'd waste time searching, right? The same goes for ...
Collapse
 
martinbaun profile image
Martin Baun

I'm glad to see this being highlighted yet again! I'm not quite sure where the hostility to code structures beyond "just code it bro" come from, but I have had to see some pretty horrific codebases and so am happy to see ANY kind of overarching structure in a codebase being talked about!

Collapse
 
codewithshahan profile image
Programming with Shahan

Clean code is the key to override headache!

Collapse
 
martinbaun profile image
Martin Baun

🤣🤣

Collapse
 
charles_roth_8c0df94d211a profile image
Charles Roth

Read "Uncle Bob"s book "Clean Code". The chapter on "code smells" by itself is worth the price of admission.

Comments: always have a comment block at the top of the module/package/class/whatever, describing WHY this (whatever) exists -- what is its purpose? Not HOW it works, but WHY it exists. Give the next person to touch it the context needed to understand it.

Collapse
 
codewithshahan profile image
Programming with Shahan

I always loved Uncle Bob's clean code technics. He is the best. My teacher Mosh (programming with mosh) always followed him as well.

Collapse
 
mdanielcooper profile image
Daniel Cooper 🇺🇸🦅

Going back to "Code Complete" being one of my favorite books when it comes to programming. During my career (going on 20+ years) I had to learn some of this the hard way trying to decipher code that I myself had written after not looking at it for a few years.

Recently had to go back and work on a program I wrote just 7 years ago and it was very easy to modify and make changes to the program because I used common sense when designing it. Take the time to refactor your code into functions where able and it makes sense. Then your subroutines can be a few lines long, with easy sections to troubleshoot.

Collapse
 
generator_garimu profile image
Garimu Alonso

Thanks for this! Saving it! 💖

Collapse
 
codewithshahan profile image
Programming with Shahan

You're most welcome!

Collapse
 
goodnewsdaniel profile image
Goodnews Daniel

Awesome! Thank you

Collapse
 
codewithshahan profile image
Programming with Shahan

Glad to hear that!

Collapse
 
berat_yilmaz_1ecd69d72810 profile image
Berat Yilmaz

Read the „ Refactoring“ book for the beginning.

Collapse
 
odeshpande7 profile image
Omkar Deshpande

Elegant and crisp explanatiom

Collapse
 
codewithshahan profile image
Programming with Shahan

Thank you for your feedback!

Collapse
 
farhad_nadimi_be71c6e116d profile image
Farhad Nadimi

Thank you for useful information

Collapse
 
codewithshahan profile image
Programming with Shahan

You're welcome

Collapse
 
b0lt_5 profile image
Ayoola Kitan

very helpful for us beginners

Collapse
 
codewithshahan profile image
Programming with Shahan

Yes, I know!

Collapse
 
mckwen2 profile image
McKwen2

Nice. Thank you.

Collapse
 
codewithshahan profile image
Programming with Shahan

You're most welcome!

Collapse
 
fxfeedio profile image
FxFeed

Nice!

Collapse
 
codewithshahan profile image
Programming with Shahan

Thanks