From 47b6253049b54186663b4205d3441f88656dc22e Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 2 Feb 2026 16:12:09 +0100 Subject: flesh out extra details in the MD files --- doc/CONTRIBUTING.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'doc') diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md index 265b686..13be092 100644 --- a/doc/CONTRIBUTING.md +++ b/doc/CONTRIBUTING.md @@ -94,6 +94,8 @@ if variable_name is not mutated afterward. Also: pass parameter as "const ref" as much as possible (```const Struct& param``` instead of pointers or non-const refs) +In summary: use 'const variable = ...;` as much as possible. + ### put spaces around code and operators (cosmetics) Don't compact the code to much horizontally, and prefer adding extra @@ -169,6 +171,33 @@ private: int field_; ``` +### try to use per-field initialized const struct + +Use the `.field = ...,` initialization pattern instead for `var.field = +...;`, especially if it means you can have the variable be declared 'const' +that way. + +Example, instead of: +```cpp +WGPUTextureViewDescriptor view_desc = {}; +view_desc.format = g_format; +view_desc.dimension = WGPUTextureViewDimension_2D; +view_desc.mipLevelCount = 1; +view_desc.arrayLayerCount = 1; +``` + +use: +```cpp +const WGPUTextureViewDescriptor view_desc = { + .format = g_format, + .dimension = WGPUTextureViewDimension_2D, + .mipLevelCount = 1, + .arrayLayerCount = 1, +}; +``` + +Make sure the `.field = ...,` initialization pattern is compatible with the compiler / c++ version used. + ### vertical space keep the code compact vertically. That includes shader code, too. -- cgit v1.2.3