Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming Conventions: What to name a method that returns a boolean? [closed]

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?

like image 743
ashtee Avatar asked Sep 03 '09 00:09

ashtee


People also ask

How do you name a method that returns a boolean?

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

How do you name a function that returns a boolean in Python?

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.

What naming convention should be used for method names?

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.

How do you name boolean values?

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.


1 Answers

IsRetrievable() 

I think that a method that returns a boolean value should be named as a yes-no question.

like image 175
Aziz Avatar answered Sep 28 '22 08:09

Aziz