|
GKP1992 wrote: The funny thing is that visual studio points it out to the developer
Not to me it doesn't (and I just double checked)
cheers
Chris Maunder
|
|
|
|
|
GKP1992 wrote: The funny thing is that visual studio points it out to the developer.
Not that I recall. However, Re-Sharper does.
|
|
|
|
|
I have SonarLint installed so, yeah forgot to mention that. You can slap me too if you want.
I remember this because I have seen legacy code like this,
bool someVariable;
...
...
bool someOtherVariable = someVariable == true ? true : false;
But I slapped myself over this too.
I am not the one who knocks. I never knock.
In fact, I hate knocking.
|
|
|
|
|
|
Even my mistakes have mistakes. Fixed. (so to speak)
cheers
Chris Maunder
|
|
|
|
|
And people wonder why Web apps are so horrible...
|
|
|
|
|
So you finally tried switching it off and on!
... such stuff as dreams are made on
|
|
|
|
|
I am very talented in turning honest mistakes into bad code.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Sure it compiles, but it was silly because the first expression has already created boolean result.
|
|
|
|
|
My mom would always put Ice Cream in the fridge. Now I always get it for her.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Also, Eel slap![^]
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
But Nobody Slapped him. Slap!
|
|
|
|
|
Slap and the Stick = SlapStick
|
|
|
|
|
Never trusted the ? operator in any language... too many questions(?) when you use the ? operator
|
|
|
|
|
Why? Value can be greater or lesser than 0 unless it is unsigned.
|
|
|
|
|
I see you are the one who write that code
|
|
|
|
|
How would you rewrite it? (I dont actually get into 'coding', I am far more an architectural engineer. )
|
|
|
|
|
Try this on for size:
bool myVar = (value < 0);
I have lived with several Zen masters - all of them were cats.
|
|
|
|
|
Is that any more concise? Dont know how many lines of assembler are in each version. The former is more explicit, it reads easier IMO (I like really readable code. The architecture is often so complex the code has to be very obvious in the kernel)
|
|
|
|
|
Define 'readable'. The problem is that 'readable' is a very subjective term. More concise it is, because an unneeded mapping bool -> bool is removed. Also, what if I just reverse true and false in at that point? It would take a while until someone spots this little treachery.
I have lived with several Zen masters - all of them were cats.
|
|
|
|
|
have you checked in in assembler to see if it is more concise?
CodeWraith wrote: what if I just reverse true and false in at that point
Why would you? You want the code to do what it should do.
|
|
|
|
|
Munchies_Matt wrote: Why would you? You want the code to do what it should do. |
Malice.
Or just beating the code into submission and later forgetting to clean up.
I have lived with several Zen masters - all of them were cats.
|
|
|
|
|
For me it's way, way better to do
value = condition
rather than
value = condition? true : false;
Because when reading you need to look at condition then you also need to check that true and false are in the correct order. Or should it be false and true?
I don't care what the assembler generates: I can about what the guy who comes after has to deal with when it's my code.
cheers
Chris Maunder
|
|
|
|
|
I guess its a personal preference thing.
|
|
|
|
|
Chris Maunder wrote: I can about what the guy who comes after has to deal with when it's my code.
Especially if that person is you in six months.
|
|
|
|