<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thierry CATRAIN on Medium]]></title>
        <description><![CDATA[Stories by Thierry CATRAIN on Medium]]></description>
        <link>https://medium.com/@thierrycatrain?source=rss-826308f4cd74------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hlcHWZGODSW-61bwjegY_A.jpeg</url>
            <title>Stories by Thierry CATRAIN on Medium</title>
            <link>https://medium.com/@thierrycatrain?source=rss-826308f4cd74------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 13:31:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thierrycatrain/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Writing clean code — Part 1 — Generic principles]]></title>
            <link>https://medium.com/@thierrycatrain/writing-clean-code-part-1-generic-principles-954fd3e185e4?source=rss-826308f4cd74------2</link>
            <guid isPermaLink="false">https://medium.com/p/954fd3e185e4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Thierry CATRAIN]]></dc:creator>
            <pubDate>Tue, 26 Feb 2019 14:58:09 GMT</pubDate>
            <atom:updated>2019-04-18T08:45:30.555Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<h3>Writing clean code — Part 1 — Generic principles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-MBSTjpf0-8DYxWoQ2KOw.png" /><figcaption>Source : <a href="https://www.perforce.com/blog/vcs/why-you-should-write-clean-code">Perforce.com</a></figcaption></figure><blockquote>“Clean code is not written by following a set of rules. You don’t become a software craftsman by learning a list of heuristics. Professionalism and craftsmanship come from values that drive disciplines.” — <strong>Robert C. Martin, Clean Code : A Handbook of Agile Software Craftsmanship</strong></blockquote><p>After more than 10 years of experience, the way I write and read code has drastically changed. It means that even the same developer evolves, and changes his or her own “clean” criterias. You can find dozens of standards outside, in the internet, and specifics for each language one can master. But the most important, in my opinion, is to define what is your “clean” version as a team.</p><p>With that said, defining your own standards should match a set of principles, as described in the <a href="https://www.oreilly.com/library/view/clean-code/9780136083238/">Clean Code</a> cookbook written by <a href="https://fr.wikipedia.org/wiki/Robert_C._Martin">Robert C. Martin</a>, which I cannot recommend you enough, developers out there, to read.</p><p>I will split the series into categories, each of them covering a specific aspect of what is considered clean code. Here is the complete set of posts in my clean code series (work in progress) :</p><ul><li><strong>Part 1 — Generic principles</strong></li><li>Part 2 — Design principles</li><li>Part 3 — Readability</li><li>Part 4 — Naming convention</li><li>Part 5 — Code structure</li><li>Part 6 — Tests principles</li></ul><h4>1. Define a standard</h4><p>Generally speaking, developers hate to waste time, and tend to dive quickly into writing code. However, as fast as you want to deliver an app, you should keep in mind the good old idiom “<em>more haste, less speed</em>”, as it is very adequate in this case. Even when you are the first and only developer at the beginning, you should lose these few minutes to write down the rules you are following. Not everything at once of course, but every time you wonder where to place this new file, how to name it, how to name your new object and in which file to add it, you definitely should take these extra minutes to extend your coding standards documentation. I personally recommend locating it in a wiki, next to your codebase. Having a standard will help reducing the gap between different developers habits, as well as avoiding feeling the split within the code written by different programers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*DDQm7s0hlDr4eUuUtkfa_A.png" /><figcaption>Source : <a href="https://www.mindzcloud.com/salesforce-consulting-services">MindZcloud.com</a></figcaption></figure><p><strong>How far to go in standardization ?</strong></p><p>There are many aspects in a programming language that might be standardize, and it might be tricky to decide what to pick and include in your coding standards. My advice here is pragmatic, write down anything that raises discussion within your team or even with yourself. First of all, chose the language you will be writing in, for there’s no real necessity to use english as a standard language. Using the business language from your company might be the good way to go, for mixing languages is to be avoided.</p><p>For example, I work in a French company, where we decided to go for english as the main language of our code, but since the business language is french, I often read method names like this.getAllDossiersFromUtilisateur(utilisateur.id). Do I need to say how much it tickles me to read this ?</p><p>Here are some common extra examples among coding standards you may want to address:</p><ul><li>Folder structure</li><li>File / function / method /class / variable names</li><li>Number of classes / functions inside a file</li><li>Number of lines inside of a function / method</li><li>Number of functions / methods within a class</li><li>Number of columns</li><li>Usage of keyword</li><li>Maximum imbricated loops / conditions</li><li>Spaces or tabs</li><li>Error handling</li><li>Position of braces</li><li>Documentation of method / function</li><li>And many more…</li></ul><p>You may decide to go for an already available standard, which would offer some advantage such as linters working out of the box, but then you need to stick to it or update your standards when something seems really unnatural to <strong>anyone in your team</strong>. This last part is critical : every one in the team must be keen and must agree with the rules your are setting up. Some new ideas may come from newcomers, and should something make sense, why not take it and update your coding standards ?</p><p>Most of the time, updating coding standards is regarded as a bad idea because you’ll start to mix things up : old style and new one. While it is true, it might be tuned down by the next generic principle called <strong>the boy scout rule</strong>.</p><h4>2. The boy scout rule</h4><blockquote>Always leave the campground cleaner than you found it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*QBrCUXWsZE67DXip5gEYoQ.jpeg" /></figure><p>You always should try to improve the quality of the code. When you are fixing, updating or even just reading a codebase you are working on, correct any transgression to the standards you defined. Your linters will sometimes yell at you, dumping lots of errors. Allow yourself to take the time to correct it, because, sooner or later, you, or a teammate, will have to do it.</p><p>The code quality must be regularly checked, at least every day, to monitor the day-to-day effort in cleaning the code. Ideally check it on every commit so that you know when you impacted the code quality, and you can fix it right away. In addition, you may want to add some post commit hook, which can handle some basic corrections automatically like replacing tabs with spaces, removing trailing whitespaces, changing end of line characters, etc. Just keep in mind that, while linters will evaluate the code style, it won’t help regarding meaningless names you define in your code.</p><p>Over the time, not enforcing the boy scout rule within your team will surely decrease the quality of your code. This is called the <strong>technical debt</strong>, and by letting it fall down, you will face a situation where new developments will be significantly slowed down by the poor code quality, and you might even need to completely shut down the value added work for a time to clean up the codebase. Beware, the technical debt does not only concerns transgression to your standards, it also applies to any abnormally complicated portion of the code, which leads us to my next, and last, point : the <strong>Keep It Simple Stupid (KISS) rule</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qGq3yH2xhsp7Q6ysotb3Tg.png" /><figcaption>Source : Spiria.com</figcaption></figure><h4>3. Keep It Simple Stupid</h4><p>The simpler the better. Try to reduce complexity and do not overdo things. You may from time to time be tempted to handle every possible scenario the code you have written may follow in extremely unusual conditions and this is a classic and a good approach in some ways. Just do not fall into the trap of overdoing your developments, do not implement every possible method you <strong>might</strong> need, one day. For example, you should have validated the input values as early as possible, avoid repetition (<strong>Don’t Repeat Yourself</strong>), one check is enough, and it should not be done in every single function that takes input parameters.</p><p>There are some tools that will help you going straight to the essential, while providing you enough safety to do the required refactoring such as <strong>Test Driven Development (TDD)</strong>, and <strong>SOLID</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rFCkEULozF2Ad80MlVcBUg.png" /><figcaption>Source : <a href="https://www.netguru.com/blog/why-tdd-is-still-alive-and-still-worth-using">Netguru.com</a></figcaption></figure><p><strong>How to TDD ?</strong></p><p>The approach of TDD is fairly simple, yet not very intuitive. From this point, I consider every reader is familiar with unit testing, otherwise, please stop reading here and go read <a href="http://softwaretestingfundamentals.com/unit-testing/">these few lines</a>. In TDD, we start any development from unit tests, once at the time, each of them bound to a scenario of the feature to develop, and we consider any error a reason to keep going. An error is a very wide term to define something wrong which forbids the test to pass, such as compilation issue, or even a red underlined variable in your test which you misspelled or did already defined. The first objective is to <strong>write the minimum amount of code</strong> needed to make the test passing. Once achieved, you are now good to <strong>refactor the code</strong>.</p><p>Since your test is passing, you are safe to change everything up to the point you are satisfied with the level of simplicity and factorization in your code, and you do not have to worry about breaking previous development, as there are covered as well by unit tests. It goes without saying that you need to consider running unit tests on each build, prior to commit, and make sure every test is passing.</p><p>Code refactoring may be done in several ways, whether it is by adding an abstraction level, or reusing and updating an existing object. However, keep in mind that making your code <strong>SOLID</strong> is one of the best ways to keep it stupid simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FrDWow5rk7cVn7Jabtn77A.png" /><figcaption>Source : <a href="https://www.monterail.com/blog/solid-principles-cheatsheet-printable">Monterail.com</a></figcaption></figure><p><strong>How to make it rock SOLID</strong></p><p>I could not explain it better than <a href="https://medium.com/u/c867c0804e76">Severin Perez</a> in his series <strong><em>SOLID</em></strong><em> Principles and Maintainable Code</em> :</p><ul><li><a href="https://medium.com/@severinperez/writing-flexible-code-with-the-single-responsibility-principle-b71c4f3f883f">The <strong>S</strong>ingle Responsibility Principle</a></li><li><a href="https://medium.com/@severinperez/maintainable-code-and-the-open-closed-principle-b088c737262">The <strong>O</strong>pen/Closed Principle</a></li><li><a href="https://medium.com/@severinperez/making-the-most-of-polymorphism-with-the-liskov-substitution-principle-e22609866429">The <strong>L</strong>iskov Substitution Principle</a></li><li><a href="https://medium.com/@severinperez/avoiding-interface-pollution-with-the-interface-segregation-principle-5d3859c21013">The <strong>I</strong>nterface Segregation Principle</a></li><li><a href="https://medium.com/@severinperez/effective-program-structuring-with-the-dependency-inversion-principle-2d5adf11f863">The <strong>D</strong>ependency Inversion Principle</a></li></ul><p>However, I would add that you should try to experiment from time to time through exercises. One of the best I found to help you familiarize with the <strong>SOLID</strong> principles is challenging yourself to not use any if ... [else ...] for a given purpose. This is called <strong>no-if code</strong>, and it is a very good practice to try thinking software design first, but this is a topic for another day.</p><p>To put it in a nutshell, clean code is a set of advices that will help you to write more maintainable and readable code. The first step in having a clean code approach is to define a standard your team must follow. Then every team member must make his or her best to constantly improve the quality of the codebase, every time he or she sees something odd or overly complicated. As long as you are keeping the code stupid simple in addition to respecting the first two points, you will be in good tracks for many years as a team.</p><p>That concludes the first part of the <em>writing clean code </em>series. Make sure to check the content from <a href="https://medium.com/u/c867c0804e76">Severin Perez</a>, because next time, we’ll be talking about design principles, and refer a lot to the <strong>SOLID</strong> ones. Stay tuned !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=954fd3e185e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>