6.3 Camel case: defined

Sometimes there is more than one reasonable way to convert an English phraseinto camel case, such as when acronyms or unusual constructs like IPv6 oriOS are present. To improve predictability, Google Style specifies thefollowing (nearly) deterministic scheme.

Beginning with the prose form of the name:

  • Convert the phrase to plain ASCII and remove any apostrophes. For example,Müller's algorithm might become Muellers algorithm.
  • Divide this result into words, splitting on spaces and any remainingpunctuation (typically hyphens).
    • Recommended: if any word already has a conventional camel caseappearance in common usage, split this into its constituent parts (e.g.,AdWords becomes ad words). Note that a word such as iOS is notreally in camel case per se; it defies any convention, so thisrecommendation does not apply.
  • Now lowercase everything (including acronyms), then uppercase only the firstcharacter of:
    • … each word, to yield upper camel case, or
    • … each word except the first, to yield lower camel case
  • Finally, join all the words into a single identifier.Note that the casing of the original words is almost entirely disregarded.

Examples:

Prose formCorrectIncorrect
XML HTTP requestXmlHttpRequestXMLHTTPRequest
new customer IDnewCustomerIdnewCustomerID
inner stopwatchinnerStopwatchinnerStopWatch
supports IPv6 on iOS?supportsIpv6OnIossupportsIPv6OnIOS
YouTube importerYouTubeImporterYoutubeImporter*

*Acceptable, but not recommended.

Note: Some words are ambiguously hyphenated in the English language: for example nonempty and non-empty are both correct, so the method names checkNonempty and checkNonEmpty are likewise both correct.