|
Let me get this right, you're asking about how stupidity can exist on the internet. The only type of question more likely to get a yes answer than 'can there be anyone on the web that stupid/ignorant/obnoxious' is 'can there be anything on the web that gross/perverse/obscene'.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Not to stray too far off topic but what's the "scandinavian language roots" you are referring to..? I'm Norwegian and have no clue what it might be.
|
|
|
|
|
Corruption of the verb nigle.[^]
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Thanks! Interesting, and potentially good South Park material. I've got to say though that "å nigle" isn't exactly everyday Norwegian in 2008. A quick google search for "nigle site:.no" returned 15 results, in most of those it was a name, some of them were Danish texts (though on .no sites), though there was ONE page that used it as a verb: Ka du står der å nigle ætter? (What are you standing there [å nigle] after?)
|
|
|
|
|
Not overly surprising, the US's major wave of immigration from Scandinavia was a century ago.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
|
Megidolaon wrote: Your code is shorter, but the other one is easier to read.
Easy to read for someone who doesn't understand what booleans are, yes. I don't want someone coding for me who doesn't understand booleans - they probably don't understand much else, either.
The third expression the original poster gives is the kind of thing that C programmers do all the time, but I don't think it's really appropriate for an application that has to be maintained by programmers of indeterminate skill. However, the first expression simply exposes the one who wrote it as ignorant.
|
|
|
|
|
geoffs wrote: m_boolVar == !!intVar;
And this one
m_boolVar = !intVar;
Although ! is shorter, I prefer to use the != way because it's clearer.
Eslam Afifi
|
|
|
|
|
The second example was only if I was feeling in a perverse mood.
However, like GDavy, you caught me in another instance of fingers not doing what my mind was thinking. I meant to type '=' and not '=='. I obviously posted this way too late in the evening (almost midnight my time). I corrected this in the original.
Also, you cannot use just one logical negation because we want the receiving bool variable to receive true if the int variable is non-zero. One negation reverses the true/false sense which, for this example, means that m_boolVar becomes true if intVar is 0 and false otherwise. That is not what was desired.
Time to go to sleep...
|
|
|
|
|
Oops , you're right. Sorry. It's 9:12 am here and I'm still awake. I think I should sleep .
Eslam Afifi
|
|
|
|
|
For me
<blockquote class="FQ"><div class="FQA">geoffs wrote:</div> m_boolVar = intVar != 0;</blockquote>
is the bestest style.
Generally != is a better option then == .
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Thanks for the vote of confidence!
On another point, I was with you until that last statement. Wouldn't the choice of '==' versus '!=' be completely dependent on what comparison you were trying to make? Generally isn't a term I would apply here.
|
|
|
|
|
I agree. Rather than choose by operator preference (precedence?) one should define the flag that makes most sense and use whatever operators needed to get there.
bool sameSize = (x*y == z*w);
bool eligible = (salary >= 30000 || fortune >= 200000);
bool defined = ((value ?? defaultValue) != null);
...
|
|
|
|
|
It's just different styles of programming rather than a coding horror.
|
|
|
|
|
I agree that it leans more towards the stylistic category rather than coding horror. That's why after I'd posted I wondered if I shouldn't have more appropriately posted this in the Soap Box. Oh well...
|
|
|
|
|
RugbyLeague wrote: It's just different styles of programming rather than a coding horror.
If you coded "boolean_value == true" in my shop, I'd do my best to get you out of my shop as quickly as possible. Calling this convention a "style" is like calling a bum's rags "fashion."
|
|
|
|
|
Hey! Keep my rags out of it a***ole!
|
|
|
|
|
dojohansen wrote: Hey! Keep my rags out of it a***ole!
*gives him $5 to buy new clothes from a thrift*
|
|
|
|
|
Not a horror, in my opinon.
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]
|
|
|
|
|
If you had typed to fast and made a mistake, the reader might have read too fast and made a mistake too.
Yours is more "horror" than the first example, IMO.
|
|
|
|
|
I am in complete agreement with you that the verbosity of the line of code that didn't sit well with me would surely tend to slow any reader down. When I am being asked to review hundreds or thousands of lines of code I would rather be slowed down for consideration of the correctness of the solution for the problem rather than issues of coding style like this.
BTW, the issue of being tired and thus not typing what the mind was thinking is an issue that can result in mistypes regardless of how the line was coded. It is often best to not program when exhausted (and obviously to not post to Code Project when same).
|
|
|
|
|
Totally agree - it *is* a coding horror.
Anyone who uses a ternary of type boolean is a twit.
|
|
|
|
|
Hey, I am really getting to like you...
|
|
|
|
|
For embedded people, this is the misra conform code :
if (0!=intVar)
m_boolVar=true;
else
m_boolVar=false;
Your first example breaks at least three rules.
|
|
|
|
|
Which example are you pointing at? The original line of code that I didn't like, or my preferred coding style?
Also, which MISRA guidelines are you utilizing... MISCRA-C 1998, MISRA-C 2004, MISRA-C++?
|
|
|
|