A place to cache linked articles (think custom and personal wayback machine)
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

8 meses atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang="en">
  4. <!-- Has to be within the first 1024 bytes, hence before the `title` element
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset="utf-8">
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name="viewport" content="width=device-width,initial-scale=1">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>The most important goal in designing software is understandability (archive) — David Larlet</title>
  13. <meta name="description" content="Publication mise en cache pour en conserver une trace.">
  14. <!-- That good ol' feed, subscribe :). -->
  15. <link rel="alternate" type="application/atom+xml" title="Feed" href="/david/log/">
  16. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  17. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons2/apple-touch-icon.png">
  18. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons2/favicon-32x32.png">
  19. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons2/favicon-16x16.png">
  20. <link rel="manifest" href="/static/david/icons2/site.webmanifest">
  21. <link rel="mask-icon" href="/static/david/icons2/safari-pinned-tab.svg" color="#07486c">
  22. <link rel="shortcut icon" href="/static/david/icons2/favicon.ico">
  23. <meta name="msapplication-TileColor" content="#f7f7f7">
  24. <meta name="msapplication-config" content="/static/david/icons2/browserconfig.xml">
  25. <meta name="theme-color" content="#f7f7f7" media="(prefers-color-scheme: light)">
  26. <meta name="theme-color" content="#272727" media="(prefers-color-scheme: dark)">
  27. <!-- Is that even respected? Retrospectively? What a shAItshow…
  28. https://neil-clarke.com/block-the-bots-that-feed-ai-models-by-scraping-your-website/ -->
  29. <meta name="robots" content="noai, noimageai">
  30. <!-- Documented, feel free to shoot an email. -->
  31. <link rel="stylesheet" href="/static/david/css/style_2021-01-20.css">
  32. <!-- See https://www.zachleat.com/web/comprehensive-webfonts/ for the trade-off. -->
  33. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  34. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  35. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  36. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  37. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  38. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  39. <script>
  40. function toggleTheme(themeName) {
  41. document.documentElement.classList.toggle(
  42. 'forced-dark',
  43. themeName === 'dark'
  44. )
  45. document.documentElement.classList.toggle(
  46. 'forced-light',
  47. themeName === 'light'
  48. )
  49. }
  50. const selectedTheme = localStorage.getItem('theme')
  51. if (selectedTheme !== 'undefined') {
  52. toggleTheme(selectedTheme)
  53. }
  54. </script>
  55. <meta name="robots" content="noindex, nofollow">
  56. <meta content="origin-when-cross-origin" name="referrer">
  57. <!-- Canonical URL for SEO purposes -->
  58. <link rel="canonical" href="https://ntietz.com/blog/the-most-important-goal-in-designing-software-is-understandability/">
  59. <body class="remarkdown h1-underline h2-underline h3-underline em-underscore hr-center ul-star pre-tick" data-instant-intensity="viewport-all">
  60. <article>
  61. <header>
  62. <h1>The most important goal in designing software is understandability</h1>
  63. </header>
  64. <nav>
  65. <p class="center">
  66. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  67. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-home"></use>
  68. </svg> Accueil</a> •
  69. <a href="https://ntietz.com/blog/the-most-important-goal-in-designing-software-is-understandability/" title="Lien vers le contenu original">Source originale</a>
  70. <br>
  71. Mis en cache le 2024-03-18
  72. </p>
  73. </nav>
  74. <hr>
  75. <p>When you're designing a piece of software, the single most important thing to design for is understandability.
  76. Security, performance, and correctness are all important, but they come after understandability.</p>
  77. <p>Don't get me wrong, all of those are important.
  78. Software that isn't correct leads to expensive errors and frustrating experiences.
  79. Slow software can be unusable and frustrating. And insecure software, well, we have a moral <em>and</em> an economic imperative to ensure our software is secure.
  80. But <em>understandability supersedes these</em>.</p>
  81. <p>It's most important, above these, because you cannot ensure any of these other design goals <em>without</em> understandability.
  82. It has to come first.</p>
  83. <h1 id="misunderstood-software-produces-defects">Misunderstood software produces defects</h1>
  84. <p>If software is misunderstood by its implementers and maintainers, then it will end up with defects.
  85. Major defects.
  86. These will come in many forms.</p>
  87. <p>The most obvious one is with correctness.
  88. If you can't understand a given piece of code, you won't be able to read it and understand that it's doing and what it <em>should</em> be doing.
  89. Tests are not your salvation here, because (1) they can cover only limited surface area, and (2) they suffer the same problem: if you don't understand the software you likely don't understand it enough to test it well.</p>
  90. <p>This then gets tangled up with security and performance requirements, too.
  91. If you don't understand the system, how are you going to make it secure?
  92. You can't understand your way into perfect security—it's a process and it's not something that's done.
  93. But if you start from not understanding your software, any hope of security is entirely lost.
  94. You'll miss some base requirements and introduce grievous <em>simple</em> security problems, not the kind that come from complex and subtle interactions between components.</p>
  95. <p>And when you don't understand the software, then any change you make for performance gains is likely to break critical functionality or secure behavior in fundamental ways.
  96. Caching can leak information or mess up your business logic.
  97. Improving queries to solve a performance problem can produce major defects, or even end up causing <em>regressions</em> in performance.</p>
  98. <p>So if you don't understand the code, then it's a losing proposition to try to do anything with it: add a new feature, fix a bug, work on security.</p>
  99. <h1 id="it-s-not-me-it-s-you">"It's not me, it's you"</h1>
  100. <p>It's easy to feel shame or anxiety about not understanding the code.
  101. I carried that for a long time.
  102. There was a codebase I worked on in a previous role where I had no <em>idea</em> what it was doing.
  103. The backend was tough for me to understand, but I got it eventually.
  104. The frontend, no hope, I never made heads nor tails of it.</p>
  105. <p>I assumed that I was just not a good enough engineer to understand our frontend code, and that there was something wrong with me.</p>
  106. <p>Look, reader, I'm a principal engineer with over a decade of experience.
  107. I'm pretty good at my job: our tech leads and most senior engineers come to <em>me</em> for their hard problems, and I consistently debug things anywhere in our stack, <em>including</em> the frontend.
  108. If I felt I couldn't understand it, there were definitely others who also could not.
  109. And the fact that I blamed myself, with so much evidence that I was good at what I do...
  110. Turns out, the problem wasn't me, it was the code.</p>
  111. <p>If you've felt similarly, know that you're not alone.
  112. And that it's not you.
  113. It's the code, the system around it.
  114. Tell that codebase "It's not me, it's you."
  115. Sometimes things are not understandable because you don't have expertise, but if you're generally experienced in the area that that code is in, it's quite probable that the problem is the codebase you're trying to work in.</p>
  116. <h1 id="how-do-we-make-it-understandable">How do we make it understandable?</h1>
  117. <p>So that just leaves the issue of how to make things understandable.
  118. There are a couple of general approaches.
  119. You can make the code itself inherently understandable, or you can give supporting documentation to aid in understanding it.
  120. Both are needed, and both have limits.</p>
  121. <h2 id="make-the-code-understandable">Make the code understandable</h2>
  122. <p>This is something we do routinely in software engineering, although it's easy to lose sight of it.
  123. There are a few key considerations I use when I do this:</p>
  124. <ul>
  125. <li><strong>Remember your audience.</strong> What will other maintainers of this code reasonably be expected to know? If something isn't common knowledge in your team or your industry, then you should probably add some comments explaining it.</li>
  126. <li><strong>Isolate the highest complexity.</strong> If something is complicated, it's worth pulling out into its own unit (a module, a function, whatever) so that you can define its interface and use it in a more fluently readable way, while also constraining that complexity for people who are trying to understand it later.</li>
  127. <li><strong>Read it with fresh eyes.</strong> It's hard to evaluate your own code for readability. One trick is to put the code away for a few days, then read it yourself again after you've switched it all out of your working memory a day or two later. This will help you see things that might trip up a new reader.</li>
  128. <li><strong>Integrate any code review comments.</strong> If someone asks how something works in a code review, do <em>not</em> just explain it to them in the comment. This means it's not clear to your reader who has all the context of your pull request, so it will <em>not be clear</em> to future readers who lack that context. Instead, update the code to be more clear (structurally or with comments) and then reply asking them if the change helps.</li>
  129. </ul>
  130. <h2 id="add-supporting-documentation">Add supporting documentation</h2>
  131. <p>Sometimes, the code will just be hard to understand. This is usually when there's a tension between requirements. Performance improvement will often result in less clear code, for example.</p>
  132. <p>It's also hard (impossible?) to understand the full context of a codebase from the code by itself.
  133. As much as we talk about self-documenting code, the codebase doesn't contain the entire system.</p>
  134. <p>So we need some supporting documentation.
  135. Here are some things that are very helpful for understanding a codebase.</p>
  136. <ul>
  137. <li><strong>System architecture documentation.</strong> I like to keep system architecture diagrams, glossaries of key terms and services, and an explanation of the system as a whole, for the systems I work on. These do get out of date, but a one-month out of date document is better than none at all. For these, I keep a recurring calendar task to update it so that it never drifts too far out of date. For a growing company, onboarding is also a good time to make sure it's current.</li>
  138. <li><strong>Architecture decision records and design reviews.</strong> We make a lot of decisions about architecture and code design as we go through our days as software engineers. When we make these decisions, that's a good time to write them down. This has three effects. The first is the clear one: it gives a record that we can use to understand later on what decision was made or why it was made. The second is less obvious, which is that by having to write our decision down we get clearer on it ourselves, and it forces us to try to explain it to someone else. This makes it so we have some focus on understandability. And the third is that this is a <em>great</em> place to insert a design review process, or at least broadcast these out, so you get feedback on clarity early in the process before writing code.</li>
  139. <li><strong>Product requirement documents.</strong> These are super helpful for us to know what we're implementing and why it matters. But they're also very helpful later for understanding the code in its context. Was this weird behavior actually intended, or is it a bug? If you can go look at why it was implemented and the original requirements, that helps you answer that question.</li>
  140. <li><strong>Code comments.</strong> These are the elephant in the room. They're helpful for explaining what a particular unit of code does and why it exists. These are very helpful in any case where something will be surprising, so they should be used for things that people will look at and puzzle over. They're also good for pointing to related documentation, otherwise it's hard to discover the related docs to understand the code when you're maintaining the code.</li>
  141. </ul>
  142. <p>Those are just a few of the ways you can can add supporting documentation to help with understandability!</p>
  143. <h1 id="gradual-improvement-works">Gradual improvement works</h1>
  144. <p>Understandability is a fuzzy thing that's subjective.
  145. And it's not something that you can, or should, aim for perfection on.
  146. If you're working in a codebase today and it's hard to understand, the temptation can be to throw it away and start over.
  147. Sometimes that's merited, but often gradual improvement can be a good solution.</p>
  148. <p>Each time you struggle to understand something, or you gain a better understanding through a task you work on, that's a good time to add documentation or improve the code to make it more understandable!
  149. Each small improvement will help you in the future and help your teammates.
  150. And each time you improve it, you lead by example and show people that this can and should be done.</p>
  151. </article>
  152. <hr>
  153. <footer>
  154. <p>
  155. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  156. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-home"></use>
  157. </svg> Accueil</a> •
  158. <a href="/david/log/" title="Accès au flux RSS"><svg class="icon icon-rss2">
  159. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-rss2"></use>
  160. </svg> Suivre</a> •
  161. <a href="http://larlet.com" title="Go to my English profile" data-instant><svg class="icon icon-user-tie">
  162. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-user-tie"></use>
  163. </svg> Pro</a> •
  164. <a href="mailto:david%40larlet.fr" title="Envoyer un courriel"><svg class="icon icon-mail">
  165. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-mail"></use>
  166. </svg> Email</a> •
  167. <abbr class="nowrap" title="Hébergeur : Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33184162340"><svg class="icon icon-hammer2">
  168. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-hammer2"></use>
  169. </svg> Légal</abbr>
  170. </p>
  171. <template id="theme-selector">
  172. <form>
  173. <fieldset>
  174. <legend><svg class="icon icon-brightness-contrast">
  175. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-brightness-contrast"></use>
  176. </svg> Thème</legend>
  177. <label>
  178. <input type="radio" value="auto" name="chosen-color-scheme" checked> Auto
  179. </label>
  180. <label>
  181. <input type="radio" value="dark" name="chosen-color-scheme"> Foncé
  182. </label>
  183. <label>
  184. <input type="radio" value="light" name="chosen-color-scheme"> Clair
  185. </label>
  186. </fieldset>
  187. </form>
  188. </template>
  189. </footer>
  190. <script src="/static/david/js/instantpage-5.1.0.min.js" type="module"></script>
  191. <script>
  192. function loadThemeForm(templateName) {
  193. const themeSelectorTemplate = document.querySelector(templateName)
  194. const form = themeSelectorTemplate.content.firstElementChild
  195. themeSelectorTemplate.replaceWith(form)
  196. form.addEventListener('change', (e) => {
  197. const chosenColorScheme = e.target.value
  198. localStorage.setItem('theme', chosenColorScheme)
  199. toggleTheme(chosenColorScheme)
  200. })
  201. const selectedTheme = localStorage.getItem('theme')
  202. if (selectedTheme && selectedTheme !== 'undefined') {
  203. form.querySelector(`[value="${selectedTheme}"]`).checked = true
  204. }
  205. }
  206. const prefersColorSchemeDark = '(prefers-color-scheme: dark)'
  207. window.addEventListener('load', () => {
  208. let hasDarkRules = false
  209. for (const styleSheet of Array.from(document.styleSheets)) {
  210. let mediaRules = []
  211. for (const cssRule of styleSheet.cssRules) {
  212. if (cssRule.type !== CSSRule.MEDIA_RULE) {
  213. continue
  214. }
  215. // WARNING: Safari does not have/supports `conditionText`.
  216. if (cssRule.conditionText) {
  217. if (cssRule.conditionText !== prefersColorSchemeDark) {
  218. continue
  219. }
  220. } else {
  221. if (cssRule.cssText.startsWith(prefersColorSchemeDark)) {
  222. continue
  223. }
  224. }
  225. mediaRules = mediaRules.concat(Array.from(cssRule.cssRules))
  226. }
  227. // WARNING: do not try to insert a Rule to a styleSheet you are
  228. // currently iterating on, otherwise the browser will be stuck
  229. // in a infinite loop…
  230. for (const mediaRule of mediaRules) {
  231. styleSheet.insertRule(mediaRule.cssText)
  232. hasDarkRules = true
  233. }
  234. }
  235. if (hasDarkRules) {
  236. loadThemeForm('#theme-selector')
  237. }
  238. })
  239. </script>
  240. </body>
  241. </html>