]> git.mdlowis.com Git - proto/labwc.git/commitdiff
CONTRIBUTING.md: document use of braces in switch statements
authortokyo4j <hrak1529@gmail.com>
Fri, 23 May 2025 05:11:57 +0000 (14:11 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 23 May 2025 20:32:17 +0000 (21:32 +0100)
CONTRIBUTING.md

index 5f7aa231e50ecfb95fa1b477254d6cbbd8e9a618..0180099d2ec5c3a170ef9a24d482d869adc561bf 100644 (file)
@@ -324,6 +324,32 @@ We use the prefix `handle_` for signal-handler-functions in order to be
 consistent with sway and rootston. For example
 `view->request_resize.notify = handle_request_resize`
 
+### Switch statements with variable declarations
+
+Unlike many modern languages, C doesn't create a new scope after `case FOO:`.
+Therefore, we wrap codes following `case FOO:` that include variable
+declarations with braces (`{..}`) to reduce variable scopes. For example:
+
+```
+switch (x) {
+case FOO: {
+       int y = 1;
+       break;
+}
+case BAR: {
+       do_something();
+       int z = 1;
+       break;
+}
+case BAZ:
+       do_something();
+       break;
+}
+```
+
+But please also consider refactoring the code into a separate function if it
+becomes lengthy.
+
 # Commit Messages
 
 The log messages that explain changes are just as important as the changes