<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/2IYKukJHq" -->

---
title: Writing Clean Code: Best Practices and Principles
description: Clean code is code that is easy to read, easy to understand, and easy to modify. Clean code follows a set of conventions and best practices that make it more...
canonical: https://daily.dev/posts/writing-clean-code-best-practices-and-principles-2iykukjhq
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Writing Clean Code: Best Practices and Principles | daily.dev
og:description: Clean code is code that is easy to read, easy to understand, and easy to modify. Clean code follows a set of conventions and best practices that make it more...
og:url: https://daily.dev/posts/writing-clean-code-best-practices-and-principles-2iykukjhq
og:image: https://api.daily.dev/og/posts/2IYKukJHq.png
og:image:alt: Writing Clean Code: Best Practices and Principles
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Writing Clean Code: Best Practices and Principles

**[DEV](https://daily.dev/sources/devto)** · 7 min read · 505 upvotes · 27 comments

## Summary

Clean code is code that is easy to read, easy to understand, and easy to modify. Clean code follows a set of conventions and best practices that make it more consistent, making it easier for multiple developers to work on the same project seamlessly. Code that is difficult to understand is more prone to errors during modifications or enhancements.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://dev.to/favourmark05/writing-clean-code-best-practices-and-principles-3amh>

## Community discussion

Top comments from developers on daily.dev.

**@srcmayte** · 24 upvotes

> Eventually, clean code becomes second nature, like coding itself or riding a bike. It will happen naturally as you start to integrate the concepts into your daily engineering.

**@sudouken** · 13 upvotes

> Core Tenants of Clean Code:
> 1. Meaningful Variable and Function Names
> 1. Keep Functions and Methods Short
> 1. Comments and Documentation
> 1. Consistent Formatting and Indentation
> 1. DRY (Don't Repeat Yourself) Principle
> 1. Use Meaningful Whitespace
> 1. Error Handling
> 1. Testing
> 1. Refactoring
> 1. Version Control
>
> Why?
> 1. Readability
> 1. Maintainability
> 1. Collaboration
> 1. Bug Reduction
> 1. Efficiency

**@eyoung** · 6 upvotes

> The author could probably elaborate on commenting good/bad as it remains a point of debate. I am very much in favour of python style 'docstrings' on all public methods... for two reasons, it can become your application's documentation later and most importantly - it helps to focus your development - what is this portion of code intended to do? If you can't state it in one short docstring comment maybe you're violating single responsibility...
>
> Multiple inline comments that restate what the code is already doing is not good practice.

**@muhammad3bdullah** · 2 upvotes

> I also think that  one of writing clean code's practices that could be shelved below "Readability" is "Writing clear code not clever code".

**@calebdre** · 2 upvotes

> I thought this would be more impactful but each of these points come with experience.
>
> The next level is when you start recognizing structural and behavioral patterns

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#javascript](https://daily.dev/tags/javascript), [#productivity](https://daily.dev/tags/productivity), [#tdd](https://daily.dev/tags/tdd)

[View this post on daily.dev](https://daily.dev/posts/writing-clean-code-best-practices-and-principles-2iykukjhq)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Writing Clean Code: Best Practices and Principles","url":"https://daily.dev/posts/writing-clean-code-best-practices-and-principles-2iykukjhq","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/writing-clean-code-best-practices-and-principles-2iykukjhq"},"datePublished":"2023-09-17T09:15:00.979Z","dateModified":"2023-09-17T09:14:59.418Z","description":"Clean code is code that is easy to read, easy to understand, and easy to modify. Clean code follows a set of conventions and best practices that make it more...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5dc251ace8b1b5e175573b3210a7267c?_a=AQAEufR","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5dc251ace8b1b5e175573b3210a7267c?_a=AQAEufR","isAccessibleForFree":true,"articleSection":"DEV","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"DEV","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/devto","url":"https://daily.dev/sources/devto"},"commentCount":27,"discussionUrl":"https://daily.dev/posts/writing-clean-code-best-practices-and-principles-2iykukjhq","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":505},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":27}],"keywords":"webdev,javascript,productivity,tdd","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"DEV","item":"https://daily.dev/sources/devto"},{"@type":"ListItem","position":3,"name":"Writing Clean Code: Best Practices and Principles"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/writing-clean-code-best-practices-and-principles-2iykukjhq","comment":[{"@type":"Comment","text":"Eventually, clean code becomes second nature, like coding itself or riding a bike. It will happen naturally as you start to integrate the concepts into your daily engineering.","datePublished":"2023-09-18T03:36:22.924Z","dateModified":"2023-10-04T12:43:51.158Z","url":"https://daily.dev/posts/2IYKukJHq#c-ofIHvW3LM","author":{"@type":"Person","name":"Steve Clarke","url":"https://daily.dev/srcmayte","image":"https://media.daily.dev/image/upload/s--4SiyqKlB--/f_auto,q_auto/v1/avatars/avatar_X2IkraOGSjpjDzQSlPT9r"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":24}},{"@type":"Comment","text":"Core Tenants of Clean Code:\n\nMeaningful Variable and Function Names\nKeep Functions and Methods Short\nComments and Documentation\nConsistent Formatting and Indentation\nDRY (Don’t Repeat Yourself) Principle\nUse Meaningful Whitespace\nError Handling\nTesting\nRefactoring\nVersion Control\n\nWhy?\n\nReadability\nMaintainability\nCollaboration\nBug Reduction\nEfficiency","datePublished":"2023-09-21T03:59:53.024Z","dateModified":"2023-09-21T04:02:51.539Z","url":"https://daily.dev/posts/2IYKukJHq#c-uUMcytd3j","author":{"@type":"Person","name":"Matthew","url":"https://daily.dev/sudouken","image":"https://media.daily.dev/image/upload/s--jRwVjerf--/f_auto/v1755725028/avatars/avatar_l1V0jO5VncYwbcQDE0JQ1?_a=BAMClqZW0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":13}},{"@type":"Comment","text":"The author could probably elaborate on commenting good/bad as it remains a point of debate. I am very much in favour of python style ‘docstrings’ on all public methods… for two reasons, it can become your application’s documentation later and most importantly - it helps to focus your development - what is this portion of code intended to do? If you can’t state it in one short docstring comment maybe you’re violating single responsibility…\nMultiple inline comments that restate what the code is already doing is not good practice.","datePublished":"2023-09-18T14:53:46.032Z","dateModified":"2023-09-18T14:54:33.809Z","url":"https://daily.dev/posts/2IYKukJHq#c-0LAb26GWJ","author":{"@type":"Person","name":"Evan Young","url":"https://daily.dev/eyoung","image":"https://media.daily.dev/image/upload/s--XunRJpDX--/f_auto/v1762793954/avatars/avatar_Vm1vw9EGTkV8xCvGaCMtP?_a=BAMAK+ZW0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":6}},{"@type":"Comment","text":"I also think that  one of writing clean code’s practices that could be shelved below “Readability” is “Writing clear code not clever code”.","datePublished":"2023-09-19T15:43:56.038Z","url":"https://daily.dev/posts/2IYKukJHq#c-RkIkQ4BYd","author":{"@type":"Person","name":"Muhammad Abdullah","url":"https://daily.dev/muhammad3bdullah","image":"https://media.daily.dev/image/upload/s--SPXhZtkO--/f_auto,q_auto/v1695193929/avatars/avatar_0fyplyAEHnR1xUoIk0dtU"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"I thought this would be more impactful but each of these points come with experience.\nThe next level is when you start recognizing structural and behavioral patterns","datePublished":"2023-09-20T04:54:57.019Z","url":"https://daily.dev/posts/2IYKukJHq#c-MSBINDrPV","author":{"@type":"Person","name":"Caleb Lewis","url":"https://daily.dev/calebdre","image":"https://avatars.githubusercontent.com/u/3318929?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}}]}
```

