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

-5

u/gosh Jul 05 '26

You are completely misunderstanding my point. This is not about individual engineers using their own personal "feelings" or styles to format code. That obviously causes chaos in a team.

It is about the team establishing a shared, semantic visual pattern, precisely like the engineering philosophy behind Hungarian Notation.

You mentioned primitive types. Take standard prefixes like b, i, u, d, p (bool, int, unsigned, double, pointer). The massive benefit of a shared notation like this isn't actually to read them; it is to skip them. If a method has 15 variables and 12 are primitives with clear prefixes, the developer's brain instantly filters them out to focus on the 3 complex domain types that actually matter.

This is about cognitive efficiency. The ultimate goal of software architecture and semantic formatting is to write code in recognizable visual patterns so that it does not need to be read line-by-line to be understood.

Human brains scale through pattern recognition, not by parsing raw text like a compiler. When an automatic formatter forces a flat, mechanical style across every single layer, it destroys those patterns. If your only tool for communication is a text comment or a wiki entry, you are relying on a medium that actively rots and slows down development in a 200k+ line codebase.

Dismissing visual ergonomics as "healing candles" just shows a lack of understanding of how human cognition operates at scale.

0

u/[deleted] Jul 05 '26

[deleted] — view deleted comment

-2

u/gosh Jul 05 '26

You are still missing the core point. This has nothing to do with my "preferred" style or personal feelings.

The medium we are using right now is a Reddit text thread. I am skim reading and replying quickly. But in a real software team, there is more time and I know how reddit "works". Very hard to have deep conversations

My point is, and always has been, about architecture. It is not about a specific style.

The problem with automated formatters is that they make developers stop thinking about the visual structure of their code. When a machine flattens everything into an identical, mechanical template, the architectural boundaries disappear.

If you want to know what my actual personal preference is: it would be to not use formatters at all, just turn them off.

ability to adapt their code's layout to highlight its architectural layers, the architecture becomes invisible, and the codebase eventually rots. That is the only thesis here.

0

u/[deleted] Jul 05 '26

[deleted] — view deleted comment

-2

u/gosh Jul 05 '26

Since you are out, I'll leave you with a very practical question to think about: How many legacy codebases across different companies have you actually audited?

If you had audited as many as I have, you would know that it is an empirical fact, not a mere "claim", that the vast majority of corporate codebases are in a abysmal, rotting state. And guess what? Many of those broken, unmaintainable systems run automated formatters and linters to perfection.

0

u/[deleted] Jul 05 '26

[deleted] — view deleted comment

0

u/gosh Jul 05 '26

That isn't an argument. And goes back to what I said that your vision of your claim isn't enough to convince others that that claim holds merit.

Don't you think I know how hard this is to explain to developers today? It wasn't this hard to explain 20+ years ago, but today it is almost impossible.

Some understand it, and they are the ones who become those "10x developers". But it is extremely difficult to get through today because the groupthink is massive, and modern software development is completely dominated by Big Tech dogmas.

-1

u/gosh Jul 05 '26

That question is teetering pretty close to appeal to authority, but since you asked, and I have said this in the past in this sub.

And what have you learned from auditing all those engines and browsers?

Look at Chromium, which you mentioned. We live in a world where one browser engine essentially holds a monopoly. Why? Because the codebase has become so overwhelmingly complex and architecturally rigid that it is nearly impossible for anyone to build a modern competitor from scratch.

When codebases reach that scale, teams are forced to introduce extreme administrative overhead, rigid automated formatters, and layers of QA just to keep the system from collapsing. But that proves my exact point: those tools are introduced as an emergency brake because the code itself has become visually stum. The text layout no longer gives the developer any native, human semantic cues about boundaries, so you have to let a machine enforce safety via formatting.

0

u/[deleted] Jul 05 '26

[deleted] — view deleted comment

1

u/gosh Jul 05 '26

It's a derailing of the actual discussion, but I have some time to burn. For games in particular, that there's a whole bunch of ways to write the same thing. That it's rare to see consistency in projects such as games codebases

And that is not surprising at all. Most games are transactional software. They are written under extreme time pressure, often with the mentality of "get it out the door and see if it sells." You cannot over-invest in long-term architecture for a product that might be dead in six months.

Also you need to find developers, adapt to developers that you can get. The pay for game development is not sky high because there are a lot of new game developers out there.

But look at a general-purpose game engine, or an operating system kernel. There, you have a completely different situation. You are designing for a lifespan of 10 to 20 years. The code must be written differently because consistency and architectural boundaries are everything.

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.

There are plenty of other things you can do, especially when combining this with comments in code.

I use *_g for globals, *_s for statics, and *_d for debug code. I also use namespaces strictly for general, company wide code, code that is meant to be shared between completely different projects in that environment. However, I use no namespaces for local code that is confined to a single target.

Why use namespaces for shared code but not local code? Because you work with local repository code constantly, and local namespaces just add noise and make the code harder to work with. Shared company-wide code has namespaces, so you can spot it instantly in the local file when it's being pulled in. For general, write-once-run-everywhere code, I use lower_camel_case to match the STL. These styles exist to guard the code, because modifying shared code is always high-risk.

Another division I enforce is between value classes, collection classes, and facade classes. I try very hard to stick to these three types and follow that pattern as closely as possible. I can tell exactly what type of object it is just by looking at the name.

I also use folders to divide layers in a specific project, so placement explicitly shows intent. This folder structure is more important than pure functionality. It is always better to spend a little more time keeping the folder pattern intact rather than hacking a quick solution into a random file.

Naming is VERY, VERY important as well, but this text is already getting long. The point is: I use names in a highly specific, architectural way.

So, what am I actually saying here?

Managing code architecture is a massive, nuanced discipline, but you have to be open to letting the text speak to you. Using a rigid, automated formatter destroys all of this. Every single one of these subtle, visual defense mechanisms just stops working.

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?

→ More replies

5

u/ts826848 Jul 05 '26

We live in a world where one browser engine essentially holds a monopoly. Why? Because the codebase has become so overwhelmingly complex and architecturally rigid that it is nearly impossible for anyone to build a modern competitor from scratch.

OK, sure, let's assume Chromium's codebase is indeed "overwhelmingly complex and architecturally rigid". I strongly suspect that people don't decide to use Chromium because of that, though.

A significant portion (if not majority?) of Chromium (or Chrome/Electron/etc.) users rely on its output/behavior, like how webpages/UIs render/behave/perform/etc., and those users pick Chromium+derivatives for function/uniformity/consistency/etc. instead of having to deal with browser/engine-specific breakage/quirks. In these cases the quality of the codebase has zero direct impact on a potential user's decision to use Chrome since they aren't directly interacting with the C++ code.

In addition, web standards are complex and they're not getting simpler any time soon. It's a lot of work to implement a web browser even with "perfect" code, and few would have the time/energy/interest in doing so, especially if a browser isn't your main product.

Because the codebase has become so overwhelmingly complex and architecturally rigid that it is nearly impossible for anyone to build a modern competitor from scratch.

This seems like a non-sequitur. Why would the complexity of Chromium's codebase have any impact on an independent codebase, especially since compatibility is generally dictated by web standards and not C++ APIs?

2

u/serviscope_minor Jul 06 '26

Many of those broken, unmaintainable systems run automated formatters and linters to perfection.

Sure? But also, so what? They also pass all the type checks built into the compiler cleanly, but having them be bad isn't a justification for abandoning type checking.

Firstly I have no idea what your architecture through formatting looks like.

Secondly as someone else pointed out, autoformatting prevents bikeshedding. That alone is reason enough to use it. Some people care way, way too much about the exact positioning of braces and whatnot. I've worked in enough codebases that I barely see it anymore[*]. I used to care a lot. Now I don't. Every so often I do use formatting to show something, usually making things aligned to make it easy to see similarities, so maybe a few extra spaces are needed.

No tools will fix fundamentally broken processes but they can help make things a bit better. If I never have to argue a bikeshedding formatting comment on a PR again I will be happy. If I never have to debug a silly bug which was caught by running basic checks again I will be happy.

[*] FSF I love what you've given us, but good god your house indent style makes my eyes bleed.

1

u/gosh Jul 06 '26

Secondly as someone else pointed out, autoformatting prevents bikeshedding

How?

way too much about the exact positioning of braces and whatnot.

This is not about braces, far from it

1

u/serviscope_minor Jul 06 '26

Well if auto formatting puts braces in the same place there's no arguing about that on PRs.

So ok not about braces but you've never said what it is about except in general terms. Please provide a concrete example, because I don't understand what you've written so far.

0

u/gosh Jul 06 '26

thats for another thread, like tutorial "how to code"