Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2008

Tip: Looking for answers? Try searching our database.

Some advice on method naming...

Thread view: 
harry - 29 Jun 2008 11:43 GMT
I have the following method in a java bean class -

private boolean saveReturnPart(List<WarningMessageVO> messages)
{
 boolean ret;

 // logic here determines if a Return Part should be saved and sets "ret"
variable

 return ret;
}

The method basically returns true if a return part should be saved, false if
not - the problem is (and probably a very stupid question) what should i
name the method?

 isSaveReturnPart() - doesn't sound right

 saveReturnPart() - sounds like it's doing the actual save

 shouldSaveReturnPart() - sounds right but is "should" the word to use?

is there a standard for this? - any suggestions?

thanks in advance

harry
Arved Sandstrom - 29 Jun 2008 12:32 GMT
>I have the following method in a java bean class -
>
[quoted text clipped - 23 lines]
>
> harry

'is' is the semi-standard prefix for boolean methods...that is, you see if
that'll work for you first. But 'has', 'can' and 'should' are also perfectly
acceptable, because they all imply a truth value.

Your last suggestion is fine - it expresses the desired idea exactly.

AHS
harry - 29 Jun 2008 12:48 GMT
>>I have the following method in a java bean class -
>>
[quoted text clipped - 31 lines]
>
> AHS

thanks for that Arved, jsut needed someone to give me a sanity check!
Patricia Shanahan - 29 Jun 2008 13:56 GMT
> I have the following method in a java bean class -
>
[quoted text clipped - 23 lines]
>
> harry

Of your ideas, I prefer "shouldSaveReturnPart". Personally, I would use
"doSaveReturnPart", but I think that is just a matter of taste.

Patricia
Daniel Pitts - 30 Jun 2008 16:09 GMT
> Of your ideas, I prefer "shouldSaveReturnPart". Personally, I would use
> "doSaveReturnPart", but I think that is just a matter of taste.
>
> Patricia
I disagree. While it is somewhat a matter of choice, its also a style of
communication.
To me, shouldFoo() implies a test to determine whether to call doFoo().
I would expect constructs like:
if (shouldFoo()) {
  doFoo();
}

If only Java had allowed "?" as part of an identifier.
if (saveReturnPart?()) {
  saveReturnPart();
}
Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Jean-Baptiste Nizet - 29 Jun 2008 13:59 GMT
harry a écrit :
> I have the following method in a java bean class -
>
[quoted text clipped - 19 lines]
>
> is there a standard for this? - any suggestions?

Hi.

If the method was a property accessor and should conform to the standard
JavaBeans naming conventions, the "is" prefix would be mandatory. I
would then choose a name like isReturnPartSaveNeeded(). But since this
is a simple method, which is private BTW, shouldSaveReturnPart is
perfect: it says exactly what themethod does.

JB.

> thanks in advance
>
> harry
Maarten Bodewes - 30 Jun 2008 00:32 GMT
> harry a écrit :
>> I have the following method in a java bean class -
[quoted text clipped - 28 lines]
> is a simple method, which is private BTW, shouldSaveReturnPart is
> perfect: it says exactly what themethod does.

I do think that getSaveReturnPart() would also be acceptable. I don't
use beans much, but maybe that's an advantage for questions like this.

Regards,
Maarten


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.