From 7fa215305031f94a45639ced61b5eccf69c08973 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 2 Dec 2022 08:17:12 +0000 Subject: [PATCH] docs(daily-email): add 2022-12-01 --- website/src/daily-emails/2022-12-01.md | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 website/src/daily-emails/2022-12-01.md diff --git a/website/src/daily-emails/2022-12-01.md b/website/src/daily-emails/2022-12-01.md new file mode 100644 index 00000000..0cc94339 --- /dev/null +++ b/website/src/daily-emails/2022-12-01.md @@ -0,0 +1,33 @@ +--- +title: > + Writing readable code +pubDate: 2022-12-01 +permalink: > + archive/2022/12/01/writing-readable-code +--- + +This week, I needed to investigate and fix a bug within some existing code. + +It's code written some time ago and not by anyone working on the team. + +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. + +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. + +I also watched a video of a conference talk titled "Writing code you won't hate tomorrow", which re-introduced me to Object Callisthenics. + +They are from "The ThoughtWorks Anthology" book and are some steps that include some of the points that I had written: + +1. Use only one level of indentation per method. +1. Don’t use the else keyword. +1. Wrap all primitives and strings. +1. Use only one dot per line. +1. Don’t abbreviate. +1. Keep all entities small. +1. Don’t use any classes with more than two instance variables. +1. Use first-class collections. +1. Don’t use any getters/setters/properties + +As well as the original book, there are numerous blog posts and videos on this topic. + +Why try some of them on the next code you write and see if it's easier to read and understand?