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

-24

u/gosh Jul 05 '26

sample:

Code layers

TypeDescription
general codeSimilar to stl, general code is written in lower case leters
source codeSource code can be used by any target. Each part in source is placed in some sort of namespace. Style is in PascalCase and each class starts with C
target codeCode in each separate target are only used in that target and isn't placed in a namespace, other than that style is similar to source code
play codeno rules, do as you wish
test codeno rules, do as you wish

The Learning Curve Comparison adding new developers

Traditional Java style (that is common):
Quality
    ^
    |                              Production (terrifying)
    |                         Production (still scary)
    |                    Production (oh god)
    |               Production (help)
    |          Production (what is safe?)
    +----------------------------------------> Time
    Day 1                                      Month 3

Layered:
Quality
    ^
    |                                         General (gold)
    |                                   Source (corporate)
    |                            Target (specific)
    |                     Play (fun!)
    |              Play (learning)
    +----------------------------------------> Time
    Day 1                                      Month 3

6

u/OlivierTwist Jul 05 '26

I think it's much easier in practice: there are just 2 most commonly used naming conventions in C++ nowadays (that is what you are actually talking about, not formatting): boost/STL snake_case and Qt CamelCase with some mixes and small variations. Both can be used for equally critical code, both can be enforced with linters. The only really annoying things are when people invent some new naming scheme or inconsistency/mixing of different styles in the same file.

2

u/gosh Jul 05 '26

The only really annoying things are when people invent some new naming scheme or inconsistency/mixing of different styles in the same file.

If you do not have rules on how to name stuff, then you will invent all the time

4

u/OlivierTwist Jul 05 '26

Sure rules are needed and should be enforced, all exceptions explicitly marked in code. Just follow boost/Qt/Linux style depending on context and history of the project.

1

u/gosh Jul 05 '26

what type of rules do you have?

2

u/OlivierTwist Jul 05 '26

Depends on a project. Greenfield projects have strict rules from day one (clang format, clang tidy, include what you use, spelling, warning as errors, 3+ compilers in CI). 30 years old code base have some check only in a new modules.

1

u/gosh Jul 05 '26

can you give some samples on how to have rules that show context?

1

u/OlivierTwist Jul 05 '26

In your case "context" means namespace. Clang can enforce namespaces names format and probably no "using namespace" in headers.

1

u/gosh Jul 05 '26

context as in architecture. like mvvm etc.

1

u/OlivierTwist Jul 05 '26

context as in architecture

Phrase doesn't make any sense.

mvvm

Qt uses MVC a lot. Name convention is absolutely orthogonal.

→ More replies

2

u/oriolid Jul 05 '26

I think I get it now. Most real-world codebases end up mixing naming conventions, because Boost and standard library have one, Qt a different one, and things like Windows API, Cocoa and different third-party libraries add even more. The OP thinks it's useful rather than an accident and wants to extend it inside the project too.

2

u/OlivierTwist Jul 05 '26

Seems so snd I don't see any value in such formalization.