Skip to content

Commit 2efa5d6

Browse files
authored
Merge pull request #5826 from ab9rf/dev-doc-update-jun2026
Add some C++ code standards to `Contributing.rst`
2 parents 2f41d07 + ea0e45d commit 2efa5d6

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

docs/dev/Contributing.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ Code format
6161
* ``#include`` directives should be sorted: C++ libraries first, then DFHack modules, then ``df/`` headers,
6262
then local includes. Within each category they should be sorted alphabetically.
6363

64+
General C++ code guidelines
65+
---------------------------
66+
* This project is currently built at the C++20 feature level, and C++20 features should be used when appropriate. C++23 features will be allowed once all of our build platforms support them.
67+
* NEVER use ``using namespace`` in a header file. In source files, do not use ``using namespace std``; instead, import each STL identifier you need specifically (e.g. ``using std::string;``).
68+
* Avoid platform specific code as much as possible.
69+
* Avoid including ``Windows.h``; if you must, ensure that ``NOMINMAX`` and ``WIN32_LEAN_AND_MEAN`` are defined before including it.
70+
* Do not include C headers (e.g. ``<stdio.h>``); use the C++ versions (e.g. ``<cstdio>``) instead.
71+
* Do not use ``std::string`` (or ``char *``) for path names; always use ``std::filesystem::path``. This avoids issues with encoding, especially on the Windows platform, which is roughly 80% of our user base.
72+
* Do not use ``printf`` or similar functions for formatting strings; use C++ streams or ``fmt::format`` instead. We use the `fmt library <https://fmt.dev/latest/index.html>`__ for formatting strings; this dependency is automatically fetched by our build system.
73+
* Avoid out parameters; prefer returning a struct, pair, or tuple, or using ``std::optional`` instead.
74+
* Prefer range for loops to traditional for loops when iterating over a container.
75+
* Avoid macros when possible; prefer ``constexpr`` variables for constants and functions or templates for code generation.
76+
6477
.. _contributing-pr-guidelines:
6578

6679
Pull request guidelines

0 commit comments

Comments
 (0)