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?
The usual convention to name methods that return boolean is to prefix verbs such as 'is' or 'has' to the predicate as a question, or use the predicate as an assertion. For example, to check if a user is active, you would say user. isActive() or to check if the user exists, you would say user. exists().
Function names should be lowercase, with words separated by underscores as necessary to improve readability. Typically, people start a function with is (e.g. is_palindrome ) to describe that a boolean value is returned.
Interface names should be capitalized like class names. Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter.
When naming booleans, you should avoid choosing variable names that include negations. It's better to name the variable without the negation and flip the value. If you absolutely can't (see Guideline 2 below), then try to find an already-negated form of the concept you are trying to express.
IsRetrievable()
I think that a method that returns a boolean value should be named as a yes-no question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With