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!

-1 points
*

Probably readability. Correct typing maybe too. Also better error checking.

permalink
report
reply
1 point

I’m not sure I understand readability? I guess is disambiguates numeric variables if you used 1 and 0. But with true and false available that would seemingly do the same thing. You still have to know what the arguments your passing are for regardless.

permalink
report
parent
reply
2 points

Does C have a logical type these days? Never use to.

permalink
report
parent
reply
2 points

I guess in reading not until c99(see other comment); they just used integers in place of Booleans, in which case your readability statement makes more sense given the historical context

permalink
report
parent
reply
4 points
*

It’s for the extra helpful documentation. You see, in this fantastic example, after the author set GLFW_TRUE to 1, he explained the deep and profound meaning of the value. This exemplifies that the number 1 can also be written as a word: “One”! Some people might be able to figure this out, but the author clearly went above and beyond to make the code accessible to the open source community, encouraging contributions from anyone who’s considering improving the code. Furthermore, this follows the long held tradition of man pages - explaining the nuance of the code, in preparation for telling others to RTFM when they arrogantly ask a question.

permalink
report
reply
-2 points

Because JavaScript exists

permalink
report
reply
5 points

i just like namespacing my variables anyway so there’s no chance of any conflicts and so you can easily change something one place instead of everywhere

permalink
report
reply
40 points

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”

permalink
report
reply
4 points

That should probably be red alert wakeup call for you right?

permalink
report
parent
reply
2 points

Why?

permalink
report
parent
reply
9 points

I can give you a shit take if you want one, but I don’t have shiitake mushrooms.

permalink
report
parent
reply
2 points

I like my shit takes wrapped in beef rolls, in case you come across some more :)

permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 2.5K

    Monthly active users

  • 1.9K

    Posts

  • 30K

    Comments