Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm working on a site with a lot of interaction between Users. So I've named the model class User. When I refer to a page of a specific user, I have variables like user, userPoints and userUrl. When a specific user is member of a group I have a simple variable called groupMember - so just plain, no prefix or whatever.

Of course I also need to refer to the currently logged in user. Right now I refer to that one with variables like currentUser, currentUserUrl and currentGroupMember if the user is part of a group.

It works a bit, but I'm not really that satisfied. It not always reads very well, especially stuff like currentGroupMember is relatively confusing.

Because I work a lot with these objects, I'm looking for names that are short to keep stuff as readable as possible.

What are the most common patterns for differentiating between a user and the currently logged-in user?

share|improve this question

closed as primarily opinion-based by MichaelT, gnat, GlenH7, Bart van Ingen Schenau, Kilian Foth Apr 25 at 11:38

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

Do you think Member is-a User? Should you subclass? –  Davin Tryon Dec 23 '13 at 8:46
In my domain code a User can be a Member of multiple Groups. So a user has a list of memberships and every Member of a group has a reference to the corresponding User. –  Dirk Boer Dec 23 '13 at 9:09
How many groups you have? If many can a user be in more than 1 group?. I guess we can fix this. –  Charan Giri Dec 23 '13 at 9:46
What contains groupMember and currentGroupMember variables ? An array of the groups the user (or current user) is member of ? –  OlivierH Dec 23 '13 at 14:11

1 Answer 1

up vote 4 down vote accepted

It might help to look at it the other way around. Instead of trying to come up with a better name for the logged in user, try to come up with better names for the other users, according to their role in the current context.

Not knowing precisely what your site does, I will try to generalize. For example, on programmers.se, I would refer to other users as authors, commenters, voters, etc. On facebook, I would refer to other users as friends. Their data type can still be User, just the variable names change.

Also, it often helps to use objects to your advantage. Instead of userPoints, try user.points. Instead of currentGroupMember, try user.isInGroup(group) or group.containsUser(user). This also makes it easier to do things like put a bunch of users in an array and call user[i].points, or in a hash table and call user["logged in"].points.

share|improve this answer
Still 'users' really covers the users the best at this project (as they are quite generic - just like most social playform). Have to think hard! –  Dirk Boer Dec 24 '13 at 14:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.