Skip to content

Instantly share code, notes, and snippets.

@xpepper
Forked from xplayer/CleanCode.2.names.md
Last active April 25, 2019 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xpepper/3914f9970defb77d29d4 to your computer and use it in GitHub Desktop.
Save xpepper/3914f9970defb77d29d4 to your computer and use it in GitHub Desktop.
CleanCode episode 2 on names

Names

The name that you use should reveal your intent

  • comments are a smell of a badly chosen name!
  • Only choose names that communicate your intent

Use pronounceable names

Avoid disinformation

  • Make sure that a name says what it means, and means what it says
  • When you have to read the code to understand what a name (of a method or a variable) mean, the name that you chose is bad

When naming, avoid special encodings

  • Avoid special encodings in naming your variables (es: IAccount instead of Account), just use names

Choosing names for classes and functions

When naming things remember:

  • Classes and variables are nouns (or noun phrases),
  • Methods are verbs (or verb phrases)
  • Avoid "Manager", "Data", "Info", "Data", "Handler"
  • Methods returning a boolean should be named like "IsXXX"

The Scope Length Rule

  • the longer the scope of the variable, the longer the name of the variable
  • variable with short tiny scope should have very short name (even a single letter)
  • the longer the scope of the method or class, the shorter the name of the variable
  • i.e. private methods should have long intention-revealing and descriptive names
  • functions that are called from many places should have short and convenient names
  • public classes (with long scope) should have short convenient names
  • private classes with limited visibility (with short scope) should have long names
  • be careful: derived classes may have long names, longer that its parent class, since it may have more adjectives added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment