This page looks best with JavaScript enabled

Notes on The Art of Readable Code

 ·  ☕ 1 min read

1. About Names

  • Choose professional words
  • Avoid overly generic names
  • Use concrete names instead of abstract ones
  • Use prefixes or suffixes to attach more information to a name
  • Decide how long a name should be
  • Use the formatting of a name to express meaning

2. Packing Information into Names

Generally speaking, adding words like is, has, can, or should makes a boolean value more explicit.

A method starting with get is conventionally treated as a lightweight accessor that simply returns an internal member variable. Violating that convention can mislead users. i

  • Package names, module names, local variable names, function names

All lowercase + underscore-style camel case

eg: this_is_var

  • Global variables

All uppercase + underscore-style camel case

eg: GLOBAL_VAR

  • Class names

Initial-capital camel case

Example: ClassName()


WeChat Official Account
WRITTEN BY
WeChat Official Account