views:

118

answers:

7

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.

+5  A: 

current_user seems the obvious choice.

JoeC
Yes, or some variation that includes the words "current" and "user".
Ed Guiness
I like that. I'd prefer a one word name though if a good one word name exists.
Emanuil
@Emanuil Operator
Mike
If your system is tiny one word might be appropriate, otherwise a two-part name like currentUser is perfectly acceptable, and quite common. If you go with a single word let's say "user" then you'll need to rename when you find a need to know who was previously logged in i.e. "previousUser". I'm sure you can think of other examples.
Ed Guiness
Mike, are you suggesting the word "operator"? I don't understand.
Emanuil
@Emanuil Yes I did
Mike
Thanks, Ed! I appreciate your thoughts on the subject!
Emanuil
Actually, Mike, I think I like it.
Emanuil
All the one-word variable names, except `user` seem too contrived to me. Operator sounds like you're running a telephone switchboard, not a program. A variable name should be clear about what it's storing.
JoeC
+1  A: 

loggedOnUser seems appropriate.

David Neale
+2  A: 

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

  • accurate (not sloppily named)
  • concise (short as possible, without losing meaning)
  • unambiguous (not easily confused for something else)

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.

Ed Guiness
+1 - I go with `activeUser` for the actual name and `activeUserId` for the unique ID in the dbase.
Andrew Heath
+2  A: 

Either theUserWhoLoggedInAFewMinutesBeforeAndWhoHasNotYetLoggedOutAgain or just ich

Ingo
+1 Funny! Hahaha
Adirael
+1  A: 

currentUser OR loggedInUser seems better i think.

thanks.

Paarth
+2  A: 

authenticatedUser, validUser, activeUser, authUser

Don
+2  A: 

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.

Craig T