{"id":1302,"date":"2025-07-22T02:44:32","date_gmt":"2025-07-21T19:44:32","guid":{"rendered":"https:\/\/kienthucmo.com\/clean-code-the-art-of-writing-clean-and-sustainable-code-in-software-development\/"},"modified":"2025-10-24T20:27:35","modified_gmt":"2025-10-24T13:27:35","slug":"clean-code-the-art-of-writing-clean-and-sustainable-code-in-software-development","status":"publish","type":"post","link":"https:\/\/kienthucmo.com\/en\/clean-code-the-art-of-writing-clean-and-sustainable-code-in-software-development\/","title":{"rendered":"Clean Code: The Art of Writing Clean and Sustainable Code in Software Development"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>There\u2019s a sad truth that every developer has experienced: <strong>just because code runs doesn\u2019t mean it\u2019s good code<\/strong>. Hmm\u2026 it\u2019s true. You might write a piece of code that works perfectly today, but return just two weeks later and, not believing your eyes, you\u2019ll ask yourself:<br><em>\u201cHmm\u2026 did I really write this mess\u2026!?\u201d<\/em><br><\/p>\n<\/blockquote>\n\n\n\n<p>Don\u2019t worry (well, maybe worry a little), welcome to the world of <strong>Clean Code<\/strong> \u2014 where code not only \u201cruns,\u201d but is also \u201creadable,\u201d \u201cunderstandable,\u201d and \u201cmaintainable without going crazy.\u201d<\/p>\n\n\n\n<p>On the journey to becoming a super-level VIP pro developer, where colleagues no longer fear reading your code, clean code is a secret weapon. It helps you:\r\n<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Avoid writing code that your future self will be horrified by.<\/li>\n\n\n\n<li>Teamwork is no longer a nightmare.<\/li>\n\n\n\n<li>Easy to debug, easy to extend, and most importantly\u2026 easy to live with.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Clean code is not a mystical or overly academic concept. It\u2019s a way to <strong>treat yourself and others on your team kindly<\/strong>.<br><\/p>\n<\/blockquote>\n\n\n\n<p>In this article, I will walk you through:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Decoding what Clean Code is and why it matters.<\/li>\n\n\n\n<li>Go through the essential principles like <strong>DRY<\/strong>, <strong>KISS<\/strong>, <strong>SOLID<\/strong> (sounds a bit academic but is actually easy to understand, though whether you can apply them in practice is another question).<\/li>\n\n\n\n<li>Look back at the \u201clegendary\u201d mistakes that everyone has made when writing messy code.<\/li>\n\n\n\n<li>And finally, review the well-curated materials from coding \u201cveterans,\u201d distilled from the pain and mistakes that you or your colleagues may have caused.\r\n<\/li>\n<\/ul>\n\n\n\n<p>And now\u2026 let\u2019s clean up that spaghetti code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is Clean Code?<\/h2>\n\n\n\n<p>The concept of <strong>\u201cClean Code\u201d<\/strong> was introduced and popularized by <strong>Robert C. Martin<\/strong>, commonly known by the nickname <strong>Uncle Bob<\/strong> \u2013 one of the \u201cliving legends\u201d in the software development industry. In his book <em>Clean Code: A Handbook of Agile Software Craftsmanship<\/em>, he defines:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u201cClean code always looks like it was written by someone who cares.\u201d<\/p>\n<\/blockquote>\n\n\n\n<p>In other words, <strong>clean code is code written with respect for the next reader<\/strong> \u2013 whether it be a colleague, a client, or yourself after several sleepless weeks due to a deadline.<br><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/i.pinimg.com\/736x\/43\/74\/05\/437405ce89a86caaa76427e8fa4fe008.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/i.pinimg.com\/736x\/43\/74\/05\/437405ce89a86caaa76427e8fa4fe008.jpg\" alt=\"What is Clean Code?\"\/><\/a><\/figure>\n<\/div>\n\n\n<h4 class=\"wp-block-heading\">So, what are the characteristics of clean code?<\/h4>\n\n\n\n<p>A piece of code is considered \u201cclean\u201d if it usually:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Readable<\/strong>: You can understand what the code is doing at a glance without having to guess.<\/li>\n\n\n\n<li><strong>Understandable<\/strong>: Variables, functions, and classes all have clear and consistent names.<\/li>\n\n\n\n<li><strong>Easy to modify<\/strong>: When adding new features, you don\u2019t have to &#8220;tear down and rebuild&#8221; the code.<\/li>\n\n\n\n<li><strong>Easy to test<\/strong>: Clean code usually separates logic clearly, making it easy to write unit tests.<\/li>\n\n\n\n<li><strong>Not tangled<\/strong>: Minimal repetition, no messy dependencies, and no \u201chard-coded\u201d values.<\/li>\n<\/ul>\n\n\n\n<p>On the other hand, <strong>bad code<\/strong> is the kind that makes people exclaim after reading it:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u201cHmm&#8230;me keep&#8230;!!!\u201d<\/p>\n<\/blockquote>\n\n\n\n<p>Or they might remain silent, but their facial expressions and eyes&#8230; tell a different story.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Why is the definition of clean code important?<\/h4>\n\n\n\n<p>Because it is the foundation of every high-quality software project. A system can have thousands of lines of code \u2014 if it\u2019s not clean from the start, every fix becomes a \u201cjanitor cosplay,\u201d digging through a pile of chaos. This wastes time, breeds new bugs, and makes long-term development difficult.\r\n\r\n<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. The Importance, Role, and Benefits of Clean Code<\/h2>\n\n\n\n<p>Writing <strong>clean code<\/strong> isn\u2019t just a good habit \u2014 it\u2019s the foundation for building software that can grow sustainably, both technically and humanly. Below are the reasons why clean code should be considered the \u201ctop priority\u201d in any serious software project.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.1. Enhancing Project Sustainability<\/h3>\n\n\n\n<p>A software project is never \u201cfinished once and for all.\u201d It constantly evolves \u2014 adding new features, fixing bugs, optimizing performance, supporting new platforms, and more. That\u2019s why the code must be easy to modify without breaking the entire system.\r\n<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Clean code helps you refactor with confidence.<\/p>\n<\/blockquote>\n\n\n\n<p>For example, if modules are written clearly and without messy dependencies, updating an API or processing logic only requires changes in the right place. Conversely, if the code is tangled, every fix is like &#8220;pulling a strand of spaghetti&#8221; \u2013 easily causing everything to get messed up.\r\n<\/p>\n\n\n\n<p><strong>Clean code<\/strong> also helps new team members onboard faster. Instead of spending weeks trying to figure out \u201cwhat this code does,\u201d a newcomer can grasp the logic just by reading it \u2014 thanks to clear naming, an easy-to-follow structure, and well-divided functions by purpose.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.2. Increasing Productivity and Reliability<\/h3>\n\n\n\n<p><strong>Clean code<\/strong> isn\u2019t written faster, but it can be read faster, debugged faster, and makes work more efficient in the long run.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When functions are concise and variables are clearly named, developers are less likely to make mistakes during debugging or feature expansion.\r\n\r\n<\/li>\n\n\n\n<li>When code is easy to test (thanks to clear separation of logic), writing unit tests or setting up CI\/CD becomes simpler \u2013 reducing the chances of bugs leaking into production.\r\n<\/li>\n\n\n\n<li>When an error occurs, <strong>clean code<\/strong> makes it easier to identify the cause, since each part of the system is clearly structured and well-isolated.<\/li>\n<\/ul>\n\n\n\n<p>A familiar saying in the programming community:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u201cWe read code more often than we write it. So why not write it to be easy to read?\u201d<\/p>\n<\/blockquote>\n\n\n\n<p><strong>Clean code<\/strong> saves you hours every week simply because\u2026 you spend less time guessing what the code does.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.3. Strengthening Teamwork Spirit and Idea Communication<\/h3>\n\n\n\n<p>Whether you work in a 3-person startup or a 3000-person corporation, software is always <strong>a collaborative product<\/strong>. And the source code is the common language among developers.<\/p>\n\n\n\n<p>When someone writes clean code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Others can immediately understand the purpose of the code.<\/li>\n\n\n\n<li>There are fewer misunderstandings when modifying someone else\u2019s code.<\/li>\n\n\n\n<li>Easier to review pull requests and give feedback.<\/li>\n\n\n\n<li>Relationships with colleagues improve significantly.<\/li>\n<\/ul>\n\n\n\n<p>This not only improves communication within the team but also fosters a culture of mutual respect. Clean code is a way to show responsibility \u2014 first to yourself, and then to your teammates.\r\n\r\n<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Writing clean code is an act of \u201chelping others understand you\u201d \u2013 one of the most important skills in teamwork.\r\n<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">2.4. (Additional) Reducing Long-term Development Costs<\/h3>\n\n\n\n<p>This is a benefit that\u2019s rarely mentioned but highly practical: clean code helps reduce the cost of maintenance, bug fixes, and new feature development.\r\n<\/p>\n\n\n\n<p>Many companies fall into the trap where, the longer a project runs, the messier the code becomes. Every change risks \u201cbreaking the chain,\u201d leading to stagnation. At that point, the cost of merely \u201ckeeping the project alive\u201d far exceeds the cost of rewriting it from scratch \u2014 all because clean code wasn\u2019t maintained from the very beginning.\r\n\r\n<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Core Principles of Clean Code<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 Meaningful Naming<\/h3>\n\n\n\n<p><strong>Why it\u2019s important:<\/strong><br>Variable, function, and class names act as the first layer of documentation for your code. Clear, descriptive names help others (and your future self) quickly understand the purpose and behavior without reading every line. Poorly chosen names force readers to trace logic manually, slow down comprehension, and increase the risk of misusing or misunderstanding the code.<\/p>\n\n\n\n<p><strong>Bad example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>def g(u):\n    return u.split('@')&#91;1&#93;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">g<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">u<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> u<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">split<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">@<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">)&#91;<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Good example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>def get_user_email_domain(email):\n    return email.split('@')&#91;1&#93;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">get_user_email_domain<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">email<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> email<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">split<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">@<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">)&#91;<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>You can understand the function\u2019s purpose immediately without having to look into the details.<\/p>\n<\/blockquote>\n\n\n\n<p><strong>Avoid:<\/strong> using vague abbreviations (<code>dt<\/code>, <code>tmp<\/code>, <code>i2<\/code>) or generic names (<code>data<\/code>, <code>process<\/code>).<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 Do One Thing (Each function should do only one thing)<\/h3>\n\n\n\n<p><strong>Why it\u2019s important:<\/strong><br>Functions that try to handle too many responsibilities become harder to understand, test, and maintain. When logic is tightly coupled inside a large function, even a small change can have unintended side effects elsewhere. Breaking complex logic into smaller, focused functions improves readability, reduces bugs, and makes the codebase easier to extend in the future.<\/p>\n\n\n\n<p><strong>Bad example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>function handleOrder(order) {\n    validateOrder(order);\n    saveOrderToDatabase(order);\n    sendConfirmationEmail(order);\n    generateInvoice(order);\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">handleOrder<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">validateOrder<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">saveOrderToDatabase<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">sendConfirmationEmail<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">generateInvoice<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Good example:<\/strong><br>Break it down:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>function validateOrder(order) { ... }\nfunction saveOrder(order) { ... }\nfunction sendEmail(order) { ... }\nfunction generateInvoice(order) { ... }\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">validateOrder<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> ... <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">saveOrder<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> ... <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">sendEmail<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> ... <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">generateInvoice<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> ... <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3.3  DRY (Don\u2019t Repeat Yourself)<\/h3>\n\n\n\n<p><strong>Why it\u2019s important:<\/strong><br>Code repetition means you\u2019ll need to update the same logic in multiple places whenever a change is required. This not only increases the chance of missing one or more spots but also makes debugging and maintenance more time-consuming. Over time, duplicated code leads to inconsistencies and unpredictable behavior across the project.<\/p>\n\n\n\n<p><strong>Bad example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>price_with_tax = price + price * 0.1\n# \u1ede ch\u1ed7 kh\u00e1c l\u1ea1i vi\u1ebft y chang\ntotal = amount + amount * 0.1<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">price_with_tax <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> price <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> price <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0.1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"># \u1ede ch\u1ed7 kh\u00e1c l\u1ea1i vi\u1ebft y chang<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">total <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> amount <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> amount <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0.1<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Good example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>def add_tax(amount):\n    TAX_RATE = 0.1\n    return amount + amount * TAX_RATE<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">add_tax<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">amount<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    TAX_RATE <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0.1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> amount <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> amount <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> TAX_RATE<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3.4  Commenting Correctly<\/h3>\n\n\n\n<p><strong>Principle:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explain the \u201cwhy\u201d, not just the \u201cwhat\u201d.<\/strong><br>Comments should describe the reasoning or intent behind the code \u2014 why a certain approach was chosen or why an exception is handled in a specific way. This helps future developers understand the context and avoid repeating the same mistakes.<\/li>\n\n\n\n<li><strong>Clear code doesn\u2019t need line-by-line comments.<\/strong><br>When code is well-structured and uses meaningful names, it naturally explains itself. Excessive inline comments only add noise and quickly become outdated as the code evolves.<\/li>\n<\/ul>\n\n\n\n<p><strong>Bad example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ Add 1 to the **count** variable.\ncount = count + 1;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">\/\/<\/span><span style=\"color: #D8DEE9FF\"> Add <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\"> to the <\/span><span style=\"color: #81A1C1\">**<\/span><span style=\"color: #D8DEE9FF\">count<\/span><span style=\"color: #81A1C1\">**<\/span><span style=\"color: #D8DEE9FF\"> variable<\/span><span style=\"color: #ECEFF4\">.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">count <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> count <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Good example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ Add 1 to the count to include the current item.\ncount += 1;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">\/\/<\/span><span style=\"color: #D8DEE9FF\"> Add <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\"> to the count to include the current item<\/span><span style=\"color: #ECEFF4\">.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">count <\/span><span style=\"color: #81A1C1\">+=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3.5  KISS (Keep It Simple, Stupid)<\/h3>\n\n\n\n<p><strong>Why it matters:<\/strong><br>The simpler the solution, the easier it is to maintain. Over-engineering (using complex design when it\u2019s not needed) will make you a \u201cvictim\u201d of your own creation.<\/p>\n\n\n\n<p><strong>Bad example:<\/strong> Using microservices for a TODO app with 1-2 users.<br><strong>Good example:<\/strong> Using a simple script or monolith until there is a real need to separate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.6  Early Return<\/h3>\n\n\n\n<p><strong>Why it matters:<\/strong><br>Reduces the depth of <code>if\/else<\/code>, making the code flatter and easier to read.<\/p>\n\n\n\n<p><strong>Bad example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>if (user != null) {\n    if (user.isActive()) {\n        sendEmail(user);\n    }\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user <\/span><span style=\"color: #81A1C1\">!=<\/span><span style=\"color: #D8DEE9FF\"> null<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">isActive<\/span><span style=\"color: #ECEFF4\">())<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #88C0D0\">sendEmail<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Good example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>if (user == null) return;\nif (!user.isActive()) return;\nsendEmail(user);<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\"> null<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">!<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">isActive<\/span><span style=\"color: #ECEFF4\">())<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">sendEmail<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3.7  SOLID Principles (OOP)<\/h3>\n\n\n\n<p>The 5 object-oriented design principles help make systems easier to extend and maintain:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>S<\/strong>ingle Responsibility \u2013 Each class should have only one responsibility.<\/li>\n\n\n\n<li><strong>O<\/strong>pen\/Closed \u2013 Open for extension, closed for modification.<\/li>\n\n\n\n<li><strong>L<\/strong>iskov Substitution \u2013 A subclass can replace its parent class without breaking the logic.<\/li>\n\n\n\n<li><strong>I<\/strong>nterface Segregation \u2013 Small, specialized interfaces.<\/li>\n\n\n\n<li><strong>D<\/strong>ependency Inversion \u2013 Depend on abstractions, not on implementations.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">3.8  Writing Automated Tests<\/h3>\n\n\n\n<p><strong>Why it matters:<\/strong><br>Code without tests is like a \u201cbridge without handrails\u201d \u2013 it can still be used, but it&#8217;s risky. Tests help to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Early bug detection<\/li>\n\n\n\n<li>Confidence when refactoring<\/li>\n\n\n\n<li>Ensure the code works as expected<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.9 YAGNI (You Aren\u2019t Gonna Need It)<\/h3>\n\n\n\n<p><strong>Meaning:<\/strong><br>Don\u2019t write code for features that \u201cmight be needed in the future\u201d when there\u2019s no real requirement yet.<br>Developers often tend to \u201cadd just in case\u201d \u2192 this leads to increased complexity and harder maintenance.<\/p>\n\n\n\n<p>Learn more: <a href=\"http:\/\/[https:\/\/kienthucmo.com\/vi\/kiss-dry-yagni-3-nguyen-tac-vang-trong-phat-trien-phan-mem\/\">KISS, DRY, YAGNI \u2013 3 Golden Principles in Software Development<\/a><br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.10 Separation of Concerns<\/h3>\n\n\n\n<p><strong>\u00dd ngh\u0129a:<\/strong><br>M\u1ed7i module\/class n\u00ean gi\u1ea3i quy\u1ebft m\u1ed9t \u201cm\u1ed1i quan t\u00e2m\u201d (concern) duy nh\u1ea5t. Giao di\u1ec7n UI kh\u00f4ng n\u00ean x\u1eed l\u00fd logic business, v\u00e0 ng\u01b0\u1ee3c l\u1ea1i.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Controller layer receives the request \u2192<\/li>\n\n\n\n<li>Delegates business logic to the Service layer \u2192<\/li>\n\n\n\n<li>The Repository accesses the data.<\/li>\n<\/ul>\n\n\n\n<p>This approach helps you modify one part without breaking the entire system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.11 Law of Demeter (Principle of Least Knowledge)<\/h3>\n\n\n\n<p><strong>Meaning:<\/strong><br>An object should only communicate with its \u201cclose neighbors\u201d and should not know too much about the internal structure of other objects.<br>\u2192 Reduces coupling, increases maintainability.<br><strong>Bad example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>order.customer.address.city.name<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">customer<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">address<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">city<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">name<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This creates a long dependency chain; changing any layer can cause cascading errors.\r\n<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.12 Frequent Refactoring<\/h3>\n\n\n\n<p><strong>Meaning:<\/strong><br>Clean code doesn\u2019t happen by accident \u2014 it\u2019s the result of continuous improvement. After passing tests, take time to refine names, split functions, and eliminate duplication.<br>Refactoring early helps prevent the buildup of \u201ctechnical debt.\u201d<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.13 Defensive Programming<\/h3>\n\n\n\n<p><strong>Meaning:<\/strong><br>Assume inputs can always be incorrect and handle edge cases from the start \u2192 avoid unpredictable bugs.<br><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>function divide(a, b) {\n    if (b === 0) throw new Error(\"Cannot divide by zero\");\n    return a \/ b;\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">divide<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">a<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> b<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">b <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\">= <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> throw new <\/span><span style=\"color: #88C0D0\">Error<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Cannot divide by zero<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> a <\/span><span style=\"color: #81A1C1\">\/<\/span><span style=\"color: #D8DEE9FF\"> b;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Note: When not to apply extreme measures<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Excessive DRY<\/strong> \u2192 creates confusing abstractions, reduces readability.<\/li>\n\n\n\n<li><strong>Excessive KISS<\/strong> \u2192 overly simple solutions, lacking flexibility when requirements change.<\/li>\n\n\n\n<li><strong>Overly strict YAGNI<\/strong> \u2192 sometimes neglects proper architectural preparation, leading to costly refactoring.<\/li>\n\n\n\n<li>Applying <strong>SOLID<\/strong> principles in the wrong context \u2192 makes code more complex than the actual benefit.<\/li>\n\n\n\n<li>&#8230;<\/li>\n<\/ul>\n\n\n\n<p>Learn more: <a href=\"https:\/\/kienthucmo.com\/en\/what-is-solid-principles-how-it-works-and-practical-applications\/\">[What is SOLID? Principles, how it works, and practical applications]<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Official Clean Code Standards\/Documentation<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Documents \/ Standards<\/th><th>Main Content<\/th><th>Practical Value \/ Application<\/th><\/tr><\/thead><tbody><tr><td><strong>Clean Code \u2013 Robert C. Martin<\/strong><\/td><td>A classic book introducing the concept of clean code, naming conventions, organizing functions and classes, error handling, writing comments, and many principles to make code readable and maintainable.\r\n<\/td><td>It is a \u201cmust-have\u201d book for programmers. It should be read slowly and applied chapter by chapter to real projects.\r\n<\/td><\/tr><tr><td><strong>The Clean Coder \u2013 Robert C. Martin<\/strong><\/td><td>It does not focus on coding techniques but discusses the mindset, attitude, responsibility, and professional ethics of software developers.\r\n<\/td><td>Helps build a serious mindset, teaches how to say \u201cno\u201d to unreasonable requests, and protects code quality.\r\n<\/td><\/tr><tr><td><strong>Refactoring \u2013 Martin Fowler<\/strong><\/td><td>Presents detailed \u201crefactoring patterns\u201d \u2013 ways to improve code without changing behavior, along with reasons and strategies.\r\n<\/td><td>Extremely useful when cleaning up old code or optimizing architecture. Works well in combination with automated testing.\r\n<\/td><\/tr><tr><td><strong>Google Style Guides<\/strong><\/td><td>Coding style standards for languages such as Python, Java, JavaScript, C++, etc. Includes naming conventions, code formatting, commenting, and file organization.\r\n<\/td><td>Helps teams maintain a consistent, readable code style. Can be applied directly or customized for internal projects.\r\n<\/td><\/tr><tr><td><strong>SOLID Principles<\/strong><\/td><td>5 object-oriented design principles: Single Responsibility, Open\/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion.\r\n<\/td><td>Improves the scalability and maintainability of OOP systems. Should be learned alongside practical examples to avoid extreme application.\r\n<\/td><\/tr><tr><td><strong>DRY \/ KISS \/ YAGNI<\/strong><\/td><td>Three foundational principles: avoid code duplication (DRY), keep solutions simple (KISS), and don\u2019t write what\u2019s not needed (YAGNI).\r\n<\/td><td>Helps keep code concise, readable, and reduces maintenance costs.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">5. Common mistakes when writing non-clean code<\/h2>\n\n\n\n<p>Although everyone wants their code to be clear and maintainable, in reality, many developers \u2014 especially when working under time pressure \u2014 often make basic mistakes that lead to messy, hard-to-read, and difficult-to-extend code. These mistakes not only affect individual productivity but also make maintenance and new feature development harder for the entire team. Below are some common mistakes frequently encountered:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using vague or meaningless variable\/function names: Names like data, temp, or handle() make it unclear what their purpose is. Names should clearly convey the role and meaning of the variable or function.<\/li>\n\n\n\n<li>Writing overly long or deeply nested functions: A function that does too many things makes maintenance and testing difficult. Break it down into smaller functions, each responsible for a single, clear task.<\/li>\n\n\n\n<li>Duplicate code, hard to test: Copying the same code in multiple places increases the risk of errors and makes maintenance more time-consuming. Common logic should be extracted into separate functions or modules.<\/li>\n\n\n\n<li>Improper or excessive comments: Writing notes about obvious things or leaving outdated comments that no longer match the actual code can mislead others. Comments should explain \u201cwhy\u201d, not \u201cwhat\u201d.<\/li>\n\n\n\n<li>Violating the Single Responsibility Principle: A class or function that handles too many tasks becomes difficult to extend and prone to errors. Each component should have only one reason to change.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">6. Conclusion<\/h2>\n\n\n\n<p>Writing clean code is not a luxury technique for those who have \u201cextra time to polish code beautifully,\u201d but a vital foundation for software to survive, grow, and succeed.<br>Clean code is like a good book: anyone who opens it can understand the storyline without the author standing by to explain. It helps the whole team confidently develop new features, refactor without fear of \u201cbreaking\u201d anything, and keep the project sustainable over time.<br>A professional programmer not only makes the software work, but also makes others want to work with them \u2014 and clean code is the common language that connects them.<br>Remember: The code you write today is the legacy you leave for the future. Write it as if you will have to maintain it for the next 5 years\u2026 because most likely, you will.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Reference<\/h2>\n\n\n\n<p>[1] R. C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship. Upper Saddle River, NJ: Prentice Hall, 2008.<br>[2] R. C. Martin, The Clean Coder: A Code of Conduct for Professional Programmers. Upper Saddle River, NJ: Prentice Hall, 2011.<br>[3] M. Fowler, Refactoring: Improving the Design of Existing Code. Boston, MA: Addison-Wesley, 2018.<br>[4] OpenDev, \u201cKienthucmo,\u201d [Online]. Available: <a href=\"https:\/\/kienthucmo.com\/en\/software-engineering\/\">https:\/\/kienthucmo.com\/en\/software-engineering\/<\/a>. [Accessed: Oct. 24, 2025].<br>[6] OpenDev, \u201cWhat is SOLID? Principles, how it works, and practical applications,\u201d [Online]. Available: <a href=\"https:\/\/kienthucmo.com\/en\/what-is-solid-principles-how-it-works-and-practical-applications\/\">https:\/\/kienthucmo.com\/en\/what-is-solid-principles-how-it-works-and-practical-applications\/<\/a>. [Accessed: Oct. 24, 2025].<br>[7] OpenDev, \u201cKISS, DRY, YAGNI \u2013 3 Golden Principles in Software Development,\u201d [Online]. Available: <a href=\"https:\/\/kienthucmo.com\/en\/kiss-dry-yagni-3-golden-principles-in-software-development\/\">https:\/\/kienthucmo.com\/en\/kiss-dry-yagni-3-golden-principles-in-software-development\/<\/a>. [Accessed: Oct. 24, 2025].<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Clean Code not only ensures the software runs correctly but also keeps the project readable, maintainable, and sustainable.<\/p>\n","protected":false},"author":1,"featured_media":2353,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowieHDDA:productID":"","footnotes":""},"categories":[50],"tags":[51],"class_list":["post-1302","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-information-technology","tag-clean-code"],"_links":{"self":[{"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/posts\/1302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/comments?post=1302"}],"version-history":[{"count":13,"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/posts\/1302\/revisions"}],"predecessor-version":[{"id":2365,"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/posts\/1302\/revisions\/2365"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/media\/2353"}],"wp:attachment":[{"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/media?parent=1302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/categories?post=1302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kienthucmo.com\/en\/wp-json\/wp\/v2\/tags?post=1302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}