Top 10 Clean Code Rules

According to “Clean code” book by Robert C, he defined some guidances and rules that developers should follow. This is more imperative for the less experienced developers. With more experience, comes the possibility of breaking some rules or reinventin…


This content originally appeared on DEV Community and was authored by Abdullah

According to “Clean code” book by Robert C, he defined some guidances and rules that developers should follow. This is more imperative for the less experienced developers. With more experience, comes the possibility of breaking some rules or reinventing them with justifications.

No code comments.

A good code needs no comment. The variables, methods, and any other component of the code such as attributes should use easily identifiable and descriptive names.

“Code comments are smell, remove them.”

Dead comments or code should be deleted.

Any unused piece of code or comments should be deleted. The best place to find them is in the version control systems.

Incorrect behaviour at boundaries.

Boundaries should always be unit tested. No behaviour should be assumed.

Positive conditionals.

Positive conditionals are easier to read than negative conditionals.

Standard architecture, coding, and design guidelines should be followed.

All the set standard architecture, coding, and design guidelines should be adhered to. Tools should also be used to ensure that this is accurate.

Good and Consistent naming.

Try to call variables, methods, classes to be understandable from the caller perspective. And it should be consistent.

KISS principle should be applied.

Needless complexity should be avoided. With increase in complexity, some design and codes in the system become useless. All designs and codes should be kept as simple as possible.

Use of exceptions instead of return codes.

In exceptional cases, an exception should be thrown, when the method fails to do its intended purpose. Null or return codes shouldn’t be used.

Make things small. Class size and method size both matter.

Typically, method should be small and compact in size. Ideally, <100 lines of code.

Boy scout rule- Leave the campground cleaner than you found it.

Leave the campground cleaner than you found it. Don’t ask for permission to refactor the code.

Thank you for stopping by and see you in the next.


This content originally appeared on DEV Community and was authored by Abdullah


Print Share Comment Cite Upload Translate Updates
APA

Abdullah | Sciencx (2025-03-09T00:00:04+00:00) Top 10 Clean Code Rules. Retrieved from https://www.scien.cx/2025/03/09/top-10-clean-code-rules-2/

MLA
" » Top 10 Clean Code Rules." Abdullah | Sciencx - Sunday March 9, 2025, https://www.scien.cx/2025/03/09/top-10-clean-code-rules-2/
HARVARD
Abdullah | Sciencx Sunday March 9, 2025 » Top 10 Clean Code Rules., viewed ,<https://www.scien.cx/2025/03/09/top-10-clean-code-rules-2/>
VANCOUVER
Abdullah | Sciencx - » Top 10 Clean Code Rules. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/09/top-10-clean-code-rules-2/
CHICAGO
" » Top 10 Clean Code Rules." Abdullah | Sciencx - Accessed . https://www.scien.cx/2025/03/09/top-10-clean-code-rules-2/
IEEE
" » Top 10 Clean Code Rules." Abdullah | Sciencx [Online]. Available: https://www.scien.cx/2025/03/09/top-10-clean-code-rules-2/. [Accessed: ]
rf:citation
» Top 10 Clean Code Rules | Abdullah | Sciencx | https://www.scien.cx/2025/03/09/top-10-clean-code-rules-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.