Still, I see two drawbacks: 1) one could violate the design and pass nullptr (but I guess this will trigger something) 2) one could delete or release the pointer. So somehow you should want to pass a "view" (database terminology) to your Passes. But wrapping all D3D11 functionality seems so cumbersome.
Let me describe my view point:
In MY engine, only I can violate the design and pass nullptr/release COM object.
There are 3 layers of making checks:
1. Compile time checks.
2. Run time invariant
3. Defensive programming.
Compile time checks: the best way to go: no user overhead, checks on build, (simplified version of unit testing for your API/design).
There are tools:
a. /W4 for projects + “treat warning as error”
b. Static code analysis (Carmack talked about it (from ~55 minute)
c. External lib: Sutter presented it on CppCon:
and
I have A and B. C is scheduled to be added this summer.
Runtime invariant: throw in constructor, if you can’t construct an object.
After this point you have fully constructed objects, that have their contracts.
From my side, I expect them work correctly. Benefit: no checks required in rendering time.
Defensive programming: you are not sure about correctness of your code/data, and you need place a lot of checks.
I decided that this is a bad thing: code bloat, performance degradation, more code = more bugs.
On top of that there is MODERN C++. This is a toolbox.
You can peek subsets of:
1. Good practices to follow, and place them to your code/design standard/pattern standard (like owner/user resource ownership)
2. Bad practices not to follow.
There is no good mapping (yet?) between your MS Word design document and code.
So, this guarantee you should give.
(Especially) If you expect that some other coder will touch your code, you’d better to stay away from bad practices like: always pass by value with expectation, that someone will push there r-value reference. Const reference was invented for this job. And this is standard, well-known practice.
Just use right (modern subset of C++) tools in right place. Use good practices, don’t use practices from tutorials where C/C# programmers wrote their samples in C++ (as they though it was C++ :D .
If it is too difficult, you can use other languages, where some of the practices are absent (and you have less potential errors) like C# or whatever.
But the power of C++ is resource management.
You can shoot yourself in a foot, but I don’t want to do it for myself =)
The other thing to remember: what skills will have “potential” co-writer of your code.
If he will be junior, or C# programmer, you will have to train him to your design decisions/ guidelines, or lower your design expectations. IMHO it is difficult to mix it.
Happy coding! :wink: