You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/dev/Contributing.rst
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,19 @@ Code format
61
61
* ``#include`` directives should be sorted: C++ libraries first, then DFHack modules, then ``df/`` headers,
62
62
then local includes. Within each category they should be sorted alphabetically.
63
63
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.
0 commit comments