|
(boolean_value = true) || (boolean_value == true)
|
|
|
|
|
VentsyV wrote: (boolean_value = true) || (boolean_value == true)
LMAO...Reading this, I was suddenly taken back to Irving M. Copi's _Introduction_to_Logic_, which I used as a textbook for an independent study in high school...it's the definition of a tautology...making it "too true"
|
|
|
|
|
You have good chances for a lot of small talk.
Greetings from Germany
|
|
|
|
|
I just found this in the project that I inherited ... it is working code. You don't have to be expert in ColdFusion to see that's something wrong with this
<cfloop index="i" from="1" to="1">
<cfloop list="#structKeyList(xnA)#" index="x">
<cfset y='xnA['&i&'].'&#x#&'.XMLtext'>
<cfset temp = QuerySetCell(clientQuery,"#x#",#evaluate(y)#, #i#)>
</cfloop>
</cfloop>
|
|
|
|
|
That's nothing wrong, it's simply a respectable horror.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
looks like code that at one time did something, but then got changed but never cleaned up
Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer.
-Fred Brooks
|
|
|
|
|
ditto, and maybe it was intentionally left that way because it may change yet again
|
|
|
|
|
StevenWalsh wrote: Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer.
-Fred Brooks
That's actually not matter of faith: while nature obeys God's plans, the software engineer deals with project manager's ones.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I've done that; I've shrunk the range of a for loop for testing and then forgot to put it back.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Yuck.
"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
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
First, let me say that the code excerpt below is not an egregious violation (and maybe not a violation at all), but it is a coding horror for my programming style and I am curious as to what the others here think about it.
So, in reviewing a coworker's code I come across the following line:
m_boolVar = (intVar == 0 ? false : true) ;
Yes, parenthesization and spacing exactly as shown above. Were it my code, it would have been written as:
m_boolVar = intVar != 0;
...or if I was feeling in a bit more perverse mood:
m_boolVar = !!intVar;
There were much bigger fish to fry in this code, but there are times when I just can't let things like this go by. These things are like misspelled words that shout out at me from among the surrounding text.
modified on Tuesday, September 16, 2008 3:02 AM
|
|
|
|
|
Uhm I think your code would have a bug....
You better write it this way:
m_boolVar = intVar != 0;
|
|
|
|
|
Yeah, thanks, I typed too fast. Sometimes (as you get older) what you are thinking doesn't quite translate into what you are typing!
|
|
|
|
|
geoffs wrote: as you get older
Don't worry about it, I can have that too, and I'm not that old yet (little over 30). And luckily not everything I think is being translated into what I'm typing
As to your original post, I completely agree with you. I have the unlucky position to have to tackle code that has multiple gems like these.
Is the logical expression that difficult to read for some that they have to literally assign a 'true' or 'false'? Or perhaps the coder fears that the logical expression returns a different kind of bool than true or false?
I myself find it bad code-practice.
|
|
|
|
|
geoffs wrote: Yeah, thanks, I typed too fast. Sometimes (as you get older) what you are thinking doesn't quite translate into what you are typing!
Which can also happen when coding, and the original version would be less prone to this kind of error. Although I wouldn't have done it that way either. I find your last solution to be way more of a horror than the original though.
I also like putting parentheses around something like "Foo = (Bar != 0)" as it makes it visually more obvious what is going on.
He said, "Boy I'm just old and lonely,
But thank you for your concern,
Here's wishing you a Happy New Year."
I wished him one back in return.
|
|
|
|
|
David Kentley wrote: I find your last solution to be way more of a horror than the original though.
I did use the word perverse with regards to the last solution. But sometimes I feel that way.
I must disagree with you with regard to the first version as I feel that it is just as prone, if not more so, to errors from mistyping.
|
|
|
|
|
Your code is shorter, but the other one is easier to read.
Your code is still pretty easy to read but I think readability is more important than conciseness.
When you look at someone's or even your own code after a while (to find a bug or whatever), it's best if you can easily read and immediately grasp the function of the code.
If everything is as concise as possibly, you often have hard to read code, which takes much longer to comprehend.
So, writing easy to read code will save you time later.
|
|
|
|
|
That's what people are always saying and perhaps rightfully so. However, coming from a background of programming stemming from the mid-70's when I had 4KB of memory to program with and compilers that weren't as optimizing as today's, conciseness was a virtue. After so many years it has become a habit but hopefully not to the point where I am so concise that I generate obfuscated code.
For me, verbose code is actually painful to read so maybe it works both ways.
And maybe there is no absolute wrong or right in this case either...
|
|
|
|
|
Oh, yes, I remember those days. Comments were out of the question since your source / the interpreter /the compiler had to fit into those 4 kb. And the same went for longer variable names, if the language supported them at all. But since then we literally got a million times as much memory at our disposal. Priorities have changed and now I also prefer clarity.
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.
|
|
|
|
|
Certainly true.
I think the real issue is whether or not the original line has any more clarity than the one I prefer coded up. IMO it does not. What part of "logical expression yielding a boolean result" is tough for any programmer to read and understand?
At some point, verbosity for clarity's sake can become ridiculous.
modified on Tuesday, September 16, 2008 11:02 AM
|
|
|
|
|
I have to agree.
m_boolVar = intVar != 0; is much clearer and easier to read, IMO.
Bill W
|
|
|
|
|
In fact I just had the very same situation today. A call to a SAP-Websewrvice yielded an integer as result. The function in which the web method was called was required by an interface to return a boolean value for success or failure.
In my case it came down to something like this:
...
ReturnValue = SAPWebserviceProxy.Z_XXXXXX(...);
ErrorFlag = IsError(ReturnValue);
if(ErrorFlag)
{
LogSAPError(ReturnValue);
}
else
{
LogSuccess(.....);
}
return ErrorFlag;
This is by no means great code, but at least everybody should be able to see what's going on. It's alwys a little awkward, no matter what you do.
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.
|
|
|
|
|
I would have no problems with how you coded that up.
|
|
|
|
|
Thanks
In any case, a simple method like
public static bool IsError(int ResultValue)
{
return ResultValue != 0;
}
will do the trick nicely. Such methods may appear a bit ridiculous as well, but actually the compiler should inline them when optimizing the code. And in cases when the return values represent not only success or failure, but also warnings, correctable errors, critical errors, fatal errors and who knows what else, a method to classify the result is much better than dealing with this redundantly in the code every time it's needed.
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.
|
|
|
|
|
geoffs wrote: For me, verbose code is actually painful to read
It's a question of striking the right balance. I often find that too many parentheses makes code harder to read in cases where removing those parentheses would cause no human ambiguity.
e.g., I prefer
if (a == b || c == d)
to
if ((a == b) || (c == d))
Similarly I prefer
return a == b;
to
return (a == b);
Kevin
|
|
|
|