|
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++?
|
|
|
|
|
The first line.
Your favorite style is worse, since you are using implicit casting and poor maintainable conventions.
I refer to MISRA-C 2004.
|
|
|
|
|
|
geoffs wrote: but it is a coding horror for my programming style and I am curious as to what the others here think about it.
As you said - it is a horror for your programming style. Different people use different styles, and as long as the code is correct and reasonably readable there is no point in discussing it.
|
|
|
|
|
Nemanja Trifunovic wrote: As you said - it is a horror for your programming style. Different people use different styles, and as long as the code is correct and reasonably readable there is no point in discussing it.
Are you serious?? Glad you're not in MY shop.
|
|
|
|
|
It's questionable. Depends on how much readability is necessary.
"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
|
|
|
|
|
I would have scoped it:
m_boolVar = (intVar != 0);
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: I would have scoped it:
m_boolVar = (intVar != 0);
Yeah, I do this, too. This is VERY readable to someone with sufficient competency in C# to be trusted with the maintenance of production code. The scoops highlight the boolean expression and make it a one-glance read; without the scoops, it requires a bit more concentration, which can be exhausting if you have to spend that bit of concentration 300 times while reading a single source file.
|
|
|
|
|
I think it's too trivial to fuss over.
|
|
|
|
|
dighn wrote: I think it's too trivial to fuss over.
If someone is wasting their time in writing such foolish expressions, and wasting my time by making me read it, it isn't trivial, not when I have to edit 200-300 lines of code before lunch.
|
|
|
|
|
i would go with:
m_boolVar = intVar ? true : false;
|
|
|
|
|
That would be invalid in C# or Java. Even in C/C++ I would always query against a Boolean expression for conceptual clarity.
Kevin
|
|
|
|
|
Swinefeaster wrote: i would go with:
m_boolVar = intVar ? true : false;
That combines the worst of expression one with the worst of expression three.
|
|
|
|
|
I use the style of your second example though usually with brackets around the expression.
m_boolVar = (intVar != 0);
However, recently I've been moving towards dispensing with the brackets too, partly prompted by my refactoring tool.
Kevin
|
|
|
|