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!

You are viewing a single thread.
View all comments View context
13 points
*

Something like if (stupid_bool & 0x01) should work for those.

permalink
report
parent
reply
12 points

Yeah of course we convert, but it effectively means you need this little custom conversion layer between every application and its database. It’s a pain.

permalink
report
parent
reply

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?

permalink
report
parent
reply
6 points

The conventional ‘not’ would not behave differently for the two non-zero values. Insidious.

permalink
report
parent
reply

Correct! I made a number of other mistakes (edited away now due to shame), but that’s the one I made on purpose.

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.4K

    Monthly active users

  • 1.9K

    Posts

  • 30K

    Comments