[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Avoid bool ?
|
From: |
Bruno Haible |
|
Subject: |
Avoid bool ? |
|
Date: |
Sat, 11 Apr 2020 12:41:44 +0200 |
|
User-agent: |
KMail/5.1.3 (Linux/4.4.0-174-generic; KDE/5.18.0; x86_64; ; ) |
Regarding this patch:
> * HACKING (Avoid bool): New subsection.
I would vote for encouraging, not avoiding, the use of 'bool'.
* Code is more readable if it uses 'bool'. The reader does not have to
wonder "is this variable or parameter a counter or a boolean?" (This
can be mitigated if you have a policy to name all variables of type
bool, all parameters of type bool, and all functions of type bool
with either a suffix '_p' or a prefix 'is_'. But do you really do so?
And how would you enforce such a policy?)
* There are portability problems [1], but they can easily be mitigated:
Use module 'stdbool' from gnulib.
Also, if you use 'bool' in the signature of functions exported by libraries,
guaranteeing binary compatibility between different compilers on old platforms
like Solaris 9 requires installing a public header file named 'pk-stdbool.h'
or similar. GNU Libunistring does this for 10 years; I think nowadays you
can, in a first approximation, get away without it and just rely on the
gnulib's and the platform's <stdbool.h>.
* You want to have more contributors? Then use a present-day coding style.
Similarly, GNU libc used to use K&R function declaration style for long
after 2000. This hampered development, because it puts off contributors.
Not using 'bool' is similar.
Just my 2 cents.
Bruno
[1] https://www.gnu.org/software/gnulib/manual/html_node/stdbool_002eh.html
- Avoid bool ?,
Bruno Haible <=