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?
49
u/OlivierTwist Jul 05 '26
Can you give a clear example where formatting and architecture aren't orthogonal?
20
u/AKostur Jul 05 '26
Every formatter that I’ve used has mechanisms to exclude sections of code. Thus the vast majority of the code can be a consistent format, and the places where it’s not stands out more because it’s delimited as being intentionally inconsistent.
18
u/GrammelHupfNockler Jul 05 '26
I'll be a bit blunt and say: If your architecture is (partially) represented or maintained by whitespace, you are probably doing something wrong. Formatters follow and highlight the structure of the AST and eliminate any bike-shedding about low-level syntax style, sometimes even highlight issues like incorrect indentation. The rare case where I've seen them destroy visually important things was when ASCII art or otherwise aligned lines of multi-line comments exceeded the hard limits we set on line length, which works as intended. Modern IDEs and LSPs provide type inlay hints, "go to definition" or hover information, eliminating the need for things like Hungarian notation for the most part.
15
u/TryToHelpPeople Jul 05 '26
This sounds like you’re constructing an argument, but it doesn’t hold up for me.
28
u/tone-bone Jul 05 '26
This feels like someone really disagrees with their company's style guide and is desperately trying to craft an argument that it shouldn't be enforced so they can put their curly braces wherever THEY want.
12
u/EC36339 Jul 05 '26
If your code heavily relies on formatting to be readable, then formatting isn't the problem.
If one part does require special formatting for some specific reasons, make it exempt from automatic formattinf somehow.
12
u/Minimonium Jul 05 '26
If your architecture fails because of poor formatting then it's not an architecture, it's a gooey mess described by scribbles in someone else's notebook that "works" until it doesn't.
I have seen plenty of bugs introduced by cutely formatted code. I'm yet to see a single case where people would say "we could have caught a bug if we have used Hungarian notation".
Developers are made efficient by giving them language enforced guarantees to reason locally about code. And by removing reasons to pointlessly bikeshed on every PR by using tools such as formatters.
9
u/oriolid Jul 05 '26
I think its' really the other way round. When I write code, I know how the structure should look when it's formatted. If clang-format doesn't produce the result I expect, it's a strong visual cue that something is wrong.
5
u/t_hunger Jul 05 '26
I think this is one of the last programming community on reddit where you can still have a 60 comment threat about code formatting in 2026.
5
u/eisenwave WG21 Member Jul 06 '26 edited Jul 06 '26
While you theoretically can express some intent by formatting code in a specific way, like aligning variable names in some places (e.g. defining a triple of constants for
float,double, andlong double), I haven't seen any evidence that teams of developers consistently do a good job at this. Most of the time, not using an auto-formatter just means that the code base becomes messy, with alignment, brace style, etc. chosen seemingly at random.I think it's far more likely that in a code base that's not auto-formatted, the differences in formatting you find are due to differences in personal preference/style by the various developers working on the code, not due to "semantic formatting" being used properly.
On the contrary, the benefits of auto-formatting are obvious and proven in practice. Just the fact that you can eliminate 100% of stupid discussions over brace style, variable alignment, overly long lines, etc. from code review saves everyone a lot of time. No one needs to manually check whether the level of indentation is correct, so developers can focus on engineering functionality instead of engineering whitespace.
It's also worth noting that you still have a huge amount of editorial freedom, even with auto-formatting. You get to choose whether to factor some helper variables out a really long expression (like making a
boolvariable before anifcondition), you decide when/how to split code into several functions, you insert blank lines between blocks of statements, etc. What's left is the auto-formatted stuff like manual alignment of variables, and that stuff is scraping the bottom of the barrel.7
u/Sopel97 Jul 05 '26
good ragebait
6
u/Friendly_Fire Jul 05 '26
I would like to see an example of how formatting emphasizes, or hides, architecture.
My opinion the opposite. Consistent formatting let's you more easily read code, and focus on the actual architectural changes. It lets you see the same basic patterns at a glance, and think at a higher level rather than figuring out what an individual line of code does.
Python's usage of white space for structure, while often criticized, is one of its great strengths IMO.
37
u/not_a_novel_account cmake dev Jul 05 '26
Oh my God you're the Hungarian notation guy.
Every time you post a new line about this I'm sitting here like, who could possibly...? And the I remember it's just one guy. Hungarian notation's last soldier, like Tom Cruise, or the New Zealander with that Indian motorcycle.
~STL
1
u/JVApen Clever is an insult, not a compliment. - T. Winters Jul 09 '26
I'm the one that pushed for auto formatters in our code base. As such, those few developers that can't handle change came to me with every example where formatting made the code worse to read.
Out of that I learned:
Id really would like to see snippets where you think formatting breaks architecture, as it really helps to talk about specific code rather than abstract concepts.
Hungarian notation is being disliked by many for a reason. It's forcing implementation details in the name of your variables. I really don't care if a "name" is a char ptr, string view, string or any other type. To understand the code, as a reader, I want to know what the purpose is. Any place where that difference between types is relevant should not influence architecture of the code.
1
u/eyes-are-fading-blue Jul 19 '26
This is the most bizarre thing I read in a long while. Formatting and architecture are two completely separate things.
2
u/gracicot Jul 07 '26
There it is. When you need to group things, use a struct, not parameters that have some grouping. A struct has a name, that grouping is physical instead. Formatting cues are simply hints for the mental model of one person and of course, that doesn't scale at all.
There's only one instance I've seen formatting needing to be disabled for grouping which is matrix initialization where 4x4 parameters were needed. That's an easy and justifiable opt out right there. The rest of the codebase is automatically formatted. I bet some structures like that benefit from turning off formatting, but that's not an excuse for turning off formatting on a whole codebase.
Easier to reason about for you. For people that don't have the same mental context or mental model as you, there is no meaningful cues to be observed.
0
u/fdwr fdwr@github 🔍 Jul 06 '26 edited Jul 06 '26
I'm not really sure what you mean by "architecture" (for which I tend to think of as broad level relationships, where you bring out the entity relationship diagrams and such), but if by "architecture" you mean the logic of the code, then my thoughts are...
Once upon a time, wise people realized that arranging code certain ways spatially increased readability of equations (e.g. adding spaces between operators, so
(1 * 2) + 3rather than jamming it into1*2+3) and logical blocks (using say 4 spaces rather than 1 or 0 spaces for indentation) and tables (aligning the columns of data rather than staggered) and function calls (spreading long multiparameter calls across separate lines for easier differing and robust merging rather than zigzap wrapping). For those wise people, code was not written to be just minimally functional but also written with an aesthetic that reduced other's cognitive load upon encountering that code. Most of these wise people naturally over time came to many of the same conclusions and patterns too.However, other unsavory coders did not care so much for other people's readability, only their own writing speed, scoffing at the reality that code is read and reread many more times than it is written. Making the code "look nice" slowed them down and seemed unnecessary. They caused a mess for others...
Then semiwise people had the epiphany that if they could forcibly reformat all code to be more consistent with simplistic rules, then they get some readability benefit for free, but they were only semiwise, failing to realize that the true aim was actually improved readability, not merely conformity, for often there are times when deviation from conformity improves readability - that exception to the rule, where permitting 1 additional column beyond the preferred line width would actually yield cleaner looking code than obeying a rigid limit. So, the automatic formatting dullbozers increased readability of bad code but decreased readability of good code, yielding a middling compromise 😕.
Having tried a dozen automated formatters over the years, I'm still looking for a truly good formatter whose primary metric is overall improved readability, not just a prioritized set of rules, not mere conformity, but actual reduced cognitive load for a reader, but I think we'd need a neural network to approach that level. Given the prevalence of LLM's these days, surely a smart one will come along soon that knows how to weigh the rules with the exceptions ⚖️ (and it will only consume 100x more power than the current ones 😅).
1
u/wyrn Jul 05 '26
I know that human being and fish can coexist peacefully
-11
u/Pannoniae Jul 05 '26 edited Jul 05 '26
lol the downvote brigade already arrived....
I don't personally agree with many of the advice (for example, systems hungarian is IMO *kind of* obsolete with IDEs - just ctrl-Q the datatype, shown immediately, apps hungarian to prefix the semantic is *much* more useful....) but it's kind of funny how people just instinctively downvote it to resolve their cognitive dissonance lol
and yeah you're right, the software development orthodoxy only brought us bloated, inefficient and expensive software, most of the hugely influential things were created "cowboy" style and not by accident.
All this linting/autoformatting/codestyle stuff just destroys semantic information and brings everything down to a lowest common denominator. I guess it's good if everything equally sucks in the name of consistency. :)
it's actually amusing to see people arguing slapping shared pointers everywhere because pretending atomic refcounting is free and totally can't cause leaks and using T* as a non-owning pointer (you unironically can't tell whether someone forgot about ownership or explicitly wants an observer - why not document it in your type?)
-1
u/RogerV Jul 05 '26
These days I use AI tools to dive into the analysis of legacy code instead of starting with visually going through and reading said code. Said code format doesn't matter to the AI analysis. And that analysis will end up highlighting what is going on functionally - it can even remark or point out when there is something clever or interesting going on.
From there is where will then start diving in to look at said code, but then I'll have some guide and clues as to what to pay careful attention to and why.
To me that approach is more robust than wringing hands about code format - which will often be something that one doesn't have any control over anyhow.