Skip to content
0:00 / 0:00

#raii#smartpointers#zeroisinitialization

Casey Muratori | Smart-Pointers, RAII, ZII? Becoming an N+2 programmer

xDahl

1.2K subscribers • 1 video on Hallway

YouTube
  • Recommended by 6 people: 6 on Hacker News.
  • Presented by Casey Muratori, founder of Molly Rocket
  • An opinion. It argues one side of a question engineers disagree on.

Advanced. Deep dive for people who know the field.

162K views2 years ago6 recommendations

Systems programmingSoftware designMemory managementDesign patternsC++

Casey Muratori critiques RAII and smart pointers, advocating for grouped-element thinking and zero-is-initialization as superior memory management paradigms.

Casey Muratori giving his thoughts on smart-pointers, RAII, OOP, briefly the Rust borrow checker etc, and why you should avoid them and instead focus on learning and moving to the next stage of programming; "Grouped element thinking and systems", which he refers to as N+1. Casey also talks about ZII (Zero Is Initialization) and stubs as alternative ways of memory structure and error handling (Referred to as N+2 in the stream). Source clip from: watch?v=f4ioc8-lDc0 @ I own nothing here, all copyright is reserved for Casey! I just wanted a better and more convenient way of sharing this information, as I find this clip to be extremely valuable. But some parts contained silence and unrelated topics, which I cut out. Frankly, I find this clip to have been the second most important advice on programming I ever saw.

Why it's here

6 people recommend this, 1 disputes it

What people say. Recommended by systems programmers for its alternative perspective on memory management, bulk allocations, and critiques of RAII.

bsderon Hacker News • Recommends

On “Committing to Rust in the Kernel”

C and C++ are very different. I think Casey Muratori hits the nail on the head here: link to this video In short, RAII and smart pointers and borrow checker are all signs of "individual element thinking" and that way lies madness. You smear out lifetime and ownership so badly that it practically by definition becomes a problem. Your goal is to think about this stuff in groups to make thinking about allocation way, way easier. Programming is all about abstracting to the next layer. I'm not sure he has quite gotten to the heart of the issue, yet. However, a bunch of smart people (Casey Muratori, Jonathan Blow, Andrew Kelley, etc.) are all dancing around something that Rust and C++ don't seem to fit the b…

gingerBillon Hacker News • Recommends

On “Odin: Moving Towards a New "core:OS"”

…of languages to Odin and their approach does not translate well to what Odin (or C) is trying to do. Unfortunately I will not be able to explain this to you in a comment or article, and it is something that takes a while to understand since it is a subtle effect of locality affecting globality. The best video on this might be from Casey Muratori: link to this video > Yes, initialization can be less efficient in Rust but then most of the time spent is spend in algorithms when they run, not during initialization of the data structure. Sadly this isn't as true as you think it is. I've written a lot of C++ code before and doing its boilerplate for ctors/dtors actually leads to much slower code in general,…

jackclaytonon Hacker News • Recommends

On “Claude Code uses Bun written in Rust now”

Above poster is talking about thinking in terms of grouped lifetimes and bulk allocations/deallocations, which is better for performance, and makes Rust borrow checking and other RAII style features completely pointless as they don't add any safety benefits. I used to think like you until I watched this video: link to this video I can confirm after exploring programming like the above video explains, that everything he says is completely true.

slowmovintargeton Hacker News • Recommends

On “Odin: A programming language made for me”

Here's Casey Muratori on his habit of moving to ZII: link to this video Much better outcomes and failure modes than RAII. IIRC, Odin mentions game programming as one of its use cases.

gingerBillon Hacker News • Recommends

On “Odin: A programming language made for me”

…hetical approach to things. So of course each style is about trade-offs. There are no solutions, only trade-offs. And different styles will have different trade-offs, even if they are not immediately obvious and require a bit of experience. A good little video on this is from Casey Muratori, "Smart-Pointers, RAII, ZII? Becoming an N+2 programmer": link to this video…

thegeekpirateon Hacker News • Recommends

On “Zig's new plan for asynchronous programs”

There's a GC library around somewhere, but I doubt anyone uses it. Manual memory management is generally quite simple, as long as you aren't using archaic languages. link to this video is worth a watch.

ChrisTrenkampon Hacker News • Recommends

On “Bun ported to Rust in 6 days”

…here's no in-between, and C programmers are dinosaurs who can be ignored. Arena allocators are a great way to automatically manage memory allocations. You malloc a whole bunch of memory and release it all with a single free, which makes it much easier to reason about your program's memory safety. Casey Muratori has a good video talking about this. link to this video And about Zig, you have an Arena Allocator out of the box: link . And it's not just limited to that, you have debug allocators that detects memory leaks and gives you stack traces where they occurred. This isn't to say that Zig is great at everything. I think Rust is great for things like kernels, high-frequency trading systems, and authe…

Capricorn2481on Hacker News • Disputes

On “Thoughts on Go vs. Rust vs. Zig”

…hese hidden allocations, citing this exact Casey Muratori video. And it was weird. A bunch of people pointed out the inaccuracies in the post, including Lina 2. That combined with Andrew saying Go is for people without taste (not that I like Go myself), I'm not digging Zig's vibe of dunking on other companies and languages to sell their own. 1 link to this video 2 link…

u/tav_stuffin r/C_Programming • Mentions

On “What is your preferred naming convention for constructors and destructors in C?”

Mostly just experimentation and learning from those most experienced to me. I started as the classical programmer that malloc()s every individual item and painstakingly frees them, I then graduated to C++ smart pointer nonsense, and then graduated to ‘group thinking’ where you stop thinking about individual items and think about entire systems. This of course happened over many years, not immediately. Casey Mouratori has a great video on these exact concepts actually, I really recommend you watch it! It’s where I stole the term ‘ZII’ from even though I was doing that before I had ever heard of him: link to this video

budroon Hacker News • Mentions

On “Show HN: Uscope, a new Linux debugger written from scratch”

…es it easy to write spaghetti code that uses reference counting all over the place. I don't recommend people to use Rust until they become a "N+1 programmer" that Casey Muratori describes as "grouped element thinking" 1. At this point, most of that programmers problems are solved and suddenly the Zig vs Rust debate becomes much more nuanced. 1 link to this video…

u/Natehhgghin r/compsci • Mentions

On “what is the alternative to object-orientation?”

…c as separate as possible. and always prioritize what data is needed to solve the problem first. And there's a lot of emphasis on reusing datatype as much as possible, and how powerful typed unions, and fat structs can be. Mike Acton has a great talk at cpp con, that is a good primer on the subject, why it's important, and what it looks like. [video Anton Mikhailov had some a good demonstration of how you can take a simple api, and as you add in high level features, the complexity of the api starts to explode, and how that turns into adding more unavoidable error conditions. [video Eskil Steenberg on how to architect large systems without classes. [video Casey Murato…

u/igors84in r/ProgrammingLanguages • Mentions

On “I feel obliged to implement a borrow checker”

Please watch this clip link to this video . In it Casey explains how you might just not have evolved your thinking of memory management enough to see that there are much simpler and more effective ways of managing memory than having to keep track of every allocation .