Skip to content

Formatting Rules: The Underestimated Clean Code Benefit

Why uniform code formatting is more than just cosmetics

A plant next to a white wall

Photo from Sarah Dorweiler on Unsplash

The Quick Path to Better Code

Today I'm dedicating myself to one of my favorite topics in the clean code world: formatting rules. Why? Because it's a genuine "quick win" – a measure that can be implemented in the shortest time and brings immediately recognizable benefits to the entire project.

Simple – at least technically

For a long time, I thought this point was the easiest on the clean code list: The team agrees on formatting rules, saves them in a configuration file, and makes them available to all developers. Everyone imports them into their IDE, and the problem is solved. Technically, this is indeed uncomplicated and immediately brings numerous advantages.

The Human Component

However, this plan contains a critical phrase: "The team agrees" – and this is often where the challenge lies, not just in IT projects. Each of us has our own preferences, opinions, and individual style. Personally, I prefer a maximum line length of about 100 characters (80 works excellently too, especially for small, focused functions). This preference can be well-justified: People read text most efficiently in narrow columns from top to bottom, not from left to right – similar to newspapers ("The Newspaper Metaphor"). An additional advantage becomes apparent during code comparisons in GitLab or other tools during code reviews.

Personal Preferences vs. Team Standards

For Fluent APIs, I also find it sensible to write each method call on a new line (for the previously mentioned reason). Yet more important than any personal opinion is the uniformity of source code in the project. Why? Because we shouldn't waste valuable time on manual code formatting. We have modern IDEs with automation features for that – and automation is one of the key factors for successful IT projects.

The Concrete Benefits

Uniformly formatted code offers decisive advantages:

  • Code reviews become more efficient as one can concentrate on functional changes

  • Essential aspects of the implementation are more easily recognizable

  • Developers save mental energy that they can instead use for further education or innovation

Practical Approach

When I start a new project with a client, I import the formatting rules first. I usually work with IntelliJ, which can easily import configurations from VS Code, Eclipse, and other IDEs. After some time on the project, I share recommendations and suggestions for improvement with the team, leaving them the freedom to decide – an approach that has proven effective.

Clean Code Recommendations for Formatting

In the clean code context, there are numerous detailed recommendations for vertical and horizontal formatting that are best illustrated through examples – for which there unfortunately isn't enough space here.

The Most Important Tip

My recommendation today is: Agree as a team on standards and apply them consistently. In parallel, you can familiarize yourselves with clean code principles and check which ones work best for your team. The most important thing, however: Don't waste time on manual code formatting! Instead, have a coffee with your colleagues and discuss truly exciting technical challenges.

Author

Sebastian Bergandy
Sebastian Bergandy