r/cpp • • Jul 05 '26

Formatting vs Architecture: How formatters are erasing visual cues and hurting codebases

I’m preparing a presentation on how automatic formatters can actually ruin code management over time. This relates heavily to the ongoing discussions about C++ memory safety and why some people see it as a critical issue while others don't get the fuss since basic memory allocation isn't that hard.

Memory issues are usually just a symptom of architectural failure, not a lack of developer skill in handling allocations. A messy architecture turns minor oversights into catastrophes. That's when hidden memory leaks or memory corruption become critical safety flaws and crashes.

I often think about the (nowadays) hated Hungarian Notation. Love it or hate it, it made developers extremely efficient because it provided immediate visual cues. Developers who actively care about the visual shape of text think completely differently about code structure. If you look at Charles Simonyi's other work, it’s clear how much focus he had on architecture.

Formatters can be an absolute disaster for architecture. It has become a religion in development teams that everything must be run through Prettier or Clang-Format to the letter. But the price we pay is that formatters erase all opportunities for visual cues regarding architecture and layers.

Architecture is WAY more important than formatting.

Code is text. By deliberately allowing flexibility in how to format, we can highlight major patterns and make code much easier to reason about. When a formatter forces all code through the same rigid, mechanical template, all code looks identical. The architecture becomes invisible. Ironically, this causes codebases to rot because developers in the team can no longer see where the architectural boundaries actually are.

Formatting in itself isn't bad, but it must be a formatting style that elevates the architecture and allows for human semantic grouping. The opposite is dangerous.

As far as I know, there is no formatter out there today that is anywhere near capable of handling the flexibility required to actually make architecture visible in code.

What are your thoughts on this? Have formatters made us blind to the actual structure and layer belonging of our code?

EDIT

To those of you who only see problems with this approach: what is your actual alternative for managing cognitive load at scale?

The common stance seems to be "just write code however you want, as long as the automatic formatter makes the layout look consistent."

But formatting only fixes cosmetic consistency, it doesn't fix structure, architectural boundaries, or intent. If you believe that naming conventions, prefixes, and semantic text layouts are useless, you are essentially advocating for visual anarchy disguised as "clean text". How does a mechanical linter help a new developer navigate architectural layers in a large codebase if the code itself provides zero visual cues about where the boundaries go?

0 Upvotes

130 comments sorted by

View all comments

Show parent comment

4

u/n1ghtyunso Jul 05 '26

You asked for a verified argument of how a formatter ruins this, so let me give you a concrete example of the mechanism

Mismatched layers is a data-transformation problem. When code in the presentation layer (View) starts to execute heavy domain logic, or when domain logic starts touching raw database/infrastructure details directly, the architecture rots.

If a developer does this in a codebase with a rigid auto-formatter, the bad code looks visually identical to the good code. The formatter wraps the lines, indents the brackets, and cleans up the spaces mechanically. It "beautifies" the architectural violation, making it invisible to the human eye during a quick scan or a pull request review. The machine hides the architectural rot by standardizing the text. In contrast, when you allow semantic text layout, developers can visually group and structure text differently depending on the layer or the data lifecycle. A massive, bloated architectural leak looks chaotic and stands out like a sore thumb in the text flow before it ever reaches a compiler or a QA check.

For example: I use very specific abbreviations for primitive or core types—only those. All other variables start with a full descriptive name, like std::vector<some_object> vectorListOfSomething;. When you write code like this and class names get too long, the code visually becomes ugly. And you shouldn't have long class names, as that is usually the first indication that you are violating the Single Responsibility Principle (the S in SOLID). With Hungarian notation, you can intentionally create styles that make bad code look physically ugly on the screen. That makes it a lot simpler to spot immediately.

I will reply here instead of at the top level simply because this is the first time in this thread i have actually found something factual we can actually talk about at all.

The very thing you are describing here is code that violates the layer of abstraction. At least thats the more recent term I have seen for exactly this problem. Code reaching into stuff that it has no place to touch directly. It does violate architecture, massively so.
It is the canonical "we'll fix it later" hack to get something working faster. Of course if you let that proliferate, it will break your codebase eventually.
100% agreed on this. This is terrible - even though rarely it could be seen as an actual tradeoff.

Yet you still completely lost me on how that can possibly relate to code formatters or concrete text layout of the implementation.
Let me repeat myself here once more - even though I dislike hungarian notation and i don't think it adds anything to your statement here (i.e. the statement is true with and without hungarian notation, its tangential imo):
I agree with you here.

And yet, I entirely fail to see your point on how this relates to code formatters at all.
You are talking about good naming here. And everything you say about names and their importance is true.
But a code formatter does not touch your names, like at all?

what does any of this have to do with indentation or bracket placement or line wrapping?

1

u/gosh Jul 05 '26

Sorry for short answer but that is deliberate, based on your respons I know better how to answer.

Do you write code like this lowerCamelCase or java style type. And do you know why you do that if you write code like this?

Another question. Are you adding a space between if (, swtich (, for ( and do you know why

0

u/gosh Jul 05 '26

To explain what indentation, line wrapping, and spaces have to do with this, we need to look at why those specific "standard" rules exist. They are actually historical restrictions designed to limit what you can see:

The space in if ( or switch (: Today, this space is completely unnecessary. It is a relic from the 1980s when we wrote code on monochrome screens that were only 40 characters wide. Developers had to abuse whitespace just to make the text readable on terrible hardware. Yet today, formatters enforce it like a holy commandment.

The lowerCamelCase style: This was heavily popularized by Java for a very specific, strategic reason. Java wanted to distance itself from C++. To do that, they wanted to stop C++ developers from using text-tricks and notation to encode architecture and context directly into the variable name. lowerCamelCase was intentionally chosen because that specific text shape effectively blocks you from using other characters or structures to signal context. It was a smart business move by Sun Microsystems to make Java look less "technical" than C++, but it effectively blinded the developer's ability to use the text shape as an architectural tool.

Those of us who use the text to actively describe context and boundaries notice this immediately. lowerCamelCase and rigid line-wrapping aren't "clean code"—they are tools that intentionally block semantic text layout.