Naming Rules

For readability of your code, please refer to following naming guideline.

Pascal and Camel

Pascal

More than 3 characters, start with a capital letter.

Example

  • Name
  • Restaurant
  • FamilyName
  • OfficeLocation

Camel

Use small letters at beginning and use capital letter for 2nd words and after.

Example

  • name
  • restaurant
  • familyName
  • officeLocation

Tip 1. private field naming

For private object I star with underscore and use Camel


Tip 2.  public and static field naming

For public and static object I use


Tip 3. Make sure it is English and read-able

Example

  • createdDate instead of cd
  • today instead of td
  • result instead of r
  • minute instead of min
  • minimum instead of min

Tip 4.  If you are in lazy mode

When I am in lazy mode and used only locally in short code, may be it is OK to use followings

  • c for char
  • i for for loop 
  • n for integer
  • o for object
  • s for string
  • x for x coordinate
  • y for y coordinate
  • z for z coordinate

Tip 5. For data object, use noun

When you can, use noun.


Tip 6. For bool, make it obvious

Example

  • isEmpty
  • canExecute
  • hasTicket

or

  • done
  • success
  • created

And don’t use negative words.


Tip 7. For methods, use verb

Example

  • FindItem
  • SendMessage
  • SearchAthlete

Tip 8. Bad examples

Try not to use numbers

name1, name2, name3

Try not to use post fix flag for bool

isPrinted instead of printFlag

It is hard to know printFlag = true or false represent.

Use singular and plural

instead of

Make sure method name represent scope of method

If the method is SearchItem then limit your self to just doing so.  If you need to do other things to the item, create another method.

Try to share this with your team so that they can all follow and work under same naming guideline.

Leave a Reply