I found "return (null);" in the source of struts's ActionForm class.

Why not "return null;" ? Is "return (null);" better than "return null;"

?

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.

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.

Carl skrev:

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

.ed

Download Fractality, free Java code analyzer:

www.EdmundKirwan.com/servlet/fractal/frac-page130.html

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

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

- Oliver

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

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

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

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

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

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

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

============

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

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

Please ignore my own reply to Brendan (sgeos).

I should think more when coding/posting :-(

-- chris

1. KLAcquireInitialTickets(NULL, NULL, NULL, NULL) returns klParameterErr (19276) on Mac OS X 10.6.3

2. Why it's returning NULLs instead of 0?

3. output parameters return NULL following a single NULL value

4. Is Not NULL still returning a NULL date??

5. Add WebForm returns 'null' is null or not an object

6. Some non-null fields being returned as null?

7. output parameters return NULL following a single NULL value

8. Subtracting Prev YTD from Current YTD where Prev is Null is always returning Null value

9. Should SQL concatenation return a null value if one field is null?

10. Can realloc(p,0) return NULL when p is non-NULL and memory aplenty?

11. Is Null returns records where value is not null

12. Null Concatenation always return null

13. Begin() applied on empty Vector returns NULL or non null value????

14. Can realloc(p,0) return NULL when p is non-NULL and memory aplenty?

15. Help query null/not null return 0/1