summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/CONTRIBUTING.md29
1 files changed, 29 insertions, 0 deletions
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.