C++ Coding Guidelines: Difference between revisions

From LuxCoreRender Wiki
Jump to navigation Jump to search
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:


= Modern C++ =
= Modern C++ =
In general, we thank you for applying the best practices of modern C++ programming, as defined by experts:
We ask you to enforce the best practices of "modern" C++ programming, as defined by best experts:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
True it is that legacy code may not always comply to those recommendations, but this is no reason for new code not to enforce them.


= Indentation =
= Indentation =
Line 9: Line 12:


On a different note, please avoid trailing spaces.
On a different note, please avoid trailing spaces.
= Object naming =
LuxCore uses camelCase/CamelCase style.
Local symbols are named with camelCase
Global symbols are named with CamelCase.


= Boost =
= Boost =
Line 15: Line 24:
Since v2.10, however, this is no longer the case, as LuxCore has been ported to C++20, which offers a standard library that can largely replace Boost, with a few exceptions.
Since v2.10, however, this is no longer the case, as LuxCore has been ported to C++20, which offers a standard library that can largely replace Boost, with a few exceptions.


Please systematically prefer C++20 standard library over Boost whenever possible and limit Boost to cases where there is no other solution.
Therefore <i>please systematically prefer C++20 standard library over Boost whenever possible</i> and limit Boost to cases where there is no other solution.


= Raw pointers =
= Raw pointers =
LuxCore development was started before the advent of modern C++ (C++11 and higher) and logically conceals numerous raw pointers. However, raw pointers are quite risky, particularly in terms of memory leaks, dangling pointers, pointer aliasing etc., and should be avoided now, to the benefit of smart pointers.
LuxCore development was started before the advent of modern C++ (C++11 and higher) and logically conceals numerous raw pointers. However, raw pointers are quite risky, particularly in terms of memory leaks, dangling pointers, pointer aliasing etc., and should be avoided now, to the benefit of smart pointers.


= Dependencies =
Since version 2.10, a new dependency manager has been added (<code> LuxCoreDeps</code>). Other means to add dependencies are deprecated. In particular:
- do not embed external dependency source code
- do not use git submodules
- do not rely on precompiled binaries
Etc.
<code> LuxCoreDeps</code> builds dependencies for sources, for all platforms, based on Conan database of build recipes.It guarantees reliability, portability and sustainability.
If you need to add a new dependency, please contact admin/dev team (on Discord, for instance, but also on Git or Forum).


= Code Documentation =
= Code Documentation =
Please document your code: insert necessary information, comments etc., in order for your peers to understand what you intend to do. Your peers encompass reviewers, other developers now and in the future etc.
Please document your code: insert necessary information, comments etc., in the code in order for your peers to understand what you intend to do. "Your peers" encompass reviewers, other developers now and in the future etc.


LuxCore relies on Doxygen to generate code documentation: use Doxygen syntax to add the necessary information in your code.
LuxCore relies on Doxygen to generate code documentation: use Doxygen syntax to add the necessary information in your code.
Doxygen documentation can be built with <code> make doc </code>. After building, you'll find the documentation in <code> out/doc </code>.
Doxygen documentation can be built with <code> make doc </code>. After building, you'll find the documentation in <code> out/doc </code>.

Latest revision as of 13:54, 30 May 2025

Here are some guidelines for C++ Coding.

Modern C++

We ask you to enforce the best practices of "modern" C++ programming, as defined by best experts: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines


True it is that legacy code may not always comply to those recommendations, but this is no reason for new code not to enforce them.

Indentation

Indentation in LuxCore has historically used tabs rather than spaces, so we will continue to observe this in the future, even if it may not be the most practical... Massive replacement of tabs by spaces may obfuscate history, so not recommended. Thank you for your compliance.

On a different note, please avoid trailing spaces.

Object naming

LuxCore uses camelCase/CamelCase style.

Local symbols are named with camelCase Global symbols are named with CamelCase.

Boost

Boost was used extensively in LuxCore, at a time when it was probably the only option for efficiently coding certain mechanisms (filepath, thread synchronization etc.).

Since v2.10, however, this is no longer the case, as LuxCore has been ported to C++20, which offers a standard library that can largely replace Boost, with a few exceptions.

Therefore please systematically prefer C++20 standard library over Boost whenever possible and limit Boost to cases where there is no other solution.

Raw pointers

LuxCore development was started before the advent of modern C++ (C++11 and higher) and logically conceals numerous raw pointers. However, raw pointers are quite risky, particularly in terms of memory leaks, dangling pointers, pointer aliasing etc., and should be avoided now, to the benefit of smart pointers.

Dependencies

Since version 2.10, a new dependency manager has been added ( LuxCoreDeps). Other means to add dependencies are deprecated. In particular: - do not embed external dependency source code - do not use git submodules - do not rely on precompiled binaries Etc. LuxCoreDeps builds dependencies for sources, for all platforms, based on Conan database of build recipes.It guarantees reliability, portability and sustainability. If you need to add a new dependency, please contact admin/dev team (on Discord, for instance, but also on Git or Forum).

Code Documentation

Please document your code: insert necessary information, comments etc., in the code in order for your peers to understand what you intend to do. "Your peers" encompass reviewers, other developers now and in the future etc.

LuxCore relies on Doxygen to generate code documentation: use Doxygen syntax to add the necessary information in your code. Doxygen documentation can be built with make doc . After building, you'll find the documentation in out/doc .