A style rule for CamelCase
"bactrian camels have two humps" is an example of a string.
It is common for programming languages that identifiers (labels or names for variables and values) are not just arbitrary strings, but very limited ones. Besides, they are distinct entities with their own syntax due to the omission of the quotation marks.
camel27 is a typical identifier.
As an immediate consequence, the lack of the quotations marks as delimiter means that white space must now be excluded from identifiers.
bactrian camels have two humps is not one, but (a sequence of) five identifiers.
One strategy to overcome this limitation is the insertion of strokes:
bactrian-camels-have-two-humps is an identifier in say Scheme and
CamelCase is another strategy for the conversion of multi-word phrases in a single word:
I suggest the following rule for the generation of CamelCase identifiers:
Suppose the descriptor for the identifier in native language has the form
w_1 w_2 w_3 .... w_n
nwords, separated by white space. For example,
the president of USA
Try to avoid one-letter words (such as
a) in the given phrase.
Now convert the phrase into a CamelCase identifier by doing:
For each of the
nwords, turn all but the first letter into small ones. So the example phrase now is
the president of Usa
Capitalize the first letter of the words
the President Of Usa
Remove the white space between the words, so
The result is your identifier.
Some of the words (but not
w_1 or two consecutive words) in the initial phrase may be decimals (e.g.
4321) and they remain unchanged. For example, the phrase
Henry 5 of England would turns into the identifier
Henry5OfEngland. In that case, in the word following the decimal, the first letter may remain unchanged, i.e. the
of does not have to be changed to
Of and the resulting identifier is
Remarks and examples
ECMAScriptis bad. The phrase
ECMA scriptconverts to the identifier
EcmaScriptand this would be a much better writing.
JSONis a bad identifier and should have been
JSONis a standard object in ECMAScript 5, and it is not only a badly, but also wrongly chosen identifier: usually only constants are exclusively written with capitals only.
The whole DOM is full of bad style identifiers, the most striking example is
XMLHttpRequest. Two acronyms in two versions (
Http), what a mess. It should have been
Another particular challenge is the naming of Node.js related code, especially since there already is a different
Node object in the standard. If we consider the dot as space between words,
Node.js is the phrase
Node js and that converts into
NodeJs, according to our rule.
Post a Comment