-
Notifications
You must be signed in to change notification settings - Fork 3
Acronyms Capitalization
Pablo Villar edited this page Mar 20, 2017
·
3 revisions
Acronyms must be capitalized such that all of its characters are uppercase, unless the acronym goes at the beginning of a name, in which case, to preserve the variables capitalization rule, all of its characters will be lowercased.
Be aware of words that aren't acronyms (and do not follow this rule), for instance:
- Apocopes, such as id, which is an abbreviation for identifier.
- Words that have been originated as acronyms, but are considered words in dictionaries nowadays, for instance: laser.
Examples of words that are acronyms are:
- URL, HTTP, SATA, USB, REST, CRUD, etc.
Good
func pathForURL(url: NSURL) -> String
// First 'URL' appearance goes UPPERCASE.
// Second appearance goes lowercase, since it's at the beggining of a non-static constant name.
func urlForPath(path: String) -> NSURL
// 'URL' goes at the beggining of the function name, use lowercase.
let urlForConnections: NSURL
// 'URL' goes at the beggining of a non-static constant name, use lowercase.
let baseURL: NSURL
// 'URL' isn't at the beggining of a non-static constant name, use UPPERCASE.
static let URL = NSURL(string: "http://www.google.com/")
// Particular scenario: URL can go all UPPERCASE in this case because it's about a static constant, which should start with Uppercase.
Bad
func pathForUrl(URL: NSURL) -> String
// First appearance: Wrong. You should never see such camel case scenario ('Url').
// Second appearance: Wrong. Constants should start with Uppercase only if they are static.
func URLForPath(path: String) -> NSURL
// 'URL' goes at the beggining of a function name, it should go lowercase.
let URLForConnections: NSURL
// 'URL' goes at the beggining of a non-static constant name, it should go lowercase.
let baseUrl: NSURL
// Wrong. You should never see such camel case scenario ('Url').
- Consistency.