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!

  • @[email protected]
    link
    fedilink
    English
    75
    edit-2
    17 hours ago

    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.

    • @[email protected]
      link
      fedilink
      63 hours ago

      I’m reminded of an old job’s database where every key was named “id_foo” instead of “foo_id”

      You didn’t have user_id. You had id_user. You didn’t have project_id, you had id_project. Most of the time, anyway. It was weird and no one could remember why it was like that. (Also changes to the DB were kind of just yolo, there wasn’t like a list of migrations or anything)

    • @affiliate
      link
      39 hours ago

      why not just take it a step further and make true = “Yes” and false = “No”

      • @[email protected]
        link
        fedilink
        1
        edit-2
        2 hours ago

        I have seen this, but with “Y”, “N” instead. That was the way the database stored it and the way the UI displayed it, but everything inbetween converted to boolean instead, because there was logic depending on those choices. It wasn’t that bad, all things considered, just a weird quirk in the system. I think there was another system that did just use those strings plain (like WHERE foo = 'Y' in stored procedures), but nothing I had to work with. We just mapped “Y” to true when reading the query results and were done with it.

        (And before anyone asks, yes, we considered any other value false. If anyone complained that their “Yes”, “y” or empty was seen as false, we told them they used it wrong. They always accepted that, though they didn’t necessarily learn from it.)

      • @[email protected]
        link
        fedilink
        English
        29 hours ago

        It would probably carry less risk, but in terms of bytes used this would be even worse. And we have other problems there that I’d tell you about but it would make me too sad.

    • unalivejoy
      link
      fedilink
      English
      1014 hours ago

      Does your boss frequently browse the database table records outside the API?

    • @forrcaho
      link
      24
      edit-2
      16 hours ago

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

      • Trailblazing Braille Taser
        link
        fedilink
        11
        edit-2
        13 hours ago

        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?

        • @[email protected]
          link
          fedilink
          813 hours ago

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

            • @[email protected]
              link
              fedilink
              16 minutes ago

              I mean, if you have a billysbool class anyway, you’d make its truthiness correct according to bossman’s scheme, and then the not operator would work correctly.

      • @[email protected]
        link
        fedilink
        English
        1315 hours ago

        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.

    • @[email protected]
      link
      fedilink
      English
      1
      edit-2
      9 hours ago

      Microsoft SQL Server has a bit type and you always use 0 and 1 and cast/convert them. No native bool type. It’s a hassle.

      • @[email protected]
        link
        fedilink
        English
        39 hours ago

        Well that would be ok, because any standard tool for interfacing with the database would transparently treat bit in the DB as bool in the code. I think many DBs call it a bit rather than a bool.

          • @[email protected]
            link
            fedilink
            English
            19 hours ago

            I’m used to ORM layers where you can write SQL queries but you’re basically converting the results to objects before you use them. These kinds of things tend to handle bits OK, and bit parameters can usually be set as booleans directly. I haven’t used SQL Server in a while though so maybe it isn’t as convenient as that.

    • Pennomi
      link
      English
      117 hours ago

      deleted by creator