I’m working through the vulkan tutorial and came across GLFW_TRUE and GLFW_FALSE. I presume there’s a good reason but in looking at the docs it’s just defining 1 and 0, so I’m sorta at a loss as to why some libraries do this (especially in cpp?).
Tangentially related is having things like vk_result which is a struct that stores an enum full of integer codes.
Wouldn’t it be easier to replace these variables with raw int codes or in the case of GLFW just 1 and 0?
Coming mostly from C, and having my caps lock bound to escape for vim, the amount of all caps variables is arduous for my admittedly short fingers.
Anyway hopefully one of you knows why libraries do this thanks!
This is often done for backward compatibility, as stdbool.h which provides true and false wasn’t standard before C99 and even though that’s more than 25 years ago now a lot of old habits die hard.
My brain is so used to seeing political content that I read “why do liberals define their own true and false” and was already like “what kind of shit take am I going to have fun reading today”
GLFW is a C library, not a C++ one, and an old one at that, and so the reason is that a long time ago, there was no bool in C. Every library would make their own true and false bc it’s handy to have.
Nowadays, the type
_Bool
has been added to C, and C++ has built-inbool
, but you can still see the legacy of no boolean in C as to use the type name “bool” as well as the key words “true” and “false” for 1 and 0, you have to include “stdbool.h,” as well as in custom types in these old GL-adjacent libraries.My boss insisted, before I arrived at the company, that everything in the database be coded so that 1 = Yes and 2 = No, because that’s the way he likes to think of it. It causes us daily pain.
Something like
if (stupid_bool & 0x01)
should work for those.I imagine this would still lead to a never ending stream of subtle logic errors.
from bossland import billysbool, billysand from geography import latlong import telephony def send_missile_alert(missiles_incoming: billysbool, is_drill: billysbool, target: latlong): if billysand(missiles_incoming, not is_drill): for phone in telephony.get_all_residents(target): phone.send_alert("Missiles are inbound to your location")
Can you spot the bug?
The conventional ‘not’ would not behave differently for the two non-zero values. Insidious.
Correct! I made a number of other mistakes (edited away now due to shame), but that’s the one I made on purpose.
deleted by creator
Now I have heard everything. What is zero? Missing value?
Zero is something you always have to watch out for and handle, because he likes to use NULL for “don’t know”. I should really have deleted the database while it was still young, before they had backups.