From 18a63f82aafb84fe2c43f9cedb3c34d890812051 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 10 Apr 2024 23:52:50 +0100 Subject: [PATCH] Add daily email for 2024-04-07 Avoiding nesting --- source/_daily_emails/2024-04-07.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 source/_daily_emails/2024-04-07.md diff --git a/source/_daily_emails/2024-04-07.md b/source/_daily_emails/2024-04-07.md new file mode 100644 index 00000000..4e1037b0 --- /dev/null +++ b/source/_daily_emails/2024-04-07.md @@ -0,0 +1,22 @@ +--- +title: Avoiding nesting +date: 2024-04-07 +permalink: archive/2024/04/07/avoiding-nesting +tags: + - software-development + - clean-code +cta: ~ +snippet: | + How many levels of nesting do you have in your code? It's something I try to keep to a minimum. +--- +One of my goals when coding is to reduce the amount of nesting in the code I write. + +I mean both in my PHP code where if conditions and foreach loops can be nested within each other, and CSS and Sass files, which support nesting CSS rules. + +My aim is to have a maximum of two or three levels of indentation, though sometimes this isn't possible. + +Doing so where I can, though, makes my code easier to read and understand and encourages other clean code approaches, such as having small and well-named functions. + +In CSS or Sass, avoiding nesting makes it easier to find a rule I'm looking for instead of having to find how rules have been nested or names have been concatenated - making it hard to search or grep for a string. + +This approach is part of "object callisthenics", which was introduced by Jeff Bay and includes other approaches that I like to follow, such as not using the `else` keyword and other good practices that I like to try and implement when possible.--