Boolean Variable Name
-
Hi, I once saw in a real piece of code the following fragment! Nice name, don't you think? { boolean e0x0301=false; . . . if (!e0x0301) { ... } }
-
Hi, I once saw in a real piece of code the following fragment! Nice name, don't you think? { boolean e0x0301=false; . . . if (!e0x0301) { ... } }
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:
-
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:
Nice :laugh:
-
Hi, I once saw in a real piece of code the following fragment! Nice name, don't you think? { boolean e0x0301=false; . . . if (!e0x0301) { ... } }
Looks like an obfuscated class have been decompiled anyway...
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://phi.lho.free.fr -
Hi, I once saw in a real piece of code the following fragment! Nice name, don't you think? { boolean e0x0301=false; . . . if (!e0x0301) { ... } }
-
Hi, I once saw in a real piece of code the following fragment! Nice name, don't you think? { boolean e0x0301=false; . . . if (!e0x0301) { ... } }
Yikes. That looks like something to do on a project when one is about to leave a company [evil grin]...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
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:
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.
-
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.
-
Hi, I once saw in a real piece of code the following fragment! Nice name, don't you think? { boolean e0x0301=false; . . . if (!e0x0301) { ... } }
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.
-
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.
-
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.
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.
-
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.
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
andx0001
), 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.
-
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.
-
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
andx0001
), 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.
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.
-
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.
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.
-
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.
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.