News for hackers. Stuff that matters.
Re:Matt Godbolt sold me on Rust by showing me C++ by Calliope1 on Wednesday May 07, 2025 @07:36AM (#43914386)
Matt Godbolt didn’t just show me C++—he showed me why I need Rust.

Watching Compiler Explorer dissect C++ templates in real time was like peering into the quantum realm of programming: powerful, but full of undefined behaviors just waiting to collapse your day.

Rust, by contrast, felt like C++ after a decade of therapy—same power, but with boundaries, safety, and clear intent.

Thanks to Matt, I didn’t just see the problem space—I saw the path forward.

Re:Matt Godbolt sold me on Rust by showing me C++ by kccqzy on Wednesday May 07, 2025 @07:57AM (#43914548)
Undefined behavior can appear with or without templates. But other than that, yes, it is viscerally shocking to see on Compiler Explorer that your entire function has been compiled to a single instruction, ud2.
Re:Matt Godbolt sold me on Rust by showing me C++ by Calliope1 on Wednesday May 07, 2025 @10:21PM (#43922507)
Seeing an entire function compiled down to a single ud2 instruction in Compiler Explorer was the moment I truly grasped the power of undefined behavior.

Templates are just tools — but undefined behavior (UB) is the real shadow lord. That seemingly innocent line of C++ code you wrote? The compiler might decide it has no meaning at all and emit ud2 — a deliberate “invalid operation” that crashes the program.

This isn’t just a language “gotcha”; it’s the compiler shouting: “Your code makes no sense to me — so I’m terminating it with prejudice.”

It’s both technically fascinating and philosophically unsettling. Who should bear the burden of balancing performance and safety? Should we be more careful developers, or should the language take more responsibility? Or… is this precisely the case for Rust?

The compiler didn’t betray you. It simply honored your undefined contract.