Write boring code
Tags: softwaredevelopment, codequality, softwareengineering, debugging
Published: 2024-05-19 19:13:14

---
title: Write boring code
published: true
date: 2024-05-19 11:57:14 UTC
tags: softwaredevelopment,codequality,softwareengineering,debugging
canonical_url: https://dvirsegal.medium.com/write-boring-code-e6a80c8311bb
---

![](https://cdn-images-1.medium.com/max/1024/0*fsa40ezPVX_z0he0)

#### **Debuggability is highly underrated**

In the words of Brian Kernighan, the famous computer scientist and author of the book “The C Programming Language”:

> Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

This quote reflects a common experience many developers face while trying to write "smart" code. They often end up with complex solutions that are hard to maintain and debug. This is a common mistake, driven by the desire to demonstrate skills (and maybe to appear clever).

So… **just write boring and straightforward code.** Organize it into small, independent modules with clear interfaces and low coupling. This makes it easier to isolate and debug issues within specific components without being affected by the rest of the system.

[How to organize a drawer the right way](https://dev.to/dejavo/how-to-organize-a-drawer-the-right-way-1c9o)

> Code is written once but read many times

Make your code readable and self-documented. This means code that follows good naming conventions, uses descriptive variables and function names, and includes clear comments (if needed).

When implementing your solution, you must think about how it will be executed. You probably focus on the happy trail, but you should also consider how it will fail and how you will debug it **in production**. Not doing so results in a mistake that can waste a lot of time and effort looking through complicated code to figure out and fix the problem.

To address this challenge, one must shift her mindset and prioritize **debuggability** from the start of the project.

![_Peter Bourgon — Metrics, tracing, and logging_](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sehcp35z0likiq5ii2z5.png)

This means leaving breadcrumbs, also known as **logs** , storing data in machine-readable format to enable efficient parsing and analysis, capturing valuable information about the application’s state, execution flow, and any errors or exceptions. There are several error-handling mechanisms that catch and report issues as early as possible, making it easier to identify and fix bugs. The logs from the different components and services will be collected into a centralized system for easier aggregation and querying.

In some cases, logs alone don't give us the complete picture of how a system is doing. It's a good idea to use **metrics** , which help us understand the system's health, performance, and behavior more completely. I’m a big fan of metrics because they give us a clearer view. You can detect anomalies and track quantities over time. Based on the collected data, you will build monitoring dashboards that provide real-time visibility (and alerting system).

![](https://cdn-images-1.medium.com/max/742/0*0DvQ08NqpfI1M8-s.jpg)

Another tool in the debugability arsenal is **tracing** , which tracks the flow of “requests” across different services and components, enabling us to visualize and analyze the end-to-end journey of a request and pinpoint bottlenecks or failures.

Furthermore, investing in administrative tooling that reflects the system's state by exposing APIs or CLIs can greatly enhance debuggability by allowing developers and administrators to interact with the system, query its state, and perform various tasks such as triggering debug modes, capturing snapshots, or executing diagnostic commands.

Lastly, live debugging tools like [Rookout](https://www.rookout.com/), [Datadog](https://www.datadoghq.com/blog/dynamic-instrumentation-application-logging/), and [Lightrun](https://lightrun.com/) allow you to debug code in production without any code changes. This is quite amazing and it is done by incorporating their agent into your code that does dynamic instrumentation. This agent is a bridge between your code and their environment. It monitors the code’s execution and identifies points in the flow (such as function calls or variable assignments), and it does some optimization not to instrument everything based on the learned history of “hot” paths to minimize the performance hit.

![](https://cdn-images-1.medium.com/max/640/0*jSjE4gU84WiVR3DE)
_Simple code works better than complicated code._

To conclude, writing boring and straightforward code, combined with various observability techniques, which should be included as early as in the design stage, can significantly enhance your system's debuggability.