Strategies to reduce "visual" code complexity

Code readability is a big factor to that maintenance process. Code that is written well is easy and fast to read when problems arise. Same with infrastructure, it's never about just the initial build. Those structures need to be built with maintenance in mind: how to extend the longevity of a project to make the hours spent building it worthwhile. We need to care about the full lifecycle of any feature at every step. Understanding how to reduce "visual" complexity is key, not just code complexity (although both, in my opinion, go hand-in-hand: code that has less cyclomatic complexity is often easier to read). This article contains some general philosophies I've adopted with my approach to programming, specifically with how to better arrange logic statements. I am not the pioneer of these concepts and will link to other blog posts that I feel are more articulate about this than I am. All examples are written with Python, but this applies to all programming languages with logic operators. Sections Go completely "else"-less "Flip" logic statements to arrange by size of inner content Implement "getters" where possible over "setters" Try/Catch the smallest statement possible Go completely "else"-less Avoiding using else statements entirely has been the most dramatic but effect change I've enacted to write better code. else is convenient but masks the actual condition being hit before code is run. Suppose I have the following code: if condition_1: print("

Apr 6, 2025 - 16:26
 0
Strategies to reduce "visual" code complexity

Code readability is a big factor to that maintenance process. Code that is written well is easy and fast to read when problems arise. Same with infrastructure, it's never about just the initial build. Those structures need to be built with maintenance in mind: how to extend the longevity of a project to make the hours spent building it worthwhile. We need to care about the full lifecycle of any feature at every step.

Understanding how to reduce "visual" complexity is key, not just code complexity (although both, in my opinion, go hand-in-hand: code that has less cyclomatic complexity is often easier to read).

This article contains some general philosophies I've adopted with my approach to programming, specifically with how to better arrange logic statements. I am not the pioneer of these concepts and will link to other blog posts that I feel are more articulate about this than I am.

All examples are written with Python, but this applies to all programming languages with logic operators.

Sections

  • Go completely "else"-less
  • "Flip" logic statements to arrange by size of inner content
  • Implement "getters" where possible over "setters"
  • Try/Catch the smallest statement possible

Go completely "else"-less

Avoiding using else statements entirely has been the most dramatic but effect change I've enacted to write better code. else is convenient but masks the actual condition being hit before code is run.

Suppose I have the following code:

if condition_1:
    print("