Search code examples
c#.netcoding-style

.Net Coding Standards Using a prefix "Is" or "Has" on Method Names


Is it advisable to prefix an "Is" or a "Has" when creating a method that returns a Boolean. My feeling is that this practice is more suited to defining property names.

Say, we have a method like the following has some logic:

bool IsActivePage()  
{  
 // Some logic to determine if the page is active...   
}

Would it be more preferable to rename the method to GetActivePageStatus and then create a boolean property IsActivePage that returns the result of that method.

What is the .NET standard? All opinions will be appreciated?


Solution

  • The Framework Design Guidelines state that you should "give methods names that are verbs or verb phrases" since "typically methods act on data". Properties, on the other hand, should be named "using a noun, noun phrase, or an adjective" and "you can also prefix Boolean properties with Is, Can, or Has, but only where it adds value".

    In this case, you are using a method rather than a property, probably since it is either expensive or has some side effects. I suggest you choose the name that provides the most clarity of what the returned value represents. The important part is that you're being consistent and that you're not confusing other developers with your convention.