While trying to cleanup an application's API, I found myself scratching my head...
What should I call the variable for a user's name "username", or "userName"?
While trying to cleanup an application's API, I found myself scratching my head...
What should I call the variable for a user's name "username", or "userName"?
I vote for "username" (one word).
"User name" (as two words) could easily mean "The user's real world name", whereas "username" (one word) has a specific meaning in many contexts (an operating system username, for instance).
My name is Richie Hindle, but my username is RichieHindle
.
FxCop, IIRC, will tell you to call it UserName or userName (depending on context) by default.
So that could be your deciding factor.
I generally have always used the term in regards to a user login as "Username" (as a variable - "username"). However, if I'm talking about a user's name, then it's "userName".
I think the general convention is to use "username" as one word.
As two words are combined, "user" and "name", for me it is "userName". Also I always use "userName" because FxCop tells me to.
'username' should be the name they log in with. 'userName' should be their actual name.
My username is 'akway' here, while my name is 'Austin Way', for example.
Important Edit: You should not have username and userName anywhere near each other.
I personally prefer loginName (or, perhaps, userID, although some people might interpret this to be a number) because of the confusion over what a "username" might be.
It depends...
userName - for Windows/Java fanatics.
user_name - for C/UNIX/Linux fans.
user-name - for some old languages and database programmers (Progress, Cobol, ...).
username - for all others.
:)
Use username
to refer to the unique identifier by which the user is known to the system. If you want to use userName
, I say go ahead, so long as you are consistent.
The distinction between this identifier and the user's real life details should not rest on the capitalization of a single letter.
Those variables can be stored in a User
class (or equivalent) and should be named to reflect the information they hold. E.g. User.fullname
or User.lastname
. As before, if you want to call these User.fullName
or User.lastName
, again, go ahead, but be consistent.
referer
anyone? The world did not end when that was misspelled.
I've always found camel-casing a distraction. I think it is over hyped. What I find really useful is to structure code, such that general boundaries around flow conditions are more visible (eg. all LHS and RHS of an assignment align, contents of if block are of mostly same length lines, etc..) If all other variables are camel-cased, use it for userName as well.