DEV Community

Cover image for Top 10 Clean Code Rules 🎨🚀

Top 10 Clean Code Rules 🎨🚀

Anik Dash Akash on September 05, 2024

When writing code, it's like writing a story. A good story is easy to read, and you understand what's happening right away. The same goes for code!...
Collapse
 
martinbaun profile image
Martin Baun

In general I try to make my code readable and clean in the sense that it follows a consistent pattern that others can follow and replicate. (edit) patterns like SOLID can help accomplish that goal. Great tips, always stay learning! :)

Collapse
 
anikakash profile image
Anik Dash Akash

Best wishes keep maintaining best practices

Collapse
 
martinbaun profile image
Martin Baun

Thank you! :)

Collapse
 
pinotattari profile image
Riccardo Bernardini

For example, instead of 12, use numberOfMonthsInAYear. This way, everyone knows what that number means!

Moreover, it will be easier to change when the number of months will change. (Who knows? Maybe a new French Revolution will introduce 13 28-day months) 😉 (Sorry, I couldn't resist)

Collapse
 
hectorw_tt profile image
Hector Williams

Good article!!!! I have a question though.Does refactoring violate the open-closed principle of the SOLID principles?

Collapse
 
anikakash profile image
Anik Dash Akash

@hectorw_tt No refactoring does not violate the open-closed principle of the SOLID. The OCP says software should be "open for extension but closed for modification." When you refactor, you're not adding new features or changing the code's behaviour. Instead, you're just improving the existing code to make it cleaner or more efficient without altering how it works. So, refactoring is still "closed for modification" because it doesn't change the functionality, it just makes the code better.

Collapse
 
andrewbaisden profile image
Andrew Baisden

Those are great tips. I'm doing this most of the time I work on projects.

Collapse
 
anikakash profile image
Anik Dash Akash

@andrewbaisden that's great. I'm open to work and collaboration feel free to knock me.

Collapse
 
ezekiel_77 profile image
Ezekiel • Edited

Personally the hardest tip for me to maintain is keeping functions small and DRY principles especially when your code interacts with external objects like an API or a network

Collapse
 
daniel27 profile image
Daniel D

Every point is to the point!

Collapse
 
anikakash profile image
Anik Dash Akash

Thanks

Collapse
 
eustachi0 profile image
Eustachio

I love this article. Thanks for sharing.

Collapse
 
anikakash profile image
Anik Dash Akash

Thanks