Pattern: Word Capitalization


Context

Often, due to syntax constraints in a language or file system, it is necessary to take a phrase and represent it as a single word with no embedded spaces. The resultant word should be easy on the eye and easy to scan, such that a reader can mentally parse it back to the original phrase.

Solution

Capitalise the first letter of each word in the phrase and remove the embedded spaces. Sometimes further massaging of the resultant word will be necessary, perhaps to lowercase the first letter as in the case of a Method Name, or to truncate the overall length.

Example

In class AttributeDescriptor the phrase, "Can generate read accessor?" is converted to a method name of canGenerateReadAccessor. Similarly the phrase "Method categorization policy" is word capitalized to form the class name, MethodCategorizationPolicy.

Consequences

Other name mangling policies are possible, such as replacing spaces with underscore characters. This would have the advantage of maintaining the word capitalisation within the phrase but it is not accepted Smalltalk policy since early implementations of the language did not support underscores in variable names. Also the effect is just plain ugly.