Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming conventions: Guidelines for verbs/nouns and english grammar usage

Can anyone point me to a site, or give me some wisdom on how you go about choosing names for interfaces, classes and perhaps even methods and properties relating to what that object or method does?

This is specifically for Microsoft development, so Java-esque "doGet" and so on isn't really used, however some general rules that cross language barriers must (I would've thought) exist.

An example might help: I have 4 choices of names for an interface:

IGroupedItem
IGroupableItem
IDataEntity
IGroupedEntity

They all contain an adjective and the noun, or just a noun. Looking at the .NET framework it seems like there must be some kind of ruleset for this, for consistency? Aside from the obvious verbs for methods.

Edit: Though the example is an interface, I'm not limiting this to just interfaces. The general guideline is classes are nouns, methods verbs, properties nouns. I suppose what I mean is choice of the synonym. Is throwing "Entity" everywhere wrong

like image 924
Chris S Avatar asked Jan 05 '09 11:01

Chris S


People also ask

What naming convention should be used for method 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. Internal words start with capital letters.

What is naming convention and example?

A naming convention can include capitalizing an entire word to denote a constant or static variable (which is commonly done in Flash programming), or it could be a simple character limit in a coding language (such as SQL).

Why do we use different naming conventions?

Reasons for using a naming convention (as opposed to allowing programmers to choose any character sequence) include the following: To reduce the effort needed to read and understand source code; To enable code reviews to focus on issues more important than syntax and naming standards.

What comes under grammar in English?

English grammar is the set of structural rules of the English language. This includes the structure of words, phrases, clauses, sentences, and whole texts.


1 Answers

Look at the MSDN articles for naming guidelines. In short:

  • Use nouns for class names and property names (it's obvious)
  • For interface names, start with I and use nouns and/or adjectives to describe behavior
  • Use verbs for method names to describe action

For your example - IGroupableItem.

like image 179
Rumen Georgiev Avatar answered Oct 24 '22 03:10

Rumen Georgiev