Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Some advice on method naming...

Reply
Thread Tools

Some advice on method naming...

 
 
harry
Guest
Posts: n/a
 
      06-29-2008
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


 
Reply With Quote
 
 
 
 
Arved Sandstrom
Guest
Posts: n/a
 
      06-29-2008
"harry" <(E-Mail Removed)> wrote in message
news:9HJ9k.176125$(E-Mail Removed)2...
>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


'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


 
Reply With Quote
 
 
 
 
harry
Guest
Posts: n/a
 
      06-29-2008
"Arved Sandstrom" <(E-Mail Removed)> wrote in message
news:ZoK9k.927$7%6.23@edtnps82...
> "harry" <(E-Mail Removed)> wrote in message
> news:9HJ9k.176125$(E-Mail Removed)2...
>>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

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


thanks for that Arved, jsut needed someone to give me a sanity check!


 
Reply With Quote
 
Jean-Baptiste Nizet
Guest
Posts: n/a
 
      06-29-2008
harry a écrit :
> 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?
>


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

 
Reply With Quote
 
Maarten Bodewes
Guest
Posts: n/a
 
      06-29-2008
Jean-Baptiste Nizet wrote:
> harry a écrit :
>> 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?
>>

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


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
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      06-30-2008
Patricia Shanahan wrote:
> 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();
}
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
 
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
method def in method vs method def in block Kyung won Cheon Ruby 0 11-21-2008 08:48 AM
Give me some advice about some books of Java programing! yuyazhang Java 14 04-29-2006 11:13 AM
Seeking advice on some method names Gavin Sinclair Ruby 25 11-30-2004 01:11 PM
Needed: Advice on Film Scanning, Or Website Which Has This Advice Larry R Harrison Jr Digital Photography 0 09-06-2003 01:00 AM
Re: Celebrity advice (was: Advice to a Junior in High School?) Asun Friere Python 1 08-27-2003 12:01 PM



Advertisments