This is extra cursed. The guy in the video is replacing bad practices with other bad practices, with a sprinkle of working around the C++ default behavior
Cakez is quickly becoming my favourite programming youtuber, I feel like I can actually relate to him. Loved his video trying out Zig! The frustrations are real and raw. Love watching you videos!
@@balijosu I'm not a beginner by any means, I just enjoy him airing his frustrations cause that is me some times, and in a lot of these programming tutorials you don't see the ''struggle" behind the project.
You should watch Ryan Fleury's video on memory management. He goes into why allocing arrays in a virtual memory backed arena allocator is actually potentially better than a single allocation. It's a really good talk.
and again you can use std algorithms on your own container types if you do a tiny bit of research and figure out how to implement the neccessary interfaces.
this is literally what i was thinking, he already has a .first() and .final() functions on his array class which basically do the same thing as .begin() and .end(). because the array is a contiguous buffer, if he changes the names of the functions/ adds .begin() and .end() methods, and has the return types be T*'s then he'll be able to use them with range based for loops (and algorithms but he doesn't like using the standard for some reason ¯\_(ツ)_/¯)
Traditional loops just store the integer iterator and comparison in the processor registers. You don't need range based iterator Objects on the stack, they just waste memory, and they don't make code easier to read.
He is ignorant. If you watch his streams you will see that he never reads any docs and just cowboy codes his way through. He is just not aware of begin() and end(). He watched Handmade Hero and never went out of his way to learn anything else
"it's best that you do make mistakes and learn" is great when it doesn't compromise millions of users private information and more, which is the reality of C and C++ memory management mistakes.
In game development, nobody cares that some hacker got an access to some random trace of game's memory. On the other hand, database leaks happen all the time no matter the language those databases written in, there's no language that's 100% safe
@@Glomly It's not about 100% safety, that reducing all the long hanging fruits, which account for like 90% of the issues. Also, things like memory leaks or crashes can ruin a game as well.
@@Giga4ever memory management is hard for those who come from garbage collected languages, so they don't understand fundamental design difference. In "manual" languages you need to keep everything as simple as possible, be conservative, keep related things together, allocate them together and release them together. In "automatic" languages you can have as much complexity as you want and create heap allocations left and right, transition to absolutely different layout midway through, knowing that the "garbage" is going to be collected after you done using it. One leads to extremely fast development iteration but bad performance, the other to slow iteration fast performance. The problems start when you try to simultaneously make your program' memory layout complex(as allocate lots of different small things in different places throughout your program) and manage the memory, ofc you get a disaster.
@joshnjoshgaming It's certainly the reality of C (only in relevant applications of course--many applications have no security concerns by their nature). But C++ gives you a lot of tools to avoid typical C problems.
46:34 "I do have compiler warnings from fontconfig and I can't anything about those". Yes, you can. You should include external libraries as "system libraries". For example, in gcc use the "isystem" flag instead of the "I" flag for include directories. I think MSVC has a pragma for this. What it does: The compiler won't output warnings coming from system headers aka libraries that you have no control over.
I feel like people that use the full C++ std:: feature set have an entirely different mindset on what programming is like, where more complexity somehow means the code is better.
he did say OVER use of magic numbers. Not use of magic numbers. In some instances its fine. IMHO as soon as you use the same magic number twice is where it gets tricky.
I don't understand how manual memory management can be bad. Tbh, it can be hard keeping track of when destructors are called for certain classes and manual control just lets you understand exactly what's happening at any given moment.
Unless you forget to do your cleanup in one place or forget to account for all exit paths. And this might be due to mental fatigue not due to skill issue. Destructors are called at the variable's scope end and in reverse order created. I don't understand what's hard about it. You don't need to think about it really.
@@sledgex9 I agree with you, I was moreso arguing against how they guy in the video made it seem like manual memory management was a bad thing and to strictly use destructors. I think you could probably use destructors most of the time, but I also feel like there's a time and a place for really precise control. Plus it helps you understand exactly when something like a memory deallocation happens because it's written out as a statement, rather than automatically called in the background if that makes sense.
@@unknown_error101 RAII should be the default for a programmer. If performance issues arise, you can fallback to manual resource management. If you want to see where memory deallocation happens for educational purposes that's fine. But usually the docs for each class should clarify enough what it does behind the scenes with resources.
@@balijosu think of it like a fisherman so good they jump into his bait bucket, only it's a scientist and he tags and releases to better the future species ;)
13:08 Also string literals are placed into a read-only section so if you try to write to the underlying bytes you get a access violation. 15:41 I compile the code with gcc -O3 and it compiles it to a constant value. So I don't understand why you would do this. 40:32 I'm pissed off! I use C not C++ why did I watch this?
"I don't know/use it so it doesn't count" is such a silly argument when you consider that my grandma would have 0 "NoobCounter" with the same argument. Knowing fundamental language features and the standard library are all are all part of knowing a language. It's valid to not use them, but disregarding everything because of ignorance and not for actual reasons, is unfortunately common with the "C subset of C++" people. Also, you missed the point of like half of the things in your typical 2Head behaviour
Ok, so you don't fall into these traps for the same reason I don't fall into any traps when I use Visual Basic. (Because I've never used Visual Basic.)
yeah but fopen is broken on Windows, it doesn't work with filenames with unicode character lol so you have to use the wide char version. This applies to all io functions (rename, unlink, mkdir, etc)
The guy that made the original video is actually the noob if he thinks that any manual memory management is noob behavior. If, like Cakez said, you manage memory in a way were you allocate only one or a few times for memory arenas that keep the memory valid for different lifetimes in the program from which you suballocate, that's actually the pro move. It's fast, it's simple, it's easy to understand, memory leaks can only happen in those few places. There is not a single valid argument you can make against this in my opinion.
boomer loops are better, I always use a loop index, linear search is almost always better than maps, you don't need objects, you don't need templates, you don't need garbage collectors or dynamic memory, you don't need to individually malloc and free every little thing, block allocate a fixed size of data, and free it all at once, pointers are ugly, and pointers can be replaced with indexes into arrays. C++ is mostly a bad language, and C++ noob code is probably more performant, easier to read, and faster to compile, than C++ pro code.
So no one ever has a use for templates and meta programming, and arrays and arena allocators can solve every scenario? Sounds like a closed minded take from a hobbyist who writes one kind of software. also I love claims of performance backed with nothing but opinion. of course parts of everything you said have some grain of truth to them in certain scenarios, but to think that applies to everything is just silly
@@joshnjoshgaming TH-cam is deleting all my replies. Probably t r i g g e r e d them with the B word. Everything is hate speech to the kommies running this site.
37:28 was so painful to watch. You clearly have no clue what resource management means, yet you have the audacity to shout "wrong" like a child. It is not just about memory allocation, he even literally showed you another example of resources with the file opening. Not knowing why RAII is important, even outside memory allocations, makes you a beginner in C++ period. Imagine you load a file and do something with it, and something went wrong(e.g. you load a shader and it has a compile error), in this case it is easy to forget to actually close the file in ALL early returns. Now you lose the handle and you have the file permanently opened, which can cause all kinds of issues(.e.g unable to fix the shader for example when hotrelaoding). Also, your whole memory argument is even kinda dumb, because you can jut use custom allocators and track stuff there instead of always over-allocating everything and being unable to release memory.
@@rohitaug I agree with you but I'm just going to assume by the way he wrote his message, that anything Casey will say in that video will fall on deaf ears.
@@rohitaug I am aware with Caseys video, but if you actually listen to his arguments, you will find that there are not any. He is just dogmatic and ignorant, where he makes claims without backing them up. Probably not the best idea to listen to the guy who has no gameplay in his game after 10 years, despite even taking money for it by making false promises.. But you are missing the point: I am talking how Cakez missed the entire point of RAII. Whether he agrees to RAII or not is his own decision, but he should disregard it for the correct reasons and not just reduce it to the "resources are just about memory". Also Cakez is using the early memory allocation, not the chunk based arena one, which even Casey said was just to make the beginning easy(so he replace it in like episode 300 or something), but Cakez unironically uses the "noob allocation strategy" in his actual production project.
Your arguments against Casey don't take into account that Casey does handmade hero in his spare time. Also he is teaching how to make engine code, not gameplay. Whether an allocation strategy is good or bad depends on how difficult it is to work with. If Cakez is not having the issues you're saying he is supposed to have, how is it a problem? I won't say that Cakez is an expert but declaring RAII as "the expert way" as the video suggests misses the mark, which is what Cakez says is wrong. Not that RAII itself is wrong for every project.
@@rohitaug He didn't do a new HMH video in a long time. He abandoned it for his next money making scheme where he "teaches" others, despite not delivering on the original promises. Cakez misunderstood the RAII part(as many other points in the video) and only reduced it to memory allocation, despite the example clearing being about file handles, so he was wrong, and that is I was originally pointing out. Let's not talk about all the issues that Cakez has with his code, there is a reason why his little Tower Defense game has not a single tower done, let alone a full level, after 3 years of fulltime work. He is constantly re-doing things.
I did not find mention about that on cpp reference unordered_map page, but if it is true I have no words to describe this language anymore without youtube shadow banning me.
@joshnjoshgaming Never used C#. Seems nice though. I should add: I generally don't like operator overloading. I prefer functions with descriptive names unless the point is to make something usable in contexts where you also want to use primitive types.
This is extra cursed. The guy in the video is replacing bad practices with other bad practices, with a sprinkle of working around the C++ default behavior
to sum up this video:
I don't use any C++ feature in C++
the std::move parts had me dying 💀
just use C at that point, if you're not even using RAII and value semantics 💀
@@Raspredval1337 yes please just use C, great idea
Cakez is quickly becoming my favourite programming youtuber, I feel like I can actually relate to him. Loved his video trying out Zig! The frustrations are real and raw.
Love watching you videos!
@frroossst4267 Take care if you're trying to learn anything though.
@@balijosu I'm not a beginner by any means, I just enjoy him airing his frustrations cause that is me some times, and in a lot of these programming tutorials you don't see the ''struggle" behind the project.
You should watch Ryan Fleury's video on memory management. He goes into why allocing arrays in a virtual memory backed arena allocator is actually potentially better than a single allocation. It's a really good talk.
@@VACatholic tagging this for later
Essentially you write C not C++
Yeah, he's writing C and compiling it in a C++ compiler and being all proud and street smart about not using the STL or whatever
@@PixelThorn why not? C+ (only one plus) is my favorite style too
@@PixelThorn c++ at it's peak is dealing with much more abstraction without any benefits
@@PixelThorn isn't the C compiler faster ? why not just write C code at this point lol
@@Brad_Script don't know, thats what he should be doing 😁
why not define your own begin() and end() functions in your array? they're so easy to define.
and again you can use std algorithms on your own container types if you do a tiny bit of research and figure out how to implement the neccessary interfaces.
this is literally what i was thinking, he already has a .first() and .final() functions on his array class which basically do the same thing as .begin() and .end(). because the array is a contiguous buffer, if he changes the names of the functions/ adds .begin() and .end() methods, and has the return types be T*'s then he'll be able to use them with range based for loops (and algorithms but he doesn't like using the standard for some reason ¯\_(ツ)_/¯)
Traditional loops just store the integer iterator and comparison in the processor registers. You don't need range based iterator Objects on the stack, they just waste memory, and they don't make code easier to read.
He is ignorant. If you watch his streams you will see that he never reads any docs and just cowboy codes his way through. He is just not aware of begin() and end(). He watched Handmade Hero and never went out of his way to learn anything else
Should do that you are right
"it's best that you do make mistakes and learn" is great when it doesn't compromise millions of users private information and more, which is the reality of C and C++ memory management mistakes.
In game development, nobody cares that some hacker got an access to some random trace of game's memory. On the other hand, database leaks happen all the time no matter the language those databases written in, there's no language that's 100% safe
@@Glomly It's not about 100% safety, that reducing all the long hanging fruits, which account for like 90% of the issues.
Also, things like memory leaks or crashes can ruin a game as well.
@@Giga4ever memory management is hard for those who come from garbage collected languages, so they don't understand fundamental design difference. In "manual" languages you need to keep everything as simple as possible, be conservative, keep related things together, allocate them together and release them together. In "automatic" languages you can have as much complexity as you want and create heap allocations left and right, transition to absolutely different layout midway through, knowing that the "garbage" is going to be collected after you done using it. One leads to extremely fast development iteration but bad performance, the other to slow iteration fast performance. The problems start when you try to simultaneously make your program' memory layout complex(as allocate lots of different small things in different places throughout your program) and manage the memory, ofc you get a disaster.
@@Glomly Security statistics disagree with your statements, manual memory management is a problem.
@joshnjoshgaming It's certainly the reality of C (only in relevant applications of course--many applications have no security concerns by their nature). But C++ gives you a lot of tools to avoid typical C problems.
46:34 "I do have compiler warnings from fontconfig and I can't anything about those". Yes, you can. You should include external libraries as "system libraries". For example, in gcc use the "isystem" flag instead of the "I" flag for include directories. I think MSVC has a pragma for this. What it does: The compiler won't output warnings coming from system headers aka libraries that you have no control over.
I feel like people that use the full C++ std:: feature set have an entirely different mindset on what programming is like, where more complexity somehow means the code is better.
I use parts of it, but there's many parts of std I just find overcomplicated for its purpose where I just made my own things instead.
@XeZrunner I've literally never met an industry dev who thinks that way. Use the STL if it helps you. Use something else if it helps you.
he did say OVER use of magic numbers. Not use of magic numbers. In some instances its fine. IMHO as soon as you use the same magic number twice is where it gets tricky.
I don't understand how manual memory management can be bad. Tbh, it can be hard keeping track of when destructors are called for certain classes and manual control just lets you understand exactly what's happening at any given moment.
Unless you forget to do your cleanup in one place or forget to account for all exit paths. And this might be due to mental fatigue not due to skill issue. Destructors are called at the variable's scope end and in reverse order created. I don't understand what's hard about it. You don't need to think about it really.
@@sledgex9 I agree with you, I was moreso arguing against how they guy in the video made it seem like manual memory management was a bad thing and to strictly use destructors. I think you could probably use destructors most of the time, but I also feel like there's a time and a place for really precise control. Plus it helps you understand exactly when something like a memory deallocation happens because it's written out as a statement, rather than automatically called in the background if that makes sense.
@@unknown_error101 RAII should be the default for a programmer. If performance issues arise, you can fallback to manual resource management. If you want to see where memory deallocation happens for educational purposes that's fine. But usually the docs for each class should clarify enough what it does behind the scenes with resources.
@@unknown_error101 if you're manually allocating memory in C++ then you are basically just writing C. just use smart pointers
"Compiler Warnings" Eh she will be fine
Unfortunately even if you don't "using namespace std", many C++ headers pollute the global namespace.
C++ noob habit is using C++.
@@arsenbabaev1022 🙄
Is that your take or your opinion?
@@adamrushford Think of it like a child watching a professional and thinking "I could do better than that". They're oblivious to their shortcomings.
@@balijosu think of it like a fisherman so good they jump into his bait bucket, only it's a scientist and he tags and releases to better the future species ;)
@@adamrushford Ok, now I'm unclear whether you agree with arse or not.
13:08 Also string literals are placed into a read-only section so if you try to write to the underlying bytes you get a access violation.
15:41 I compile the code with gcc -O3 and it compiles it to a constant value. So I don't understand why you would do this.
40:32 I'm pissed off! I use C not C++ why did I watch this?
"I don't know/use it so it doesn't count" is such a silly argument when you consider that my grandma would have 0 "NoobCounter" with the same argument. Knowing fundamental language features and the standard library are all are all part of knowing a language. It's valid to not use them, but disregarding everything because of ignorance and not for actual reasons, is unfortunately common with the "C subset of C++" people. Also, you missed the point of like half of the things in your typical 2Head behaviour
Toxic
@@Cakez77 Truth = toxic? Weird dude
So he should count it towards the noob counter? Or what? Lol
you’re malding and it’s showing
Ok, so you don't fall into these traps for the same reason I don't fall into any traps when I use Visual Basic. (Because I've never used Visual Basic.)
Nice rage bait
I'm not mad, I'm just disappointed.
39:55 ifstream is WAY slower than FILE* with fread
yeah but fopen is broken on Windows, it doesn't work with filenames with unicode character lol so you have to use the wide char version. This applies to all io functions (rename, unlink, mkdir, etc)
The guy that made the original video is actually the noob if he thinks that any manual memory management is noob behavior. If, like Cakez said, you manage memory in a way were you allocate only one or a few times for memory arenas that keep the memory valid for different lifetimes in the program from which you suballocate, that's actually the pro move. It's fast, it's simple, it's easy to understand, memory leaks can only happen in those few places. There is not a single valid argument you can make against this in my opinion.
a terrifying amount of chat thinks exactly the same in that regard as the guy in the video apparently
44:51 can't this be fixed with "std::atomic x{};" or "auto r = std::make_shared();"?
Wait a second your other video title was "Why I Write C++ Like it is C."... no dude you're just compiling C code as C++ Apparently lol
I wouldn't paint the entire STL with the same brush. Some of it is ugly as sin though.
boomer loops are better, I always use a loop index, linear search is almost always better than maps, you don't need objects, you don't need templates, you don't need garbage collectors or dynamic memory, you don't need to individually malloc and free every little thing, block allocate a fixed size of data, and free it all at once, pointers are ugly, and pointers can be replaced with indexes into arrays. C++ is mostly a bad language, and C++ noob code is probably more performant, easier to read, and faster to compile, than C++ pro code.
So no one ever has a use for templates and meta programming, and arrays and arena allocators can solve every scenario?
Sounds like a closed minded take from a hobbyist who writes one kind of software.
also I love claims of performance backed with nothing but opinion.
of course parts of everything you said have some grain of truth to them in certain scenarios, but to think that applies to everything is just silly
good luck wasting runtime time and memory with c\stl regex instead of CTRE 😎
@@Raspredval1337 noobies write their own pattern matching instead of using regex
@@Glomly imagine being productive with c++, must be so hard for you
@@joshnjoshgaming TH-cam is deleting all my replies. Probably t r i g g e r e d them with the B word. Everything is hate speech to the kommies running this site.
Sorry, but what was the argument about string literals? I don't understand the point of the argument.
37:28 was so painful to watch. You clearly have no clue what resource management means, yet you have the audacity to shout "wrong" like a child. It is not just about memory allocation, he even literally showed you another example of resources with the file opening. Not knowing why RAII is important, even outside memory allocations, makes you a beginner in C++ period. Imagine you load a file and do something with it, and something went wrong(e.g. you load a shader and it has a compile error), in this case it is easy to forget to actually close the file in ALL early returns. Now you lose the handle and you have the file permanently opened, which can cause all kinds of issues(.e.g unable to fix the shader for example when hotrelaoding).
Also, your whole memory argument is even kinda dumb, because you can jut use custom allocators and track stuff there instead of always over-allocating everything and being unable to release memory.
Watch this video from a non-noob: "Casey Muratori | Smart-Pointers, RAII, ZII? Becoming an N+2 programmer"
@@rohitaug I agree with you but I'm just going to assume by the way he wrote his message, that anything Casey will say in that video will fall on deaf ears.
@@rohitaug I am aware with Caseys video, but if you actually listen to his arguments, you will find that there are not any. He is just dogmatic and ignorant, where he makes claims without backing them up. Probably not the best idea to listen to the guy who has no gameplay in his game after 10 years, despite even taking money for it by making false promises.. But you are missing the point: I am talking how Cakez missed the entire point of RAII. Whether he agrees to RAII or not is his own decision, but he should disregard it for the correct reasons and not just reduce it to the "resources are just about memory". Also Cakez is using the early memory allocation, not the chunk based arena one, which even Casey said was just to make the beginning easy(so he replace it in like episode 300 or something), but Cakez unironically uses the "noob allocation strategy" in his actual production project.
Your arguments against Casey don't take into account that Casey does handmade hero in his spare time. Also he is teaching how to make engine code, not gameplay. Whether an allocation strategy is good or bad depends on how difficult it is to work with. If Cakez is not having the issues you're saying he is supposed to have, how is it a problem? I won't say that Cakez is an expert but declaring RAII as "the expert way" as the video suggests misses the mark, which is what Cakez says is wrong. Not that RAII itself is wrong for every project.
@@rohitaug He didn't do a new HMH video in a long time. He abandoned it for his next money making scheme where he "teaches" others, despite not delivering on the original promises. Cakez misunderstood the RAII part(as many other points in the video) and only reduced it to memory allocation, despite the example clearing being about file handles, so he was wrong, and that is I was originally pointing out. Let's not talk about all the issues that Cakez has with his code, there is a reason why his little Tower Defense game has not a single tower done, let alone a full level, after 3 years of fulltime work. He is constantly re-doing things.
I used to think you actually coded c++.. then I saw this video
People saying the square bracket operator initializing on read isn't hidden behavior are coping so hard. As a non C++ dev, that shit's crazy
It returns a reference you can assign through. How else could it work?
It is the same in python though
I did not find mention about that on cpp reference unordered_map page, but if it is true I have no words to describe this language anymore without youtube shadow banning me.
@@balijosu iirc in C# that's an exception, items must be added to dictionaries manually ( could be wrong its been awhile)
@joshnjoshgaming Never used C#. Seems nice though.
I should add: I generally don't like operator overloading. I prefer functions with descriptive names unless the point is to make something usable in contexts where you also want to use primitive types.