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!

  • flatbield
    link
    fedilink
    English
    7
    edit-2
    2 months ago

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

    • @crimsonpoodle@pawb.socialOP
      link
      fedilink
      32 months ago

      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.

      • flatbield
        link
        fedilink
        English
        62 months ago

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

        • @crimsonpoodle@pawb.socialOP
          link
          fedilink
          52 months ago

          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

          • flatbield
            link
            fedilink
            English
            32 months ago

            For what it is worth. I learned C in 1990. Switched largely to Python in 1998.

          • bluGill
            link
            fedilink
            12 months ago

            True is not one in C. You can always compare a value to 0 if you need false but comparing to any single value for true is wrong. Often functions will return some calculated value which would be zero for false and who cares - it isn’t zero so return it for true. Thus all defines of true are suspect.

      • @JakenVeina@lemm.ee
        link
        fedilink
        English
        4
        edit-2
        2 months ago

        A function call of “MyFunction(parameter: GLFW_TRUE)” is more readable than “MyFunction(parameter: 1)”. Not by much, mind you, but if given the choice between these two, one is clearly better. It requires no assumptions about what the reader may or may not already know about the system.It communicates intent without any ambiguity.