|
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.
|
|
|
|
|
Whoever wrote that probably has a background in Javascript where you can never be sure if a comparison operator actually converts to a bool.
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
|
|
|
|
|
JavaScript does make one a little twitchy.
cheers
Chris Maunder
|
|
|
|
|
I agree. Those parentheses are totally unnecessary.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
The one you posted has an extra semicolon, right?
bool myVar = (value < 0) ? : true : false;
Ternary operator only has one semicolon.
bool myVar = (value < 0) ? true : false;
But, yes, even the right syntax in this case is a waste, because the result of (value < 0) will result in true or false.
That's what you call your "Double-checking boolean code"
Here's the advanced code for superior programmers who want extreme overkill:
bool myVar = (value < 0)? true : (value > 0 ? false : true);
modified 5-Feb-18 8:28am.
|
|
|
|
|
raddevus wrote: The one you posted has an extra semicolon, right?
It did. Fixed.
raddevus wrote:
bool myVar = (value < 0)? true : (value > 0 ? false : true);
There we go! I knew someone could make the code better!
cheers
Chris Maunder
|
|
|
|
|
raddevus wrote: bool myVar = (value < 0) ? true : false;
raddevus wrote: bool myVar = (value < 0)? true : (value > 0 ? false : true);
That's the "advanced" version with the extra subtle bug that flips the result when value == 0 , right?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
"I meant to do that!"
|
|
|
|
|
And then you wonder what seems wrong when you walk in the door, then remove all confusion when you open the cupboard!
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Colts player Edwin Jackson, Avon man killed by suspected drunken driver[^]
F*** Drunk Drivers straight to the deepest depths of hell.
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???
|
|
|
|
|
IMHO - your title should have been F*** Drunk Drivers, with a link to the Edwin Jackson story.
Anyhow, I agree with your sentiment toward drunk driving.
|
|
|
|
|
BTW - It's also been determined that the drunk was in the country illegally.
|
|
|
|
|
I saw that about an hour ago.
|
|
|
|
|
I was playing Minecraft when my screen went all grayscale. I tried rebooting, but that didn't work. A quick Google lead me to a thread about this, and is appears Win + Ctrl + C will activate a screen filter of some sort. This might be NVidia, but no one in that thread was sure.
That's very annoying.
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???
|
|
|
|
|
So many hidden keystrokes[^], but yeah. Standard Win10 behaviour that's probably impossible to figure out what happened until it happens.
Wait, did I just describe Windows?
TTFN - Kent
|
|
|
|
|
Kent Sharkey wrote: that's probably impossible to figure out what happened until it happens
As opposed to knowing what happened before it happens?
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
Win+Ctrl +C does nothing opn my systemsexcept flas a little graythen go back to normal.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
I'd wish there was such a feature for a green-screen.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|