Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Why use "return (null);" instead of "return null;" ?

Reply
Thread Tools

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

 
 
Carl
Guest
Posts: n/a
 
      08-21-2006
I found "return (null);" in the source of struts's ActionForm class.
Why not "return null;" ? Is "return (null);" better than "return null;"
?

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      08-21-2006
Carl wrote:
> I found "return (null);" in the source of struts's ActionForm class.
> Why not "return null;" ? Is "return (null);" better than "return null;"
> ?


No difference.

Arne
 
Reply With Quote
 
 
 
 
Jeffrey Schwab
Guest
Posts: n/a
 
      08-21-2006
Arne Vajh°j wrote:
> Carl wrote:
>> I found "return (null);" in the source of struts's ActionForm class.
>> Why not "return null;" ? Is "return (null);" better than "return null;"
>> ?

>
> No difference.


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.
 
Reply With Quote
 
EJP
Guest
Posts: n/a
 
      08-21-2006
Jeffrey Schwab wrote:

> return(null) is a pet peeve of mine.


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.
 
Reply With Quote
 
Ed
Guest
Posts: n/a
 
      08-21-2006

Carl skrev:

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


http://java.sun.com/docs/codeconv/ht....doc6.html#438

..ed

--
www.EdmundKirwan.com - Home of The Fractal Class Composition.

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

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      08-21-2006
On 21.08.2006 10:02, Ed wrote:
> Carl skrev:
>
>> I found "return (null);" in the source of struts's ActionForm class.
>> Why not "return null;" ? Is "return (null);" better than "return null;"
>> ?

>
> http://java.sun.com/docs/codeconv/ht....doc6.html#438


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
 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      08-21-2006

"Robert Klemme" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On 21.08.2006 10:02, Ed wrote:
>> Carl skrev:
>>
>>> I found "return (null);" in the source of struts's ActionForm class.
>>> Why not "return null;" ? Is "return (null);" better than "return null;"
>>> ?

>>
>> http://java.sun.com/docs/codeconv/ht....doc6.html#438

>
> 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;


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

- Oliver

 
Reply With Quote
 
EJP
Guest
Posts: n/a
 
      08-22-2006
Oliver Wong wrote:

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


To whom? Someone who doesn't understand the syntax of the statement? So?
 
Reply With Quote
 
sgeos
Guest
Posts: n/a
 
      08-22-2006
Jeffrey Schwab wrote:
> 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,


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

 
Reply With Quote
 
Luke Webber
Guest
Posts: n/a
 
      08-22-2006
sgeos wrote:
> Jeffrey Schwab wrote:
>> 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,

>
> 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;


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why use ENC JNDI (java:comp/env) instead of JNDI name ? Mick Java 2 02-23-2005 12:50 PM
Why tuples use parentheses ()'s instead of something else like <>'s? seberino@spawar.navy.mil Python 44 01-06-2005 10:11 AM
Producer - Consumer Threads why use "while" loop instead of "if"? Usenet Poster!!! Java 4 09-30-2004 03:48 PM



Advertisments