6 ms·
The author's opinion is uncommon but not unique. A few examples: https://handmadehero.org/ https://handmadehero.org/ https://ourmachinery.com/post/physical-des
by stephc_int13 7y ago
The author's opinion is uncommon but not unique.
A few examples:
https://handmadehero.org/ https://handmadehero.org/
https://ourmachinery.com/post/physical-design/ https://ourmachinery.com/post/physical-design/
Simple libs widely used in game dev circles:
https://github.com/nothings/stb https://github.com/nothings/stb
This one is a full game engine with tools made for educational purpose:
https://www.raylib.com/ https://www.raylib.com/
I do write games and game engine code and tools in C++ without using any of the OOP features.
I know quite a few of other professional, experienced and talented developers doing the same, even full AA studios with up to 50 employees.
Some of them are going back to procedural C after a few years of disappointment with OOP madness.
I'll publish articles about this later, but for now, all I have to say is that it just works.
Newbies are often afraid of manual memory management and pointers, but there are simple ways to avoid shooting yourself in the feet with those.
- slacka 7y agoWriting game engines in C++ without using any OOP features, makes perfect sense to me. Other than the author likes C, he failed to show me why his approach is better than yours. I found it very light on details.
- ncmncm 7y agoWriting game engines in C++ without using destructors is just foolish. If by OOP you mean virtual functions? Nobody uses that stuff much anymore, except Java refugees. (They use shared pointers, too.) But, anyplace you would use a function pointer in C, it's cleaner with a virtual function, and often faster.
- skohan 7y ago> Writing game engines in C++ without using destructors is just foolish. Why? My understanding is that in modern game dev you're mostly traversing large arenas of structured memory, and you avoid freeing individual objects like the plague.
- Const-me 7y agoMemory is just one kind of resources. Games do tons of I/O, often gigabytes/second. To illustrate, any PC game has a lot of places which call GPU driver like this: D3D11_MAPPED_SUBRESOURCE mapped; context->Map( buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped ); // Write memory address pointed by mapped.pData context->Unmap( buffer, 0 ); With C++ RAII, you can do something like that instead: MappedBuffer mapped{ buffer } // Write memory address pointed by mapped.pData. // No need to do anything else, the destructor of MappedBuffer will unmap.
- ncmncm 7y agoThis. Freeing memory is the least important job for destructors.
- Scarbutt 7y agoHandmadehero started as C but transition to C++ AFAICT ?
- stephc_int13 7y agoThere is no classes, extremely rare use of templates in the Handmade Hero code. C++ with structs and 99% procedural code is actually very close to vanilla C. Let's not be pedantic here.
- p7IDD243 7y agoClasses and structs in C++ are almost the same thing with the exception of the default member visibility, unless you mean a POD?
- mattbreeden 7y agoIt was C++ from day one because he intended to use operator overloading
- ru999gol 7y agoI think he is the perfect example of why I don't care what those C (or minimalist subset C++) programmers have to say. When you actually see how he works, how much time he spends debugging his messy code. They are all sooooooo far away from what I would describe as remotely good, clean code. And all so full of themselves too of course. I liked Handmadehero for this reason, he is so arrogant and certain about how to properly write code, but when you actually see how he codes, what mess he produces and how long he spends live debugging it all the time. He constantly finds bugs in code he wrote earlier, etc. Yet he is so totally unable to find anything remotely wrong about the way he does things, and that there might have been some ideas invented in the last 30 years that could make him more productive. I have zero respect for those types of programmers. I would quit any job instantly if I ever had to work with guys like this.
- jdmoreira 7y agowow. You must be a prolific game programmer like Casey Muratori, right? You understand that he is an extremely successful programmer in his field and has the respect of thousands of programmers world wide? Maybe you can share some of your accomplishments with us.
- cwyers 7y ago> there are simple ways to avoid shooting yourself in the feet with those A cursory look at the CVE list for any C software in the wild indicates that no, there are not simple ways to avoid shooting yourself in the feet with manual memory management in C. It's _incredibly hard_ even for "elite" programmers who have a lot of incentive to avoid these problems. The counterpoint is that people are probably going to spend less time looking for ways to maliciously use those problems in your C game than they are in the Linux kernel, but there is plenty of potential for even seasoned C coders to engage in bullet-on-foot violence.
- jplayer01 7y agoThese are game developers though. On the list of requirements and priorities, I'm sure code safety is right beside commenting code and clean code. Not in a disparaging way. But tight deadlines, crazy expectations and insane work hours doesn't leave much time or energy to worry about it.
- stephc_int13 7y agoYeah, I am not talking about vulnerabilities. I am simply talking about ease of use and avoidance of leaks and crashes. Writing super secure code is usually not a requirement for gamedev, and I completely agree, this is hard and potentially harder in C than, say, in Rust.
- eropple 7y agoIt's a requirement if you do network I/O whether you realize it or not.
- tomp 7y agoIf a bug in a game's network IO crashes/takes over the whole OS, the security vulnerability is in the OS, not in the game.
- eropple 7y agoNo. Security is a full-stack endeavor. At all levels it is incumbent upon software professionals to build secure and resilient systems, any time they're exposed to a network. The OS should backstop your efforts, not replace them.
- pier25 7y ago> I do write games and game engine code and tools in C++ without using any of the OOP features. Excuse my C/C++ ignorance, but why not simply use C?
- choeger 7y agoThere is still the STL, there are still templates and data structures have a very well-defined lifetime.
- skrebbel 7y agoIsn't the STL mostly classes? How is that not OO?
- choeger 7y agoWell, yes you have some objects in there. But it is rather an implementation detail. You don't use inheritance for instance.
- gpderetta 7y agoSTL has nothing to do with OOP . In Alex Stepanov (the ST in STL) words "object orientedness is almost as much of a hoax as Artificial Intelligence"
- oldmanhorton 7y agoBecause c++ without OOP still gives you RAII (which is neutered a bit if you don't write your own classes but still), safe pointers, references, lambda, and an immense standard library, to name a few.
- klipt 7y agoIf by safe pointers you mean unique_ptr etc, I'm pretty sure those are classes: https://en.cppreference.com/w/cpp/memory/unique_ptr https://en.cppreference.com/w/cpp/memory/unique_ptr So by definition require OOP?