Sujet : Re: question about nullptr
De : andreytarasevich (at) *nospam* hotmail.com (Andrey Tarasevich)
Groupes : comp.lang.cDate : 09. Jul 2024, 06:45:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6if96$18hur$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
On 07/07/24 3:17 PM, Keith Thompson wrote:
I just about always use NULL, not 0, when I want a null pointer
constant. Similarly, I use '\0', not 0, when I want a null character,
0.0 when I want a floating-point zero, and false when I want a Boolean
zero. I just like being explicit.
Me too.
But at the same time I realize that this is a habit forced upon my by circumstances, by necessity. C (as well as C++) at its beginning (and when I started to use the language) was not very well-suited for type-agnostic/DRY programming. It had a few odd features/idioms acknowledging the possibility, but by large both languages were predominantly type-aware or type-explicit. I reckon, this is actually what made you to "like" such explicitness. But it is pointless to talk about "liking" something, when one really had no choice.
The moment C++ realized the full power of generic/template programming, it immediately rushed head-over-heels into type-agnostic programming style. It was `auto` and `decltype` initially, which then just opened the proverbial floodgates, triggering the avalanche of additional features targeted at the type-agnostic programming style. Many in C++ world still protest it, claiming that old-style type-explicit code is "easier to read", but they are nothing more than overgrown kids being reluctant to take the training wheels off their bikes (since they make it "easier to ride"). There no doubt anymore than type-agnostic programming is the next big thing for C++.
The same goes for C. C is not C++, of course, but with the introduction of `typeof` in C23 and, hopefully, better `_Generic` appearing one of these days, one can hope that being type-explicit is a thing of the past in C as well.
So, no. While I too prefer to use `NULL` for pointers and '\0' for character constants, I realize that do it out of deep-seated habit, or for nostalgic/luddite reasons mostly. Plain undecorated `0` as a universal type-agnostic constant should really be my choice everywhere today.
-- Best regards,Andrey