Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Boolean Variable Name

Boolean Variable Name

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
16 Posts 9 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Rage

    Bill, searching frenetically in the pile of paper on his desk while hitting F5. Bill: "Oh god, I keep losing this post-it on which I note the address of the array cell that does not get filled properly" James, sitting next to him, smiling :" Why don't you rename a variable after it ?..." Bill:" Oh yes, good idea, I suppose I'll remove it later in the production code." :rolleyes:

    N Offline
    N Offline
    Nagy Vilmos
    wrote on last edited by
    #7

    What's really scary is that I'm a 'Bill', well a William, and my old boss was a James. The stupidity of the 'James' suggestion reminded me of him. (I must find out if he's sober yet; it has been seven years)


    Panic, Chaos, Destruction. My work here is done.

    1 Reply Last reply
    0
    • K killabyte

      haha that is great :-D the only place u should see hex numbers is Hardware.h imho

      S Offline
      S Offline
      supercat9
      wrote on last edited by
      #8

      I will confess to having used hex-ish variable names in code for certain hardware ports which didn't have standardized names. I've also used hex-ish defined constants for colors which needed to be remappable to different hardware (an NTSC system used $1x for gold, $4x for red, $8x for blue, $Cx for green, and $Fx for green-yellow; PAL systems mapped the colors completely differently). Although there are defined names for colors, I find it much easier to know that $3x is an almost red orange than to remember whether "ORANGE" refers to $2x or $3x. Those things having been said, the code here looks like it may have been obfuscated.

      1 Reply Last reply
      0
      • D Daniel Kanev

        Hi, I once saw in a real piece of code the following fragment! Nice name, don't you think? { boolean e0x0301=false; . . . if (!e0x0301) { ... } }

        L Offline
        L Offline
        Lutoslaw
        wrote on last edited by
        #9

        Looks like this variable determines whether an object has a particular set of flags. If there would be, let say, 10 flags, then a 'meaningful' name would have to be "IsFlag1AndFlag2AndFlag3And....AndFlag10AndNothingElse = false" So, for the author of a flag's enumeration this is just a short form of the above.

        Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

        L 1 Reply Last reply
        0
        • K killabyte

          haha that is great :-D the only place u should see hex numbers is Hardware.h imho

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #10

          Ummm, no I'm very fond of adding flag words to objects instead of doing something horrible like adding countless bool members. Usually they are an enumerated type and defining them in anything than hex is awkward. Like this:

          // Yes, I still have the CAPITAL habit from C++
          [flags]
          public enum D_SOMEFLAGS : ulong
          {
          // empty flag word
          NONE = 0x0000000000000000,

          // 1 = object has been validated, 0 = object has not been validated
          VALIDATED         = 0x0000000000000001,
          
          // 1 = Object has been changed, 0 = object is still original
          CHANGED           = 0x0000000000000002,
          
          // many more...
          

          }

          But I agree that hex notation should only be used in variable names on rare occasions.

          A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

          K 1 Reply Last reply
          0
          • L Lutoslaw

            Looks like this variable determines whether an object has a particular set of flags. If there would be, let say, 10 flags, then a 'meaningful' name would have to be "IsFlag1AndFlag2AndFlag3And....AndFlag10AndNothingElse = false" So, for the author of a flag's enumeration this is just a short form of the above.

            Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #11

            A few posts above I also commented on flags.

            // Yes, I still have the CAPITAL habit from C++
            [flags]
            public enum D_SOMEFLAGS : ulong
            {
            // empty flag word
            NONE = 0x0000000000000000,

            // 1 = object has been validated, 0 = object has not been validated
            VALIDATED         = 0x0000000000000001,
            
            // 1 = Object has been changed, 0 = object is still original
            CHANGED           = 0x0000000000000002,
            
            // many more...
            

            }

            would it not be better (using my example there) to add something like ... CHANGED_AND_VALIDATED = 0x0000000000000003; ... to the enumeration?

            A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

            L 1 Reply Last reply
            0
            • L Lost User

              A few posts above I also commented on flags.

              // Yes, I still have the CAPITAL habit from C++
              [flags]
              public enum D_SOMEFLAGS : ulong
              {
              // empty flag word
              NONE = 0x0000000000000000,

              // 1 = object has been validated, 0 = object has not been validated
              VALIDATED         = 0x0000000000000001,
              
              // 1 = Object has been changed, 0 = object is still original
              CHANGED           = 0x0000000000000002,
              
              // many more...
              

              }

              would it not be better (using my example there) to add something like ... CHANGED_AND_VALIDATED = 0x0000000000000003; ... to the enumeration?

              A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

              L Offline
              L Offline
              Lutoslaw
              wrote on last edited by
              #12

              Yes and I add such extra pieces to enumerations too. However, in the situation I mentioned there are a lot of various flags and the additional enum member would look sth like

              CHANGED_AND_VALIDATED_AND_FLAG3_AND_FLAG5_AND_FLAG11_AND_FLAG12_AND_.... = some code

              I have nothing against long names in programming but if a name of one of constants starts taking more than 10% of a whole method content then something is going wrong I think. Although 0x0301 contains just three flags, it's very simple to determine which flags are used (x0100, x0200 and x0001), therefore there is nothing bad in **e**_code_ boolean names.

              Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

              L 1 Reply Last reply
              0
              • L Lost User

                Ummm, no I'm very fond of adding flag words to objects instead of doing something horrible like adding countless bool members. Usually they are an enumerated type and defining them in anything than hex is awkward. Like this:

                // Yes, I still have the CAPITAL habit from C++
                [flags]
                public enum D_SOMEFLAGS : ulong
                {
                // empty flag word
                NONE = 0x0000000000000000,

                // 1 = object has been validated, 0 = object has not been validated
                VALIDATED         = 0x0000000000000001,
                
                // 1 = Object has been changed, 0 = object is still original
                CHANGED           = 0x0000000000000002,
                
                // many more...
                

                }

                But I agree that hex notation should only be used in variable names on rare occasions.

                A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

                K Offline
                K Offline
                killabyte
                wrote on last edited by
                #13

                well we arent really in disagrement because when using this you will never see the values set only the symbols which is fine, good practise for saving memory infact. the conatations i was implying was that hex numbers should be out of the way.

                1 Reply Last reply
                0
                • L Lutoslaw

                  Yes and I add such extra pieces to enumerations too. However, in the situation I mentioned there are a lot of various flags and the additional enum member would look sth like

                  CHANGED_AND_VALIDATED_AND_FLAG3_AND_FLAG5_AND_FLAG11_AND_FLAG12_AND_.... = some code

                  I have nothing against long names in programming but if a name of one of constants starts taking more than 10% of a whole method content then something is going wrong I think. Although 0x0301 contains just three flags, it's very simple to determine which flags are used (x0100, x0200 and x0001), therefore there is nothing bad in **e**_code_ boolean names.

                  Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #14

                  True, but in that case usually some kind of operation is associated with a particular combination of flags. You might use the name of this operation instead of naming all Flags involved. You can still elaborate in the comments. Something like this:

                  ...

                  /// Flag combination for sucessful modifications by the user,
                  /// includes the following flags:
                  /// - MODIFIED
                  /// - VALIDATED
                  /// - APPROVED_BY_BOSS
                  /// - DB_UPDATE
                  /// (many more)
                  MODIFIED_BY_USER = 0x90aebeee7a3f017b,

                  ...

                  A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

                  L 1 Reply Last reply
                  0
                  • L Lost User

                    True, but in that case usually some kind of operation is associated with a particular combination of flags. You might use the name of this operation instead of naming all Flags involved. You can still elaborate in the comments. Something like this:

                    ...

                    /// Flag combination for sucessful modifications by the user,
                    /// includes the following flags:
                    /// - MODIFIED
                    /// - VALIDATED
                    /// - APPROVED_BY_BOSS
                    /// - DB_UPDATE
                    /// (many more)
                    MODIFIED_BY_USER = 0x90aebeee7a3f017b,

                    ...

                    A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

                    L Offline
                    L Offline
                    Lutoslaw
                    wrote on last edited by
                    #15

                    Dammmit we still agree. I was thinking of it when I was posting my message and wondering if you express that. Hmm I think we have a dead end in this discussion. Cool signature by the way.

                    Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

                    L 1 Reply Last reply
                    0
                    • L Lutoslaw

                      Dammmit we still agree. I was thinking of it when I was posting my message and wondering if you express that. Hmm I think we have a dead end in this discussion. Cool signature by the way.

                      Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #16

                      Agreement is the best conclusion we can reach. :) Until next time then.

                      A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups