From 4a7c92aa40115caacd699736d72b969c8f011e9d Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Thu, 22 Jun 2023 14:15:07 +0000 Subject: [PATCH] Update 'Coding Style' --- Coding-Style.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Coding-Style.md b/Coding-Style.md index 4b1b715..73b3f04 100644 --- a/Coding-Style.md +++ b/Coding-Style.md @@ -282,6 +282,28 @@ Do eliminate trailing whitespace on any line, preferably as a separate patch or ### Conditions +Boolean values should not be checked for equality to make the code more readable: +```c +if (error) + return 1; + +if (!error) + return 0; +``` + +The check for 0 should refer to the specific way the 0 is used: `0` for a numeric value, `'\0'` for the end of a string, or `NULL` for a pointer. In this way, the variable type can be derived implicitly by reading the comparison. For the FALSE boolean we refer to the rule about boolean equations. +```c +if (buffer == NULL) + return NULL; + +if (get_bit (stream) == 0) + node->value++; + +if (bwc->info.file_ext [0] != '\0') + return 0; +``` + + ### Functions The following general rules should be followed when defining a function in BigWhoop: * Function name must be lowercase, optionally separated with underscore _ character