In other words - what would be a good name for a variable that references the currently logged user?
I've come up with a few:
- logged_user
- visitor
- me
I'm not convinced either of them is good enough though.
In other words - what would be a good name for a variable that references the currently logged user?
I've come up with a few:
I'm not convinced either of them is good enough though.
The underlying point is worth some elaboration.
It is very important to choose good variable names, where a "good name" has the properties of being
If you are stuck then try to describe the thing in plain English.
Do you want to store the name of the user who is currently logged in? How about currentlyLoggedInUser?
In your context do you care about users not logged in?
If not then currentUser would do fine, and it's more concise.
Can it be confused for something else?
Nope. We have a winner!
Now you could shorten it further, like currUser but you lose some of the clarity. Remember the IDE will be there to help you type, so you have to think what you're losing (clarity) as a trade off from what you gain (fewer keystrokes). That point can be settled by personal taste when you're developing by and for yourself, but if you're in a team it's a no-brainer; choose the version that will be easiest to understand in future.
Think of that axe-wielding maniac who has to maintain your code in five years time.
Either theUserWhoLoggedInAFewMinutesBeforeAndWhoHasNotYetLoggedOutAgain
or just ich
I would be more inclined to go with the simplest form user
. If you need to identify a previously logged on user then previousUser
is a logical choice. Also, if you need to distinguish between a user that is logged in or not then a simple isUserLoggedIn
boolean will do the trick.