views:

379

answers:

7

I have an interface in c# that helps retrieving of data from a custom archive on server. The interface looks like this:

public interface IRetrieveData
{
    bool OkToRetrieve(SomeData data); // Method in question...
    bool RetrieveToLocal(SomeData data);
}

This interface is implemented by the clients that retrieve the data to the local database. There are different flavors of clients that have access to each others data. So, when the processing component calls IRetrieveData.OkToRetrieve right before actual retrieve, the call goes to the client code where the decision is made on whether the data should be retrieved or not. At this point the client can return false and that piece of data is skipped or return true and the processing component calls RetrieveToLocal and send the data to the client which then processes it.

Where I am getting confused is whether to rename the method "OkToRetrieve" to just "Retrieve" or "CanRetrieve" or leave it as OkToRetrieve.

Does anyone have any suggestion?

+14  A: 
IsRetrievable()

I think that functions that return boolean value should be named as a yes-no question.

Aziz
I like the `is` part, but just because it is retrievable doesn't mean it's OK to retrieve it. I would call it `isOKToRetrieve`
Thomas Owens
Absolutely. The "Is" prefix is a coding standard on our team.
Rap
ALl I would add TO Ariz' answer, (And this is a nitnoi) is to make a distinction as t oexactly what the function is checking... Is it whether the data IS retrievable, or whether the current code CAN retrieve it, or whether it SHOULD rectrieve it, etc. etc. e.g., if the function is examining the validity of the data and 'authorizing the retrieval when the data passes some set of conditions, then IsComplete() or IsValid, or IsTransactionallyConsistent, or something that describes the nature of the check that is being done to 'pass' might be somewhat more informative.
Charles Bretana
@bpayne Uhhh how would you use "Is" for something like shelf.HasProducts() or body.ContainsKnife()?
mxmissile
mxmissile: I would call those methods `isEmpty()` (and, if the shelf has a limit, `isFull()`) and I would NEVER make a `containsKnife()` method, but rather a `contains()` method that accepts a parameter. And yes, `contains()` is an exception to the is rule.
Thomas Owens
I think what Aziz has suggested about having it as a Yes No question is right. So, as Thomas Owens has commented above I am going with IsOkToRetrieve().
ashtee
@bpayne fair enough, i'm assuming isEmpty() and isFull() would contain parameters if shelf could contain more than "products"?
mxmissile
+5  A: 

Allways name boolean methods with names similar to questions that can be answered Yes or No.

In your case, CanRetrieve would be a good name (just to use your own suggestion).

eKek0
A: 

CanRetrieve sounds fine to me. I've seen the Can stem used in Microsoft APIs. The only other real option IMO is IsRetrievable (from Aziz) which somehow seems too linguistically twisted!

spender
A: 

if you are doing more checks and isRetrievable() isn't appropriate you could use:

IsValid()
davidsleeps
A: 

I would prefer isOKToRetrieve or isRetrieveOK over variants without "is" under the convention that functions and methods should be verbs.

Tyler McHenry
A: 

Methods mean action. Therefore, I prefer method names to start with a verb. How about?

CheckIsRetrievable(SomeData data)
Mehmet Aras
"Is" is a verb...
Marcel Lamothe
A: 

In this specific case, I'd probably name it:

public bool IsReady (SomeData)

Because it more clearly demonstrates what will happen once this returns true.

Noon Silk