|
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.
|
|
|
|
|
OK, here is why:
I prefer the 'if x, then y = a, if not y=c' readability to 'y = if x'.
It just isnt explicit when I read the code. A programer might think the second is better, because its terser, but thats the thing I have seen so often, programmers glorying in how terse, and arcane, they can make their code at the expense of good simple readability.
I prefer explicit readability. Probably because I have more than enough complexity to deal with in the architecture when working in the kernel! It is viciously complex at times.
|
|
|
|
|
var negative = value < 0;
This way, variable "negative" will be automatically initialized as Boolean, and the value will be true if value is smaller than zero, otherwise it will be false.
|
|
|
|
|
In VB only.
I prefer the 'if x, then y = a, if not y=c' readability to 'y = if x'.
It just isnt explicit when I read the code.
|
|
|
|
|
I don't see why "x = condition" is not explicit enough.
is it negative value? = is the value smaller than zero? is pretty explicit and self explanatory.
there is no need to add this redundant statement : "if yes then it's truly negative, or else it's false"; because the first expression "is the value smaller than zero?" has given us a true or false answer already.
|
|
|
|
|
I just prefer 'if x = y then c = a, else c = z'
|
|
|
|
|
|
Oh man. Fixed.
cheers
Chris Maunder
|
|
|
|
|
Well, that is not elegant (and possibly less efficient) but correct. I would say both milk and cereal in the fridge.
|
|
|
|