▲ 0 r/cpp

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?

reddit.com
u/gosh — 19 hours ago

The real reason behind AI (slop)

Gamer Nexus have done a lot of good videos about AI and the insane prices and overvalued companies that do not earn money.

It's a monopoly that do not want to sell personal computers, they want us to rent it. We should use terminals connected to data centers.

youtube.com
u/gosh — 1 month ago

Are vibe coders starting to wake up and understand that this was a bit harder than the marketing.

u/gosh — 2 months ago

What is best to find memory leaks?

Is it worth use tools because what I have used is code in the sample below

For those who've used hooks and dedicated tools like ASan, what does ASan and others add that is valuable.

I have been working a bit with tools but found it very problematic if code is written for different OS and there are different editors/compilers and developers have their own favorite setup.

#ifdef TARGET_COMPILER__LEAKS_CHECK
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
#include <crtdbg.h>

namespace
{
   // Tip: Use AllocHook_d and values there to set breakpoint  or find where to start debug code.

   /// @brief win32_leak_check_ is a helper class to enable memory leak check in debug mode
   struct win32_leak_check_
   {
      win32_leak_check_()
      {
         // ## Use "_CrtSetDbgFlag" - Windows C Runtime (CRT) method, acts as a master control switch for the debug heap manager
         const int iDebugFlags = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );       // get current debug flags
         _CrtSetDbgFlag( iDebugFlags | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // enable debug heap allocations and automatic leak check at program exit
         //_CrtSetBreakAlloc(12500);   // lowest alloc# set break att specific allocation number you can find this number in memory leak dump
      }
   };

   win32_leak_check_ win32leakcheck_g; // global instance to enable memory leak check in debug mode

   /// @brief AllocHook_d is called for each allocation and deallocation, set breakpoint here and inspect call stack to find where allocation is
   static int AllocHook_d(int iAllocType, void* /*pUserData*/, size_t uSize, int /*iBlockType*/, long iRequestNumber, const unsigned char* /*pFilename*/, int /*iLineNumber*/)
   {
      if( iAllocType == _HOOK_ALLOC && uSize == 320 )
      {
         std::cout << "## AllocHook: alloc# " << iRequestNumber << ", size " << uSize << std::endl;
         //__debugbreak();                                                    // attach debugger and inspect call stack here
      }
      return TRUE;
   }
}
#endif // defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
#endif // TARGET_COMPILER__LEAKS_CHECK

Full sample: https://github.com/perghosh/Data-oriented-design/blob/main/target/server/http/main.cpp

u/gosh — 2 months ago