Clean Code Principles

Alper Karabay
4 min readOct 30, 2023

--

Clean code is more than just a matter of aesthetics; it’s a craft that empowers developers to produce software that is not only functional but also easy to understand, maintain, and extend. It embodies a set of principles, practices, and techniques that prioritize readability, simplicity, and clarity in programming. Writing clean code is akin to writing a well-crafted story, where each line not only serves a purpose but also contributes to the overall coherence and understanding. This approach, pioneered by software engineering luminaries like Robert C. Martin (Uncle Bob), promotes a mindset that is as much about communication as it is about programming. In this article, we delve into the fundamental principles that define clean code, exploring its significance and the impact it has on the quality and sustainability of software development

Why Do We End Up With a Bad Code?

The desire to develop quickly is one of the biggest reasons that creates bad code. We usually try to quickly develop the features requested from us in our business life. At the end of the day, the details we ignore will slow us down a lot in the later stages of the project. Besides, when a new person joins the team, understanding the code becomes a torture.

Since the cleanliness of the code is not a concretely measurable value, the only valid constraint you should keep in mind when writing the code is WTF/Minutes (WTFPM). Here WTFPM stands for “Works that Frustrate” that the developer can read per minute.

While writing your code, always think about how many times per minute the next developer will say WTF while reading this code.

Lets look at the thoughts of big guys:

THE BOY SCOUT RULE:

The Boy Scouting Rule is a programming principle that states, “Always leave the code you are working on a little bit better than you found it.” This adage is inspired by the Boy Scouts of America’s Leave No Trace principles, which encourage individuals to leave the environment cleaner than they found.

Here is something that you should care while writing the code:

1. Use meaningful, pronounceable names:

BAD USAGE

Always think that you might need to talk about your code. Seriously how would you pronounce DtaRcrd102? And what does genDt or modDt mean?

GOOD USAGE

2. Functions should be small and do one thing

Just imagine how many hours it would take to understand this code. No more comments.

Seems better, but what does TestableHtml mean?

USE DESCRIPTIVE NAMES

3. Ideal number of function arguments is 0

Use at most 3 arguments. If you need more try to use class parameters.

4. Don’t use flag arguments

5. Explain yourself in the code

What do these conditions mean?
Better Usage

--

--