<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/5-tips-for-writing-cleaner-code-vyqikwvqn" -->

---
title: 5 Tips For Writing Cleaner Code | daily.dev
description: Nesting in code is something we do all the time, and although there&#x27;s nothing inherently wrong with nesting, it can sometimes make code harder to read. The...
canonical: https://daily.dev/posts/5-tips-for-writing-cleaner-code-vyqikwvqn
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: 5 Tips For Writing Cleaner Code | daily.dev
og:description: Nesting in code is something we do all the time, and although there&#x27;s nothing inherently wrong with nesting, it can sometimes make code harder to read. The...
og:url: https://daily.dev/posts/5-tips-for-writing-cleaner-code-vyqikwvqn
og:image: https://api.daily.dev/og/posts/VyQikwVQN.png
og:image:alt: 5 Tips For Writing Cleaner Code
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.

# 5 Tips For Writing Cleaner Code

**[Hashnode](https://daily.dev/sources/hashnode)** · 3 min read · 283 upvotes · 18 comments

## Summary

Nesting in code is something we do all the time, and although there's nothing inherently wrong with nesting, it can sometimes make code harder to read. The "Return Early" design pattern allows us to use the if statement as a guard clause to check for errors and return before executing any further code.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://domtech.hashnode.dev/5-tips-for-writing-cleaner-code>

## Community discussion

Top comments from developers on daily.dev.

**@kkurko** · 3 upvotes

> Cool tips, in general you should follow them, but I think there may be exceptions:
>
> - not so bad to have impure function if side effect is very limited and kinda isolated from other things
> - you can go with not so meaningful names (even with one letter name) if variable have one or two lines scope. Example I can provide is when you have a really long variable name because of the domain/business and you need for example to map an array:
>
> ```
> const arrayOfItemsWithReallyLongNames.map((itemWithReallyLongName) => ...);
>
> ItemsWithReallyLongNames((item) => ...);
> ```
>
> More general and sometimes not...

**@dailydevsv** · 2 upvotes

> The blog gives a very clear idea on how to write clean code. The examples used are easy to understand and follow

**@proteo5** · 1 upvotes

> I love the article, but I strongly disagree with point number 2. Saving code with clever code is harmful and makes it very difficult to debug when issues arise. It seems silly but those extra code help a lot to identify the issues, especially since the real word functions don't have a few lines of code.
> I encourage you to see this article.
> https:// medium. com/@joshuawcomeau/clever-code-considered-harmful-a1fb1054e8a1 Clever code considered harmful

**@maarcusvinicius** · 0 upvotes

> Post very necessary

**@titomitto** · 0 upvotes

> Good tips on making your code clean

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments
- [CNCF Unveils Schedule for KubeCon \+ CloudNativeCon Europe 2026](https://daily.dev/posts/cncf-unveils-schedule-for-kubecon-cloudnativecon-europe-2026-ikhcoa5cb) · CNCF · 2 upvotes · 0 comments
- [CNCF Debuts KubeCon \+ CloudNativeCon Japan 2026 Schedule](https://daily.dev/posts/cncf-debuts-kubecon-cloudnativecon-japan-2026-schedule-xp5pyudub) · CNCF · 1 upvotes · 0 comments

---

Tags: [#general-programming](https://daily.dev/tags/general-programming), [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/5-tips-for-writing-cleaner-code-vyqikwvqn)

```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":"5 Tips For Writing Cleaner Code","url":"https://daily.dev/posts/5-tips-for-writing-cleaner-code-vyqikwvqn","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/5-tips-for-writing-cleaner-code-vyqikwvqn"},"datePublished":"2022-06-01T00:41:22.778Z","dateModified":"2022-06-01T00:41:22.779Z","description":"Nesting in code is something we do all the time, and although there's nothing inherently wrong with nesting, it can sometimes make code harder to read. The...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/85f1a4a81b8516e8ecdb50dda71ef1c6","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/85f1a4a81b8516e8ecdb50dda71ef1c6","isAccessibleForFree":true,"articleSection":"Hashnode","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":"Hashnode","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/4a287b2e7cb5499bae863f8e7137cdb4","url":"https://daily.dev/sources/hashnode"},"commentCount":18,"discussionUrl":"https://daily.dev/posts/5-tips-for-writing-cleaner-code-vyqikwvqn","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":283},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":18}],"keywords":"general-programming,javascript","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Hashnode","item":"https://daily.dev/sources/hashnode"},{"@type":"ListItem","position":3,"name":"5 Tips For Writing Cleaner Code"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/5-tips-for-writing-cleaner-code-vyqikwvqn","comment":[{"@type":"Comment","text":"Cool tips, in general you should follow them, but I think there may be exceptions:\n\nnot so bad to have impure function if side effect is very limited and kinda isolated from other things\nyou can go with not so meaningful names (even with one letter name) if variable have one or two lines scope. Example I can provide is when you have a really long variable name because of the domain/business and you need for example to map an array:\n\nconst arrayOfItemsWithReallyLongNames.map((itemWithReallyLongName) => ...);\n\nItemsWithReallyLongNames((item) => ...);\n\nMore general and sometimes not totally clear name makes it more easier to read, because there is no line breaks","datePublished":"2022-06-03T07:58:01.760Z","dateModified":"2022-06-03T07:58:15.858Z","url":"https://daily.dev/posts/VyQikwVQN#c-RgTx2yaLu","author":{"@type":"Person","name":"Kirill Kurko","url":"https://daily.dev/kkurko","image":"https://avatars.githubusercontent.com/u/58859242?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}},{"@type":"Comment","text":"The blog gives a very clear idea on how to write clean code. The examples used are easy to understand and follow","datePublished":"2022-06-01T03:34:53.556Z","dateModified":"2022-06-01T03:35:15.104Z","url":"https://daily.dev/posts/VyQikwVQN#c-wzap-xZdo","author":{"@type":"Person","name":"Samvedaha Vipasyam","url":"https://daily.dev/dailydevsv","image":"https://lh3.googleusercontent.com/a-/AOh14GhknIOEDMm8LSZ1iKIc-MJb7zg2rPt4jqpsld44=s100"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"I love the article, but I strongly disagree with point number 2. Saving code with clever code is harmful and makes it very difficult to debug when issues arise. It seems silly but those extra code help a lot to identify the issues, especially since the real word functions don’t have a few lines of code.\nI encourage you to see this article.\nhttps:// medium. com/@joshuawcomeau/clever-code-considered-harmful-a1fb1054e8a1 Clever code considered harmful","datePublished":"2022-06-07T17:46:13.885Z","url":"https://daily.dev/posts/VyQikwVQN#c-9LIkd6fGv","author":{"@type":"Person","name":"Alfredo Pinto","url":"https://daily.dev/proteo5","image":"https://lh3.googleusercontent.com/a-/AOh14Gjve6T8sZp0ZcVoofzLeD0FtGgf8ReNrOoXlpwI=s100"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Post very necessary","datePublished":"2022-06-01T10:54:10.640Z","url":"https://daily.dev/posts/VyQikwVQN#c-SlyUAFJCg","author":{"@type":"Person","name":"Marcus Vinicius","url":"https://daily.dev/maarcusvinicius","image":"https://media.daily.dev/image/upload/v1670502158/avatars/avatar_vwO0sxHCzK3EsIh7XsSTh.jpg"}},{"@type":"Comment","text":"Good tips on making your code clean","datePublished":"2022-06-06T23:05:43.916Z","url":"https://daily.dev/posts/VyQikwVQN#c-AdzS_PItx","author":{"@type":"Person","name":"Tito Mitto","url":"https://daily.dev/titomitto","image":"https://lh3.googleusercontent.com/a-/AOh14GjqRzdnfY95og5YT6QlS_h42qZrxaly1rFMcNajsEw=s100"}}]}
```

