oliverdavies.uk/content/node.4297cfc8-623f-4d32-b353-5a441c2c632f.yml

102 lines
3.9 KiB
YAML
Raw Normal View History

2025-07-10 00:14:12 +01:00
uuid:
- value: 4297cfc8-623f-4d32-b353-5a441c2c632f
langcode:
- value: en
type:
- target_id: daily_email
target_type: node_type
target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7
revision_timestamp:
- value: '2025-05-11T09:00:51+00:00'
revision_uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
revision_log: { }
status:
- value: true
uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
title:
- value: |
Writing readable code
created:
- value: '2022-12-01T00:00:00+00:00'
changed:
- value: '2025-05-11T09:00:51+00:00'
promote:
- value: false
sticky:
- value: false
default_langcode:
- value: true
revision_translation_affected:
- value: true
path:
- alias: /daily/2022/12/01/writing-readable-code
langcode: en
body:
- value: |
<p>This week, I needed to investigate and fix a bug within some existing code.</p>
<p>It's code written some time ago and not by anyone working on the team.</p>
<p>The code wasn't very readable, so before I could fix the bug, I needed to figure out what the code was supposed to be doing.</p>
<p>I started to write a list of things that would make the code easier to read and understand - no single-letter variable names, reduced levels of indentation and splitting some nested ternary operators to use separate return statements.</p>
<p>I also watched a video of a conference talk titled "Writing code you won't hate tomorrow", which re-introduced me to Object Callisthenics.</p>
<p>They are from "The ThoughtWorks Anthology" book and are some steps that include some of the points that I had written:</p>
<ol>
<li>Use only one level of indentation per method.</li>
<li>Dont use the else keyword.</li>
<li>Wrap all primitives and strings.</li>
<li>Use only one dot per line.</li>
<li>Dont abbreviate.</li>
<li>Keep all entities small.</li>
<li>Dont use any classes with more than two instance variables.</li>
<li>Use first-class collections.</li>
<li>Dont use any getters/setters/properties</li>
</ol>
<p>As well as the original book, there are numerous blog posts and videos on this topic.</p>
<p>Why try some of them on the next code you write and see if it's easier to read and understand?</p>
format: full_html
processed: |
<p>This week, I needed to investigate and fix a bug within some existing code.</p>
<p>It's code written some time ago and not by anyone working on the team.</p>
<p>The code wasn't very readable, so before I could fix the bug, I needed to figure out what the code was supposed to be doing.</p>
<p>I started to write a list of things that would make the code easier to read and understand - no single-letter variable names, reduced levels of indentation and splitting some nested ternary operators to use separate return statements.</p>
<p>I also watched a video of a conference talk titled "Writing code you won't hate tomorrow", which re-introduced me to Object Callisthenics.</p>
<p>They are from "The ThoughtWorks Anthology" book and are some steps that include some of the points that I had written:</p>
<ol>
<li>Use only one level of indentation per method.</li>
<li>Dont use the else keyword.</li>
<li>Wrap all primitives and strings.</li>
<li>Use only one dot per line.</li>
<li>Dont abbreviate.</li>
<li>Keep all entities small.</li>
<li>Dont use any classes with more than two instance variables.</li>
<li>Use first-class collections.</li>
<li>Dont use any getters/setters/properties</li>
</ol>
<p>As well as the original book, there are numerous blog posts and videos on this topic.</p>
<p>Why try some of them on the next code you write and see if it's easier to read and understand?</p>
summary: null
field_daily_email_cta: { }