From 9ffde94c8679d8aa91eb1d745b024c1782af3c5b Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Fri, 15 Nov 2024 22:46:00 +0100 Subject: [PATCH] Document that using integers in boolean contexts is not recommended --- CONTRIBUTING.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65f12f7f1..4eefb4604 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -149,6 +149,22 @@ if(Foo) { .. } Unless the alternative code is more complex and harder to read. +### Using integers in boolean contexts should be avoided + +❌ + +```C++ +int Foo = 0; +if(!Foo) { .. } +``` + +✅ + +```C++ +int Foo = 0; +if(Foo != 0) { .. } +``` + ### Methods with default arguments should be avoided Default arguments tend to break quickly, if you have multiple you have to specify each even if you only want to change the last one.