File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Cattle Drive and the fly likes Style Question: someMethod( expression ) vs. someMethod(expression) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Style Question: someMethod( expression ) vs. someMethod(expression)" Watch "Style Question: someMethod( expression ) vs. someMethod(expression)" New topic
Author

Style Question: someMethod( expression ) vs. someMethod(expression)

Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
Hi,

I can't figure out from the style guide whether there is a preferred format for spacing within parentheses.

There are examples of both



and

Should I just choose one and stick with it?

Katrina
Nick White
Ranch Hand

Joined: Oct 09, 2006
Posts: 94
Katrina

Hi... again.

I guess whatever you decide, or whatever I tell you, will be of little difference in the end. (you will understand one day! )

Spacing (you might want to double the Style Guide on spacing around casts)


I have pobably given away way too much already, but I got this quote from Pauline (one of th excellent nitpickers), on one of my assignments.

What did I do? you may ask...

Only went and typed (int) - note there are no spaces!!!

If you want my advice... (I doubt you do, but heh I am only trying to help), the style guide is only the start....

Forget about the gaps etc (don't. but you WILL understand one day... )

It will all become natural, and the then you can grind your teeth on the code.

Katrine - welcome once again - you WILL enjoy

Regards

Nick
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Hi Katrina,

As far as spacing goes within parentheses, you're generally OK with any of those options in your subject and the examples you cite. (Check the Style Guide for exceptions.)

Though the Style Guide doesn't require you to stick with one or the other, I think your idea to choose one and stick with it is a good approach. I think there's something about consistently formatted code that makes it easier on tired eyes (and brains) to read and grasp.

You'll see it soon enough: readability is Big Thing 'round these parts.

Have fun!
Pauline
[ November 04, 2006: Message edited by: Pauline McNamara ]
Nick White
Ranch Hand

Joined: Oct 09, 2006
Posts: 94
Hi Pauline

How are you?

Feelin' mean?

Looking forward to number 5...... (of course, that means you give me the green light on 4b! ).

I see there is a whole bunch of us on 4b..............

Perhaps we could send a posse round

Hope the weather is Ok in Switzerland - sunny and cold here.

Regards

Nick
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Howdy Nick

Only went and typed (int) - note there are no spaces!!!


Actually, if this was part of a cast, the (int) is fine. If I remember correctly, that nitpick was about another part of that same cast...


Anyway, here's what the Style Guide says about casts and spacing:

All casts should be written with no spaces.

(MyClass) v.get(3); // NO!
( MyClass )v.get(3); // NO!
(MyClass)v.get(3); // YES!


Happy trails,
Pauline
Nick White
Ranch Hand

Joined: Oct 09, 2006
Posts: 94
Hey cowgirl

Not complaining...just looking forward to Katrina joing the trail... and if she can see through the dust that I kick up, well that's great

Now about 4b.....
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9048
    
  10
The Style Guide used to require spacing around all identifiers, which is why you see the space between the identifier and the parenthesis. However, that constraint has recently been lifted. I would think, however, that your code would be more readable if you choose one way and use it consistently (unless the nitpicker or Style Guide tells you otherwise for a particular situation).


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
Thank you for helping me out on this one. I think I will leave the rest of the discussion for future nitpicks.

Katrina
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Style Question: someMethod( expression ) vs. someMethod(expression)