Swift-style-guide: ID vs Id vs Identifier

Created on 7 Jan 2016  路  6Comments  路  Source: raywenderlich/swift-style-guide

Examples:

var userID
var userId
var userIdentifier

I struggle with this about once per project and I don't see many discussions on it.

I think it's _always_ a special case and as long as it's consistent within a project I try not to think about it too much.

However, would love to hear how others think and if there's _any_ logical advantage to any one of these options over the others.

Most helpful comment

Apple does use the "Identifier" suffix ex reuseIdentifier, eventIdentifier and when abbreviating Apple uses the uppercase "ID", for example NSManagedObject has an objectID, CKNotification has a notificationID and subscriptionID, CKRecord has a createrUserRecordID etc.

All 6 comments

Apple appears to be favoring the identifier suffix, over the prior ID suffix.

Personally, I'm not a fan of the Id suffix.

I used to use camel case for abbreviations, so Id works for me. but if it's in the end of the name of a variable then ID is more readable i think

Apple does use the "Identifier" suffix ex reuseIdentifier, eventIdentifier and when abbreviating Apple uses the uppercase "ID", for example NSManagedObject has an objectID, CKNotification has a notificationID and subscriptionID, CKRecord has a createrUserRecordID etc.

I tend to stick with what @jawwad posted.

@jawwad is correct. userID (The Dropbox SDK gets it wrong. :] )

Generally acronyms should be avoided but, The Apple API Design Guide says:

Acronyms and initialisms that commonly appear as all upper case in American English should be uniformly up- or down-cased according to case conventions:

var utf8Bytes: [UTF8.CodeUnit]
var isRepresentableAsASCII = true
var userSMTPServer: SecureSMTPServer

Will include mention under naming.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

WingYn picture WingYn  路  15Comments

rayfix picture rayfix  路  3Comments

rayfix picture rayfix  路  3Comments

hollance picture hollance  路  28Comments

xezun picture xezun  路  6Comments