3 ms·
I want to address some points for people that are reading and don't have enough C++ experience to judge that they are not as serious as they might seem. * You
by dxuh 4y ago
I want to address some points for people that are reading and don't have enough C++ experience to judge that they are not as serious as they might seem.
* You can just have your constructors not initialize your member variables. If they don't have default constructors that do work, then no work is done.
* Yes, originally. Move-semantics are part of the language since C++11. Enough time has passed.
* I read and write C++ every day at work and in my free time and I rarely find this to be a problem. If I see a non-trivial type, I assume it's destructor is called at the end of scope. And whether I have to look up the destructor of some type or a corresponding free function (like in C code usually), makes no difference to me.
* Gamedev can live entirely without exceptions and many other software projects do as well. You just have to write your constructors so that they do little work (which is encouraged anyways) and use methods to initialize them. Having static methods that return an optional<T> is also pretty common.
Of course you can also have constructors that do a ton of work, so you never know what is being done, exception handling everywhere to error handle all that code and not use move semantics or very old C++ versions. There are always ways to use a language in a bad way and get bad results. I am sure you have seen bad C code.
Of course RAII is not simple. It's extremely complicated, which is why I consider it missing. Using a new language needs be justifyable by some significant added value.
- jcelerier 4y agoI absolutely agree, I've written a few hundred thousand loc of C++ at this point and I don't remember one time where I felt that having RAII was anything but great. It made me absolutely hate whenever I had to work in other languages Java and C# and had to remember to release non-memory resources manually.
- baq 4y agoThat’s basically any gced language and the fix is present for decades at this point: try-with-resources, ‘using’, ‘with’ (with-whatever IIRC can be traced back to Lisp…)
- jcelerier 4y agono, those are absolutely not fixes: you have to remember to use "using", "with", etc. whereas you have to go out of your way to circumvent RAII
- baq 4y agoNon-issue. You can use fopen in C++ and remember to fclose, too.
- jcelerier 4y agoNo, every time you have something that sound like "you just have to [...]" it means future bugs that were entirely preventable. The only correct way in c++ is to wrap it in a unique_ptr or handle type so that fclose gets called automatically when you are done with the resource
- pjmlp 4y agoUse static analysers, just like you have to do on C and C++ to handle many of their flaws.
- deleted 4y ago[deleted]
- gingerBill 4y ago> You can just have your constructors not initialize your member variables. If they don't have default constructors that do work, then no work is done. So your constructors don't do any construction?---defeating the entire point of a constructor. > Yes, originally. Move-semantics are part of the language since C++11. Enough time has passed. First, move-semantics solve a lot of the issues with copy-constructors in C++, as I previously stated. Secondly, what has time got to do with this? It's a solution in C++'s RAII with copy-constructors. Not the only possible solution but the one that the C++ committee settled on. > I read and write C++ every day at work and in my free time and I rarely find this to be a problem. If I see a non-trivial type, I assume it's destructor is called at the end of scope. And whether I have to look up the destructor of some type or a corresponding free function (like in C code usually), makes no difference to me. I'm also assuming that your code base uses constructors and destructors all over the place and is absolutely fine with the added costs of constructors and destructors. And that's fine. But they are implicit and when reading the code, you don't necessarily know if a constructor is being called from just reading it. That is just a statement of fact and not really a criticism. > Gamedev can live entirely without exceptions and many other software projects do as well. You just have to write your constructors so that they do little work (which is encouraged anyways) and use methods to initialize them. Having static methods that return an optional<T> is also pretty common. Firstly, is the argument here to make constructors only do trivial things in?---(which rarely ever happens in practice, especially if you use anything from the STL). Secondly, many game devs usually have have an explicit `init` method too for the exact reason you can separate allocation and initialization, and have the ability to handle failure cases with `init`, usually with a return value indicating this failure state. You can have static methods, yes, but then you are literally getting around the construct of an implicit constructor and having an EXPLICIT construction call. RAII itself is actually very simple, but to make it useful is complicated and complex. The issue with RAII is not necessarily the scope-exit semantics but rather coupling this within the type system itself as a way to have scope-hierarchical-based management of resources.
- godratio 4y agoThe value is having an alternative closer to C and farther away from the garbage lang that C++ has become. No one is expecting you to rewrite your entire project in Odin but those that are starting new projects have a high value choice with Odin and others.