C++ usage guidelines
As of Redot 26.3, we are moving to C++20. Below are some guidelines for C++ usage in Redot.
Disallowed features
Any feature not listed below is allowed. Using features like constexpr
variables and nullptr is encouraged when possible. Still, try to keep your
use of modern C++ features conservative. Their use needs to serve a real
purpose, such as improving code readability or performance.
Standard Template Library
We don't allow using the STL as Redot provides its own data types (among other things). See Faq Why Not Stl for more information.
This means that pull requests should not use std::string,
std::vector and the like. Instead, use Redot's datatypes as described below:
- Use
Stringinstead ofstd::string. - Use
Vectorinstead ofstd::vector. In some cases,LocalVectorcan be used as an alternative (ask core developers first). - Use
Arrayinstead ofstd::array.
auto keyword
Please be conservative with the use of the auto keyword for type inference. While it can avoid
repetition, it can also lead to confusing code:
// Not so confusing...
auto button = memnew(Button);
// ...but what about this?
auto result = EditorNode::get_singleton()->get_complex_result();
Keep in mind hover documentation often isn't readily available for pull request reviewers. Most of the time, reviewers will use GitHub's online viewer to review pull requests.
While we are not forbidding its usage outright, it should only be used when the type is obvious and the code is not too complex.
Lambdas
Lambdas should be used conservatively when they make code effectively faster or simpler, and do not impede readability. Please ask before using lambdas in a pull request.
#pragma once directive
Please prefer #pragma once in new files over #ifdef-based include guards.