
- 6
- 250 106
xDahl
เข้าร่วมเมื่อ 14 พ.ค. 2022
I sometimes write subpar code, and the rest of the time I write garbage code.
Getting into electronics soon.
Getting into electronics soon.
วีดีโอ
Casey Muratori | Smart-Pointers, RAII, ZII? Becoming an N+2 programmer
มุมมอง 54K3 หลายเดือนก่อน
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 (R...
Testing my ncurses alternative library (inputs).
มุมมอง 185ปีที่แล้ว
I will not apologize for the white theme... Anyway, NCurses is great, but it's sometimes cumbersome to work with, and since it doesn't free all memory, it makes memory leaks harder to find with Valgrind. For this reason (and many others), I decided to make my own small library; specifically, this one is tailored towards a program I am making (Can't wait to show that one in action). It isn't mea...
Tabs for indentation, spaces for alignment always works.
มุมมอง 2512 ปีที่แล้ว
No, changing your indentation width doesn't mess up your alignment.
(DEMO) Gap Buffer written in C.
มุมมอง 1.5K2 ปีที่แล้ว
Gap-Buffers are my second favorite data structure, purely based on its simplicity and speed. In this video, I had a VERY small gap, to demonstrate how it works (And to keep things on a single line). You can write an implementation around 50 lines of code or less. My implementation here is rather poor, but it was just to demonstrate the concept. I don't see a lot of videos about it on TH-cam, fo...
That's a take I disagree with, simply because RAII perfectly applies to group thinking. It has nothing to do with individual elements. You can obviously use RAII to free up the whole pool, but you can also implement an object that automatically releases a thing back to the pool. And what it gives you is that you know that thing came from a pool. It's not just a pointer you know nothing about. And if you didn't use RAII, you'd have to ask yourself a bunch of questions about that pointer: Is it supposed to be freed? Is it a reference? Does it come from the stack? How was that allocated? RAII gives you that answer right away and it makes it much easier to work with existing large codebases.
How would you feel about code that dereferences a smart pointer and then passes that pointer to functions (assuming that those functions do not have external side effects)? So once those functions complete, you can assume that no external state contains that pointer. Ehh, I guess what I'm trying to argue against is forcing every function to de-reference a smart pointer. Constantly incrementing and decrementing an atomic counter does become slow, but it probably doesn't matter for non-realtime applications. I find myself leaning towards Rust these days since it tracks lifetimes automatically.
In my opinion most of the RAII paranoia comes from "trying to manage memory perfectly, with zero delay in time, without a single byte waste in space, and minimize memory copy (or represent data relationships) with pointer/references everywhere", or "trying to modeling the real world perfectly with abstract concept of objects rather than plain data", the seek for perfectionism is the thing that brings all the RAII and smart pointer stuff. I was a perfectionist myself in the past, until later I realized that most of the time, I actually don't need that level of precision. Take your example, do I actually need to release the pool slot IMMEDIATELY after the object is no more needed? My answer is NO, in 99% times I could just bear some waste of space and time, allocate scratch pools and do memory copy back and forth as needed, leave the pool slot as occupied even if a object is no more needed, and release this pool altogether in a later phase when the job is done. The program memory structure now would not look like a tree or graph of objects referencing each other with pointers/references (OOP thinking), but would look like a bunch of long-lived pools and ephemeral pools of data where the data is being copied and processed between them (Data-Oriented thinking or the Entity-Component-System way). In the DOD (ECS) way, RAII could be used, but not necessarily brings any more benefits, since handling pools of plain data is way easier than handling a web of inter-referencing objects.
It was a little surprised with how he described his memory managment model. So just allocate a huge chunk of memory and then write your own memory management function and you request memory from that? So he just has his own version of malloc? So at some point he is just like `byte array = malloc(200mb)`?
i miss weird al scout
2,000 YEARS OF HUMAN EVOLUTION ---
The Problem ist, that young and unexperienced Developers very often try to teach/convince me as a very experienced programmer by using "modern techniques" as smart pointer and finally drop the old "insecure" stuff. They tell me that "today nobody uses raw pointers any longer". He intentionally suppressed to say "...as you dinosaur" ;-) - But I sometimes when people argue very strongly I'm able to minds! 🤓 But that's another story... After some discussion I recognised that the basic problem is that the buddy didn't really understood pointers but applies smart pointers solely in order to be smart (as we know - everybody is "smart" uuuuh). That said smart Pointers in his world of thinking are supposed to let him "feel better / more secure" - in order to give him a feeling of safeness. That is because "smart" sounds... ...smart. ;-) IMO this is a quite dangerous attitude.
Great Video Great advices. Great argued! 👍 As I hear your arguments I very often thought that my Thinking is talking!
I come back every once in a while to rewatch this, its a good reminder and you get little nuggets every time
"High performance lubrication"
the heavy is flummoxed by how much the hardware store has
This kind of applies to web development as well. If you just make a monolith the you can just solve the problem simply and efficiently instead of breaking it apart into a million separate services and introducing failure point into your solution
the incentives in our profession are set such that garbage code is encouraged, you have all these cloud providers which coincidentally happen to be the corps that run bunch of bootcamps or sponsor coding bootcamps... they dont need you to know or want to write efficient clean code, they need you to write that garbage so your cloud bill is thicker. Microsoft/Amazon/Oracle all encourage this and most training material/courses are sponsored by them. So we have this outcome.
In my practice high performance code is mostly allocate and reuse there is no free... even though i do JVM based systems, the things that good systems share are the same across most languages.
Is that what you want the store employee to tell you when you ask him about what things do they have?
i'd argue if you start from array-programming language (ie one where everything is typically encoded as arrays / SoA and most operators and math functions can accept either scalars or arrays) you can avoid object-oriented stage somewhat (eg my initial realization that objects are quite stupid when i was writing something in python with heavy usage of numpy arrays).
do you agree with him?
Thats not entirely true. Advanced OOP programmers know that through heuristics like rule of 3, rule of 5 and single responsibility. This means advanced C++ programmers write calsses dedicated solely to manage memory (SRP) in a comprehensive way (rule of 3/5) - which ends up them thinking about systems and their data having the same lifetime - I've seen people doing talks precisely about this on CppCon. This is, of course, more indirect and I appreciate Casey for being explicit, but the 'median' programmers are slowly getting there.
I could not get past the 100 days of hand made hero (burnout), I might go back to learn more and try to get +600
This is of course a game programming stream, so it's not an issue if a failure mode means not rendering something. In other fields like firmware programming, high frequency trading, kernel code, etc this is really not acceptable.
Everybody does it right in their very first program. Nobody individually allocates every character for "Hello, World", they group it together into a single lifetime as a string. ... then we teach them to individually track every byte.
But this only makes meet the polka better
@xDahl. Thanks for this extract. I'm a big fan of Casey Muratori's approach to programming as well. Just curious, if this video is the 2nd most important advice on programming you ever saw, what's the most important one? Is it the link in your pinned message - the talk on DoD?
Imo it would be funnier if: 1. It was acapella 2. It didn't have "would ya look at all that stuff" at the start 3. It didn't randomly cut to heavy
mfs are uploading worse versions of your version, months later... they dont have nearly as much effort put into them, all the clips are basically the same speed and worse quality yet still somehow "HD" they also dont bother changing the frame of his pose to semi-match the song, or get the 'lip-sync' anywhere as nice
I need a version where someone actually animates his mouth to sync with every word while still being over exaggerated and keeping the rest of his body completely inanimate
"I try not to talk too derogatory about these things, because it was me." - yeah stealing that one.
we all are ; )
They got
Scout be spittin facts
{Mostly game focused here...} This is all great stuff, and after 25 years, Ive seen most if not all of this stuff, from radically different teams. Im glad folks like Mike Acton and Casey are spreading the word of better designs and such, but I feel often theyre a bit too dogmatic on best and 'proper'. Its completely fine and good enough to do what feels just slightly above your current learning level but actually build something, vs spending way too many hours trying to be 'perfect' and like some of these folks are going on about. I see way too many new gamedevs trying to be impressive in style, vs just building something fun. But, about the talk. Loading in blocks of heterogenous but 1:1 associated data is absolutely fantastic. Dealing with entities in a SoA style system (for the gameplay information) is also really solid. However, having situations where you have any N:1 (or N:K) links is where things can be tricky. One thing Id love to see is how to handle say, streaming assets along with arbitrary NPCs being alive, and having assets in different pools for the sake of good GPU usage (though, I have heard they are much better allowing arbitrary buffers nowadays, and havent done a good deep dive there, but lets assume they like different types of data in different buffers) Ive found different methods work for different needs, though that can complicate the codebase more than using a single type of design along with accepting the warts for the parts it doesnt work well for. If I was working with a more junior team or we planned on hiring more junior folks to fill out the team, I might fall back to a more RAII style (which he essentially mentions) with some of his concepts hidden behind APIs. Which is not an uncommon design for a few engines. Between multicore and CPU caches, the single object simple model is essentially dead. Processing large sets of data just once per frame along with doing it in a simple and multicore friendly format is really solid. On the flip side of all this is that fact that a HUGE number of games can honestly be in a slower but easier to build style and still be awesome and professional and fun. Sorry, this got way too rambly.
{Re Gameplay vs Engine .:. Ive found theres a distinctly different use case and dev method between gameplay data and engine data, which isnt often talked about in these talks. You can absolutely build your gameplay layer like your engine layer, but often youre use case, and your users are so different that another technique would likely be better. Ie, scripting languages, simpler constructs. More individual resource thinking at the gameplay layer, with group thinking at the engine layer. One of the most impressive engines Ive seen in regards to gameplay has been the Tomorrow Corporations engine. Could you build say, Destiny 2 or H0D in it? Absolutely not, but for the games it can build its just fantabulous}
The teacher when I ask what this thing can do for my life.
Casey is describing good strategies for managing memory when programming, not just to reduce mistakes but also for performance. However I believe he is delusional to think that these strategies then make smart pointers/borrow checkers irrelevant. I've watched him in his videos spend a lot of time tracking down tricky pointer mistakes. You can use all of these same strategies with smart pointers or rust or garbage collected languages and still get all the benefits, and then you also have the compiler checking your work. Perhaps for single player video games people don't see the value in that, or they don't feel it is worth the downsides. But for work where security is a concern on top of just crashes and bugs (databases, operating systems, multiplayer servers) its only better to have more mistakes caught.
I don't entirely disagree with you, but I don't think he's delusional here, just tired of advice that don't apply to him and most cases. Smart-Pointers are a perfectly fine tool that have their use cases, same for the BorrowChecker. A large part of why some still need to deal with tricky pointers though is due to the language design of C, it was fine for the time period it came from but is lacking today for modern machines. Sadly, new languages haven't been good enough at replacing the needs of every C/C++ developer, and it will take time before they do. Last time I checked, Casey was interested in JAI. I've moved onto Odin, as I got tired of dealing with C's problems and spec lawyers.
I would have at least 100 stutters trying to say all that
I wondered how to create repeat mapped memory page...
fuck this song is a banger
Me mentioning that I saved a little extra money for emergencies My phone after the Google/Apple spyware heard that: 0:05
I had this on 2x speed because i watched the last video on it and i thought that was how the video was supposed to be lol
As a developer with 30+ years of experience I can clearly see why "grouped element thinking" is so important and how it relates to good data oriented design.
Would you look at all that stuff..... they've got allen wrenches, gerbil feeders, toilet seats, electric heaters Trash compactors, juice extractor, shower rods and water meters Walkie-talkies, copper wires safety goggles, radial tires BB pellets, rubber mallets, fans and dehumidifiers Picture hangers, paper cutters, waffle irons, window shutters Paint removers, window louvres, masking tape and plastic gutters Kitchen faucets, folding tables, weather stripping, jumper cables Hooks and tackle, grout and spackle, power foggers, spoons and ladles Pesticides for fumigation, high-performance lubrication Metal roofing, water proofing, multi-purpose insulation Air compressors, brass connectors, wrecking chisels, smoke detectors Tire guages, hamster cages, thermostats and bug deflectors Trailer hitch demagnetizers, automatic circumcisers Tennis rackets, angle brackets, Duracells and Energizers Soffit panels, circuit brakers, vacuum cleaners, coffee makers Calculators, generators, matching salt and pepper shakers
I was fully expecting heavy to get shocked at the mention of "automatic circumcisors"
In the context of a web application server (request/response based, everything kinda is self-contained and hierarchical), how would one go from n to n+1? (With specific examples).
Casey out here being the hoe_math of programming.
Good stuff. So much of getting better at programming is recognizing how your choice of system design is causing you to do more work than is actually needed. When you've come up with a design that's so simple and has so few failure points, it feels so good.
Here's a fun game! Count every item scout has spoke out
Heavy: Wow Scout, is impressive you know all that! Um…Scout? Scout take breath now! DOCTOR
They’ve got: Allen wrenches, gerbil feeders, toilet seats, electric heaters, trash compactors, juice extractors, shower rods and water meters, walkie talkies, copper wires, safety goggles, radial tires, bb pellets, rubber mallets, fans and dehumidifiers, picture hangers, paper cutters, waffle irons, window shutters, paint removers, window louvres, masking tape and plastic gutters, kitchen faucets, folding tables, weather stripping jumper cables, hooks and tackle, grout and spackle, power foggers, spoons and ladles, pesticide for fumigation, high performance lubrication, metal roofing, water proofing, multipurpose insulation, air compressors, brass connectors, wrecking chisels, smoke detectors, tire gauges, hamster cages, thermostats and bug deflectors, trailer hitch demagnetizers, automatic circumcisers, tennis rackets, ankle brackets, Duracells and energizers, soffit panels, vacuum cleaners, circuit breakers, coffee makers, calculators, generators, matching salt and pepper shakers 😂😂
Remember, when they go to Home Depot use Engineer’s phone number he has a discount
Scouts teeth don’t move…
Fire🔥✨🔥✨🔥✨
My dad when I ask if we can get ice cream on the way to Home Depot:
eminem been real quiet ever since this dropped
Isn't he basically talking about arena allocation at that point?
Yes and no, there's more than just arenas for custom allocators.