CamelCase

From Wikipedia, the free encyclopedia

Jump to: navigation, search

CamelCase (also spelled "camel case") or medial capitals[1] is the practice of writing compound words or phrases in which the words are joined without spaces and are capitalized within the compound—as in LaBelle, BackColor, or iPod. The name comes from the uppercase "bumps" in the middle of the compound word, suggestive of the humps of a camel. The practice is known by many other names.

Camel case is a standard identifier naming convention for several programming languages, and has become fashionable in marketing for names of products and companies. However, camel case is rarely used in formal written English, and most style guides recommend against its use.

Contents

[edit] Variations and synonyms

The first letter of a camel-case compound may or may not be capitalized. For clarity, this article calls the two alternatives upper camel case and lower camel case. Some people and organizations use the term camel case only for the latter, and refer to upper camel case as Pascal case.[2][3] In some contexts, however, the term camel case does not discriminate between the two. Other synonyms include:

  • BumpyCaps[4]
  • BumpyCase
  • CamelBack (or camel-back) notation[5]
  • CamelCaps
  • CapitalizedWords or CapWords (for upper camel case) in Python[6]
  • mixedCase (for lower camel case) in Python[6]
  • ClCl (Capital-lower Capital-lower) and sometimes ClC
  • InterCaps or intercapping[7]
  • InternalCapitalization
  • LeadingCaps (implies that the first letter is capitalized)
  • NerdCaps[4]
  • WikiWord or WikiCase (especially in wikis)

The StudlyCaps style is similar (but not necessarily identical) to camel case.[4] It is sometimes used in reference to camel case but can also refer to random mixed capitalisation (as in "MiXeD CaPitALiZaTioN"), popularly used in online culture.

Camel case is also distinct from title case, which is traditionally used for book titles and headlines. Title case capitalizes most of the words yet retains the spaces between the words.[8][9][10]

Camel case is also distinct from Tall Man lettering, which uses capitals to emphasize the differences between similar-looking words.

[edit] History

[edit] Early uses

The advertisement for the 1953 film The Robe debuted CinemaScope, one of the earliest product trademarks to use medial capitals.

Camel case has always been used (albeit sporadically) in English, for example, as a traditional spelling style for certain surnames, such as in Scottish MacLean (originally, "son of Gillean") and Hiberno-Norman FitzGerald ("son of Gerald"). This same convention is sometimes used in English for surnames of foreign origin which include prepositions or other particles, e.g., DuPont (from French Dupont or du Pont), DiCaprio (from Italian Di Caprio), and VanDyke (from Dutch van Dijk). The actress ZaSu Pitts, whose fame peaked in the 1930s and 1940s, sometimes spelled her given name in CamelCase, emphasizing its derivation from two other names.

From the mid-20th century, it has occasionally been used for corporate names and product trademarks, such as

Mixed capitals have also been traditionally used to indicate element boundaries in chemical formulas like NaCl (early 19th century[12]) and other technical codes like HeLa (1983).

[edit] Origins of use in computing

The use of camel case became widespread only in the 1970s and 1980s, when it was adopted as a standard or alternative naming convention for multi-word identifiers in several programming languages. The origin of this convention has not yet been settled.

[edit] Background: multi-word identifiers

Computer programmers often feel the need to write descriptive (hence multi-word) identifiers, like "previous balance" or "end of file", in order to improve the readability of their code. However, most popular programming languages forbid the use of spaces inside identifiers, since they are interpreted as delimiters between tokens. The alternative of writing the words together as in "endoffile" is not satisfactory, since the word boundaries may be quite difficult to discern in the result.

Some early programming languages, notably Lisp (1958) and COBOL (1959), addressed this problem by allowing a hyphen ("-") to be used between words of compound identifiers, as in "END-OF-FILE". However, this solution was not adequate for algebraic-oriented languages such as FORTRAN (1955) and ALGOL (1958), which needed the hyphen as a subtraction operator. (FORTRAN also restricted identifiers to six characters or fewer at the time, preventing multi-word identifiers except those made of very short words.) Since the common punched card character sets of the time had no lower-case letters and no other special character that would be adequate for the purpose, those early languages had to do without multi-word identifiers.

It was only in the late 1960s that the widespread adoption of the ASCII character set made both lower case and the underscore character "_" universally available. Some languages, notably C, promptly adopted underscores as word separators; and underscore-separated compounds like "end_of_file" are still prevalent in C programs and libraries. Yet, some languages and programmers chose to avoid underscores and adopted camel case instead. Two accounts are commonly given for the origin of this convention.

[edit] The "Lazy Programmer" theory

One theory for the origin of the camel case convention holds that C programmers and hackers simply found it more convenient than the standard underscore-based style.

The underscore key is inconveniently placed on QWERTY keyboards. Additionally, in some fonts the underscore character can be confused with a minus sign; it can be overlooked because it falls below the string of characters, or it can be lost entirely when displayed or printed underlined, or when printed on a dot-matrix printer with a defective pin or misaligned ribbon. Moreover, early compilers severely restricted the length of identifiers (e.g., to 8 or 14 letters), or silently truncated all identifiers to that length. Finally, the small size of computer displays available in the 1970s encouraged the use of short identifiers. It was for these reasons, some claim, that many C programmers opted to use camel case instead of underscores, for it yielded legible compound names with fewer keystrokes and fewer characters.

[edit] The "Alto Keyboard" theory

Another account claims that the camel case style first became popular at Xerox PARC around 1978, with the Mesa programming language developed for the Xerox Alto computer. This machine lacked an underscore key, and the hyphen and space characters were not permitted in identifiers, leaving CamelCase as the only viable scheme for readable multiword names. The PARC Mesa Language Manual (1979) included a coding standard with specific rules for Upper- and lowerCamelCase which was strictly followed by the Mesa libraries and the Alto operating system.

The Smalltalk language, which was developed originally on the Alto and became quite popular in the early 1980s, may have been instrumental in spreading the style outside PARC. Camel case was also used by convention for many names in the PostScript page description language (invented by Adobe Systems founder and ex-PARC scientist John Warnock), as well as for the language itself. A further boost was provided by Niklaus Wirth—the inventor of Pascal—who acquired a taste for camel case during a sabbatical at PARC, and used it in Modula, his next programming language.

[edit] Spread to mainstream usage

Whatever its origins within the computing world, camel case spread to a wider audience in the 1980s and 1990s, when the advent of the personal computer exposed hacker culture to the world. Camel case then became fashionable for corporate trade names, first in computer-related fields but later expanding further into the mainstream. Examples ranging from the 1970s to the 2000s give a history of the spread of the usage:


During the dot-com bubble of the late 1990s, the lowercase prefixes "e" (for "electronic") and "i" (for "Internet", "information", or perhaps "intelligent") became quite common, giving rise to some camel case names like iPod and eBox.

In 1998, Dave Yost suggested using camel case for long chemical names such as AmidoPhosphoRibosylTransferase[15]. The city of SeaTac, Washington, incorporated in 1990, is an example of a city officially spelled in camel case.

[edit] History of the name

The original name of the practice, used in media studies, grammars, and the Oxford English Dictionary, was "medial capitals". The fancier names such as "InterCaps", "CamelCase", and variations thereof are relatively recent, and seem more common in computer-related communities.

The earliest known occurrence of the term InterCaps on Usenet is in an April 1990 post to the group alt.folklore.computers by Avi Rappoport,[16] with BiCapitalization appearing slightly later in a 1991 post by Eric S. Raymond to the same group.[17] The earliest use of the name "CamelCase" occurs in 1995, in a post by Newton Love.[18] "With the advent of programming languages having these sorts of constructs, the humpiness of the style made me call it HumpyCase at first, before I settled on CamelCase. I had been calling it CamelCase for years," said Newton, "The citation above was just the first time I had used the name on USENET."[19]

The name CamelCase is not related to the "Camel Book" (Programming Perl), which uses all-lowercase identifiers with underscores in its sample code.

[edit] Current usage in computing

[edit] Programming and coding

The use of medial caps for compound identifiers is recommended by the coding style guidelines of many organizations or software projects. For some languages (such as Mesa, Modula, Java, Python, and Microsoft's .NET) this practice is recommended by the language developers or by authoritative manuals, and has threfore become part of the language's "culture".

Style guidelines often distinguish between upper and lower camel case, typically specifying which variety should be used for specific kinds of entities: variables, record fields, methods, procedures, types, etc. These rules are sometimes supported by static analysis tools that check source code for adherence.

The original Hungarian notation for programming, for example, specifies that a lowercase abbreviation for the "usage type" (not data type) should prefix all variable names, with the remainder of the name in upper camel case; as such it is a form of lower camel case.

Programming identifiers often need to contain acronyms and initialisms which are already in uppr case, such as "old HTML file". By analogy with the title case rules, the natural camel case rendering would have the abbreviation all in upper case, namely "oldHTMLFile". However, this approach is problematic when two acronyms occur together (e.g., "parse DBM XML" would become "parseDBMXML") or when the standard mandates lower camel case but the name begins with an abbreviation (e.g. "SQL server" would become "sQLServer"). For this reason, some programmers prefer to treat abbreviations as if they were lower case words, and write "oldHtmlFile", "parseDbmXml", or "sqlServer".

Camel case is by no means universal in computing. In some programming languages, notably Lisp and Forth, compound names are usually separated by hyphens, which are claimed to be more readable and more convenient to type.[citation needed] Camel case is also inappropriate when the language ignores capitalization in identifiers, as is the case of Common Lisp.

[edit] Wiki link markup

Camel case is used in some wiki markup languages for terms that should be automatically linked to other wiki pages. This convention was originally used in Ward Cunningham's original wiki software, the WikiWikiWeb, and is still used by some other wikis, such as JSPWiki, TiddlyWiki, Trac, and PMWiki. Wikipedia formerly used camel case linking as well, but switched to explicit link markup using square brackets, and many other wiki sites have done the same. Some that default to a different link markup may have an option (sometimes with a plugin) to enable camel case links. Some wikis which do not use camel case linking may still use the camel case as a naming convention, such as AboutUs.

[edit] Other uses

The NIEM registry requires that XML data elements use upper camel case and XML attributes use lower camel case.

Camel case is also the official convention for file names in Java and for the Amiga personal computer.

In some Unix-like operating systems, such as Linux and Solaris, the most popular command-line interfaces and scripting languages canno easily habdle file names that contain embedded spaces. Therefore, users of those systems often resort to camel case (or underscores, hyphens, and other "safe" characters) for compound file names like MyJobResume.pdf.

[edit] Current usage in natural languages

CamelCase has been used in languages other than English for a variety of purposes, including the ones below:

[edit] Orthographic markings

Camel case is sometimes used in the transcription of certain scripts, to differentiate letters or markings. An example is the rendering of Tibetan proper names like rLobsang: the "r" here stands for a prefix glyph in the original script that functions as tone marker rather than a normal letter.

[edit] Inflection prefixes

Camel case may also be used when writing proper names in languages that inflect words by attaching prefixes to them. In some of those languages, the custom is to leave the prefix in lower case, and capitalize the root.

This convention is used in Irish orthography as well as Scots Gaelic orthography; e.g., i nGaillimh ("in Galway"), from Gaillimh ("Galway"); an tAlbanach ("the Scottish person"), from Albanach ("Scottish person"); go hÉireann ("to Ireland"), from Éire ("Ireland).

Several Bantu languages also use this convention, e.g., kiSwahili ("Swahili language" in Swahili) and isiZulu ("Zulu language" in Zulu).

[edit] In abbreviations and acronyms

In French, CamelCase acronyms such as OuLiPo (1960) were favored for a time as alternatives to initialisms.

CamelCase is often used to transliterate initialisms from alphabets where two letters may be required to represent a single character of the original alphabet, e.g., DShK from Cyrillic ДШК.

[edit] Honorifics within compound words

In several languages, including English, pronouns and possessives may be capitalized to indicate respect, e.g., when referring to the reader of a formal letter or to God. In some of those languages, the capitalization is customarily retained even when those words occur within compound words or suffixed to a verb. For example, in Italian one would write porgendoLe distinti saluti ("offering to You respectful salutations") or adorarLo ("adore Him").

[edit] Other uses

In German, all nouns carry a grammatical gender -- which, for roles or job titles, is usually masculine. Since the feminist movement of the 80s, some writers and publishers have been using the feminine title suffixes -in (singular) and -innen (plural) to emphasize the inclusion of females; but written with a capital 'I', to indicate that males are not excluded. Example: LeserInnenbriefe ("letters from [male or] female readers") instead of Leserbriefe ("letters from readers") or Leserinnenbriefe ("letters from female readers").

[edit] See also

[edit] References

  1. ^ http://www.askoxford.com/asktheexperts/faq/aboutwords/medial
  2. ^ Brad Abrams : History around Pascal Casing and Camel Casing
  3. ^ Pascal Case
  4. ^ a b c Brian Hayes, "The Semicolon Wars,"American Scientist Online: The Magazine of Sigma XI, the Scientific Research Society July-August 2006, art. pg. 2.
  5. ^ C# Coding Standards and Guidelines at Purdue University College of Technology
  6. ^ a b Style Guide for Python Code at www.python.org
  7. ^ Iverson, Cheryl, et al (eds) (2007). AMA Manual of Style (10th ed.). Oxford, Oxfordshire: Oxford University Press. ISBN 9780195176339. 
  8. ^ Title Case in PHP at SitePoint Blogs
  9. ^ WordTips: Intelligent Title Case
  10. ^ How to: Change casing in Text to TitleCase - Jan Schreuder on .Net
  11. ^ "MisteRogers" (1962)
  12. ^ Jöns Jacob Berzelius. Essay on the Cause of Chemical Proportions, and on Some Circumstances Relating to Them: Together with a Short and Easy Method of Expressing Them. Annals of Philosophy 2, 443-454 (1813), 3, 51-2, 93-106, 244-255, 353-364 (1814) from Henry M. Leicester & Herbert S. Klickstein, eds., A Source Book in Chemistry, 1400-1900 (Cambridge, MA: Harvard, 1952)
  13. ^ United Healthcare
  14. ^ http://www.pwcglobal.com/images/topnav/pwc.gif
  15. ^ New Scientist ‘Feedback’ Vol 158 No 2139 20 June 1998
  16. ^ http://groups-beta.google.com/group/alt.folklore.computers/msg/21f332e5b813313e
  17. ^ http://groups.google.com/group/misc.misc/msg/f5f25b79cd9026bd
  18. ^ http://groups.google.com/group/comp.os.os2.advocacy/msg/ab3c8107c6e150fa
  19. ^ Newton Love

[edit] External links

Personal tools