Why use "return (null);" instead of "return null;" ?

Why use "return (null);" instead of "return null;" ?

Post by Carl » Tue, 22 Aug 2006 11:28:48


I found "return (null);" in the source of struts's ActionForm class.
Why not "return null;" ? Is "return (null);" better than "return null;"
?
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Arne Vaj » Tue, 22 Aug 2006 11:56:57


No difference.

Arne

 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Jeffrey Sc » Tue, 22 Aug 2006 12:08:46


Except that one has more line noise. return(null) is a pet peeve of mine.

Some people prefer to use the parentheses for consistency with function
calls, loop tests, etc. I think they're also secretly insecure about
operator precedence, and can't shake the feeling that a statement like
"return 5 + x" will return five, discarding the value of x and losing
forever the knowledge of what it contained.
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by EJP » Tue, 22 Aug 2006 13:36:33


and mine

> Some people prefer to use the parentheses for consistency with
> function calls, loop tests, etc.

Apparently so. The trouble with that position is that 'return' *isn't* a
function call or a loop. And in C/C++/Java the parentheses are
specifically required around loop-expressions only because there is no
'do' as in Algol, PL/1, Pascal, ...

And it is certainly a pet peeve of mine that we went to all the trouble
of inventing formula translators fifty years ago so we could use
arithmetic precedence rather than reverse Polish, and there are *still*
people afraid to use it.
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Ed » Tue, 22 Aug 2006 17:02:46


Carl skrev:


http://www.yqcomputer.com/ #438

.ed

Download Fractality, free Java code analyzer:
www.EdmundKirwan.com/servlet/fractal/frac-page130.html
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Robert Kle » Tue, 22 Aug 2006 17:30:34


This sample from that URL is similarly silly:

return (size ? size : defaultSize);

This statement has exactly the same semantics and there is absolutely no
need for the brackets:

return size ? size : defaultSize;

Kind regards

robert
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Oliver Won » Tue, 22 Aug 2006 23:38:11


With the parenthesis, the return value is "more obvious in some way".

- Oliver
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by EJP » Wed, 23 Aug 2006 10:52:38


To whom? Someone who doesn't understand the syntax of the statement? So?
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by sgeo » Wed, 23 Aug 2006 10:57:38


I follow the "BEDMAS, parentheses around everything else" rule.
Easy to remember and everyone (with what, at least a sixth grade
education?)
should be able to understand the code even if they don't like
parentheses.

if ( (x || y) && z )
return x;

-Brendan
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Luke Webbe » Wed, 23 Aug 2006 13:08:23


Even BEDMAS doesn't hold true in Java, or in any other language I've
used. Division and multiplication have the same precedence, as do
subtraction and addition. Where precedence is equal, it goes left to
right. Whereas with BEDMAS, division comes before multiplication and
addition before subtraction. Which is a pretty screwed up rule, when you
think about it. But I guess /some/ kind of rule is better than none at
all. <g>

Luke
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Michael Ra » Wed, 23 Aug 2006 14:47:30

EJP schrieb:


It works similiar to serifs in fonts. The additional grouping
"highlights" the return value, making it more obvious for human readers.

Another example:

a = f = b == c ? d : e;

To figure out the return value one would have to _read_ the line.

If this expression had been written as

a = f = (b == c ? d : e);

everyone knows immediately what the return value is - just by looking at
the line.

Bye
Michael
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by sgeo » Wed, 23 Aug 2006 19:25:04


Division and multiplication are the same operation, as are addition and
subtraction. In any case, unless you are implicitly flooring your
results, puting division before multiplication shouldn't change
anything. I can't see a situation where addition before subtraction
make a difference. Care to enlighten me?

-Brendan
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Patricia S » Wed, 23 Aug 2006 19:57:34


I don't quite understand what you are saying here. First of all, (a-b)+c
is not at all the same expression as a-(b+c), and (a/b)*c is not the
same as a/(b*c). Addition and subtraction are different operations,
although they have equal precedence in Java.

Even ignoring that issue, for integer types multiplication and division
are non-associative, and for floating point types none of
multiplication, division, addition, and subtraction is associative. The
fact that Java evaluates a+b+c as (a+b)+c not a+(b+c) really does matter.

Patricia
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Chris Uppa » Wed, 23 Aug 2006 20:03:08


============
import java.math.BigDecimal;

public class Test
{
public static void
main(String[] args)
{
double big = (double)(1L<<40);
double ulp = Math.ulp(big);
double halfUlp = ulp / 2.0;

print("big", big);
print("ulp", ulp);
print("halfUlp", halfUlp);
print("(big - ulp) + halfUlp", (big - ulp) + halfUlp);
print("big - (ulp + halfUlp)", big - (ulp + halfUlp));
}

static void
print(String s, double d)
{
System.out.print(s);
System.out.print('\t');

// Patricia's technique for easily visualising the exact
// value of a double
BigDecimal bd = new BigDecimal(d);
System.out.println(bd.toPlainString());
}
}
============

-- chris
 
 
 

Why use "return (null);" instead of "return null;" ?

Post by Chris Uppa » Wed, 23 Aug 2006 20:31:26


Um, yes. So it isn't...

Please ignore my own reply to Brendan (sgeos).

I should think more when coding/posting :-(

-- chris