|
Originally posted by Michael Matola:
If it's the assignment I think it is, the point is moot because there's a simpler way to write the method in question.
Originally posted by Michael Matola:
(2) However, JavaRanch style doesn't allow you to return from anywhere but the end of a method (grrr...)...
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Originally posted by Michael Matola:
Or you can just pull a
return b - a ;
if it's only the sign of the numbers and not their values that's relevant. (Now why would I think that...)
Originally posted by Peter Gragert:
Michael's second note
b-a may 'overflow', I would not use.
Originally posted by Johannes de Jong:
method in question
Which method. Is the - a method in this case and if it is of which class is it a method ?? Man I'm missing some basics here.
Originally posted by Johannes de Jong:
Overflow as far as I'm concerned can't happen when you subtract !!!
If you have to take into account others (beginners?), they should
learn this basic construct, shouldn't they?
Michael's second note
b-a may 'overflow', I would not use.
I'm so glad you asked - made me take a closer look at the method in question (and what it returns ). I'd been sidetracked by an example of that method that returned those values...
return b - a ; looks like a pretty clever solution.
Originally posted by Pauline McNamara:
In my current version of the "method in question", the return statement calls another class's method with almost the same name. Sound close?
Originally posted by jason adam:
By George I think she got it
By the way, enjoying the forum?
Originally posted by jason adam:
By George I think she got it
This is not an overflow problem. "- (-2147483647)" is simply a logical error ie. the programmer forgot (or did not know) the max signed value's. It's not an overflow error.
I see an overflow error as an runtime exception.
Originally posted by Pauline McNamara:
What do you think? Which of the following is more readable:
<pre>
return (a < b ? -1 : ( a == b ? 0 : 1 ) )</pre>
or this?
<pre>
if ( a < b )
{
return -1 ;
}
else if ( a == b )
{
return 0 ;
}
else
{
return 1 ;
}
</pre>
I'm particularly interested in hearing from you experienced programmers out there. Of course, since this is related to an assignment I'm working on, there's really only one opinion that counts in the end
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Well there is the '-' binary operator and there is the '-' unary operator. What else would you call the '-' binary operator if not subtraction?Originally posted by Michael Matola:
And besides, there's no such thing as subtraction. It's just a special case of addition (where at least one operand is negative).
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Originally posted by Johannes de Jong:
This is not an overflow problem. "- (-2147483647)" is simply a logical error ie. the programmer forgot (or did not know) the max signed value's. It's not an overflow error. I see an overflow error as an runtime exception.
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Well there is the '-' binary operator and there is the '-' unary operator. What else would you call the '-' binary operator if not subtraction?
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|