Pawel Pawlowicz wrote:In my short career as a programmer I saw this so many times that it made me wonder. Why some peopole just don't want to return condition?
Tim Driven Development | Test until the fear goes away
Karthik Shiraly wrote:I once misunderstood a piece of code thanks to one innocuous line that looked like this:
The ! and the l together - combined with the IDE font I was using and a mediocre monitor resolution - made the ! pretty inconspicuous while reading.
Ever since, I use "if (condition == false)" or its equivalent, no matter the language.
Better to make code less taxing to read for others, than save a few characters for no good reason.
Why some peopole just don't want to return condition?
Karthik Shiraly wrote:Ever since, I use "if (condition == false)" or its equivalent, no matter the language.
Better to make code less taxing to read for others, than save a few characters for no good reason.
Joanne
sai rama krishna wrote:
Why some peopole just don't want to return condition?
I would like to know what kind of condition you are expecting to return. I am not very clear.
Joanne
Tyson Lindner wrote:I just recently finished some coding practice at CodingBat and was surprised by how much I did this. I'm gonna make a small defense of it:
A lot of the time when we're coding our thought process goes like this:
1. Check condition
2. Do something
So we have two separate steps making things nice and organized for our brain.
But when we place the return keyword first, its almost like this step process gets reversed or at the very least intertwined. In our minds we're starting to "do something" (return a value) before or at the same as we're checking a condition. Our brains are handling two steps at once, which isn't necessarily a big deal, but I think sometimes its easier to just type a little more and take things one at a time.
Tyson Lindner wrote:But sometimes what you're returning isn't a boolean.
Joanne
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:&& already has higher precedence so these parentheses aren't necessary.
Rob Spoor wrote:Except by using the ternary operator:
Joanne
Joanne Neal wrote:
Tyson Lindner wrote:But sometimes what you're returning isn't a boolean.
In that case the shortcut won't work. It only works when you're using a condition to decide whether to return true or false.
Tyson Lindner wrote:But then again maybe that hassle is only a nano-second of thought to well experienced programmers.
Tyson Lindner wrote:But then again maybe that hassle is only a nano-second of thought to well experienced programmers.
Mike Simmons wrote:
Joanne
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Pawel Pawlowicz wrote:In my short career as a programmer I saw this so many times that it made me wonder. Why some people just don't want to return condition?
(....)
Piet Souris wrote:Well, the general form is:
Piet Souris wrote:Why would you want to make an exception to this rule, just for this very specific version:
Piet Souris wrote:Having said that, in the ongoing Scala course, I learnt to just write: A.
Piet Souris wrote:[(indeed, it's part of the struggle, getting used to
this form of syntax ) The problem is non existent there!
Pawel Baczynski wrote:I totally disagree with the opinion that writing return condition; should be called a shortcut.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Pawel Baczynski wrote:They make my eyes bleed
James Boswell wrote:
Pawel Baczynski wrote:They make my eyes bleed
This doesn't sound like the statement of someone who is happy...
Pawel Baczynski wrote:But I put a winky face after that statement
Tim Driven Development | Test until the fear goes away
Bear Bibeault wrote:
Tyson Lindner wrote:But then again maybe that hassle is only a nano-second of thought to well experienced programmers.
Well-experienced programmers know that good code is all about clarity, and not assuming that someone else will be clever enough to figure things out.
Pawel is correct, returning the condition is not "a shortcut"; writing a lot of unnecessary code is never correct.
Tyson Lindner wrote: just sometimes that's a result of following a normal step by step process.