[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Avoid bool ?
|
From: |
Jose E. Marchesi |
|
Subject: |
Re: Avoid bool ? |
|
Date: |
Sat, 11 Apr 2020 13:44:45 +0200 |
|
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi Bruno!
> * 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.
As always I appreciate your views, but in this specific point we will
have to agree to disagree :)
- Avoid bool ?, Bruno Haible, 2020/04/11
- Re: Avoid bool ?,
Jose E. Marchesi <=