Thursday, 28 July 2011

Capitalization of Inferred Names

Today's short blog covers the rules for the 'Capitalization of Inferred Names'. This is something so basic that we're all supposed to know about it. These rules are often mis-named and referred to as, for example: 'JavaBeans property naming rules’.

Given that naming and precision is so import in our business, I thought that I'd jot down a link to the appropriate document, just for revision purposes. So, the definition for the ‘Capitalization of inferred names’ can be found in Page 57, Section 8.8 of the Sun JavaBeans Specification.

And, just in case you can't be bothered to click on the link, the capitalization rules are, to quote the document:

When we use design patterns to infer a property or event name, we need to decide what rules to follow for capitalizing the inferred name. If we extract the name from the middle of a normal mixedCase style Java name then the name will, by default, begin with a capital letter. Java programmers are accustomed to having normal identifiers start with lower case letters. Vigorous reviewer input has convinced us that we should follow this same conventional rule for property and event names.

Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone. So for example,

    “FooBah” becomes “fooBah”
    “Z” becomes “z”
    “URL” becomes “URL”

We provide a method Introspector.decapitalize which implements this conversion rule.

No comments: