valkey icon indicating copy to clipboard operation
valkey copied to clipboard

[NEW] use native `bool` type in Valkey

Open PingXie opened this issue 9 months ago • 7 comments

This feels almost like a separate major decision since it's so deeply rooted in this code base. We have atomics and other C99 and later features, but not bool and C++ comments. :smile:

I'd like to hear arguments against adding it though. It's part of C nowdays and it's odd to have a rule that forbids it.

Originally posted by @zuiderkwast in https://github.com/valkey-io/valkey/pull/245#discussion_r1586898155

PingXie avatar May 01 '24 22:05 PingXie

What's a c++ comment?

madolson avatar May 01 '24 23:05 madolson

The only thing I don't like about bool is that:

int isTrue() { return 1 }

is not the same as

bool isTrue() { return true}

Since a bool is only 1 byte. We have actually had production outages because of that mistake at AWS, because we internally use bool in various places, and people didn't understand the difference.

More generally, I prefer the code to more or less all use the same conventions. It's much more important to me to be consistent, since the more we diverge the more folks will poke in and say they want to do something else because that is the way that they like it.

madolson avatar May 01 '24 23:05 madolson

What's a c++ comment?

// "C++ style" line comments are valid in C99

zuiderkwast avatar May 02 '24 00:05 zuiderkwast

Let's keep these conventions then. Are they actually written down anywhere?

zuiderkwast avatar May 02 '24 00:05 zuiderkwast

What's a c++ comment?

I've never heard these be called C++ comments, always single line comments. That just might be because I never write C++ code though :D

madolson avatar May 02 '24 00:05 madolson

They're coming from c++ originally i believe.

https://en.cppreference.com/w/c/comment

zuiderkwast avatar May 02 '24 00:05 zuiderkwast

I remember in very old C, there is no bool type, it is not like C++, which has built-in data type boolean. After C99, C import bool type, but in low level, i think it need to be converted into integer zero or non-zero value. Thus, i think in valkey, we do not need to import #include <stdbool.h>.

Personally, I have C++ experience. I still remember when I read redis code initially, because Redis is written by pure C language, I am confused by some C syntax.

hwware avatar May 02 '24 19:05 hwware