views:

274

answers:

12

When I'm programming, I often find myself writing functions that -should- (to be proper english) contain apostrophes (too bad C started everyone thinking that an apostrophe was an appropriate delimiter). For example: get_user's_group() -> get_users_group() . What do you guys do with that forced-bad-english ambiguous english? Just ignore the apostrophe? Create a different phrasing?

+2  A: 

How about getGroupByUser?

Gumbo
or GetGroupForUser
MikeW
+3  A: 

Ingore it, move on!

Although get_user_group() would work in this care also.

Adrian Lynch
+9  A: 

In that case, I would do get_group_for_user().

So, yes, I would "create a different phrasing" :)

Either that, or user.get_group().

Sapph
+1 user.getGroup() exactly means get user's group.
JCasso
? Sorry, I don't even understand that `.` syntax. What is user in the statement `user.get_group()` ?
Tchalvak
Ah, I was thinking in php, I guess that'd be a javascript syntax. My bad.
Tchalvak
+3  A: 

Either get_user_ApostropheShouldBeHereButLanguageWillNotLetMe_s_group or just ignore it because it really doesn't matter.

Jason
It does matter for someone else reading the code as get_users_group can mean (at least) two different things.
Tatu Ulmanen
If you have proper documentation, I don't think it would be a big deal.
David Brown
It matters, but not enough to dwell on. A simple rephrasing is all that's required.
keyboardP
Right, that's also a big part of the problem, is that, trying for an example, get_dogs_group (a group for dogs, perhaps?) is very different from get_dog's_group -> get_dogs_group (the group that a single dog is in). So the wording often becomes somewhat imprecise in the absence of apostrophes, unfortunately.
Tchalvak
@Tatu Ulmanen: Ugh, no. There are many words that have multiple meanings even in a programming context (think, for example, of `static` in C++ which I think has four different meanings). But this rarely matters because of context. If there are multiple possible meanings of `get_users_group` in the same context then yes, rename. Otherwise, don't worry about it and just move on.
Jason
Well, hard to be self-documenting when the function names get ambiguous. I'm not sure that context applies to functions very well? If you have a completely unattached lib file with a single function in it, there's little context until you get specific and comment/make the context. *shrugs*
Tchalvak
+6  A: 
getGroupForUser() 

or

getGroupByUser()
Fabiano
I guess those are votes for rephrasing.
Tchalvak
A: 

Normally I just drop the apostrophe, but do back-ticks work? (get_user`s_group)

Wallacoloo
+1  A: 

I ignore the apostraphe getGroupyUser and group_from_user are both perfectly understandable. Worrying about having correct grammer in your function names is a waste of time and distracts from the correct goal of having clear and understandable user names.

RHicke
A: 

getGroupOfUser? getUserGroup?

It's a programming language, not literature...

It would be getBackgroundColour in proper English (rather than getBackgroundColor)

gbn
A: 

the point of proper english in function naming is a bit extreme ...

i mean why is the apostrophe bothering you but the _ instead of a space is not ?

Gaby
Because no-one ever uses _ in normal writing/speech. Apostrophes, on the other hand, are pretty basic.
Tchalvak
that was not my point ... i meant why is it ok to replace spaces and not apostrophes.. if the issues is what char to use you could replace apostropes as well with _
Gaby
Fair enough. I guess it's that _ is a efficient replacement for space, whereas apostrophe has no useful replacement that I could think of. *shrugs*
Tchalvak
+1  A: 

Depending on the programming language you may be able to use Unicode variable names, this SO thread lists a few.

With Unicode identifiers you could use one of the unicode apostrophes to give the proper english language formatting to your variable name. Though this only speculative. And it would be hard to maintain. Actually, now that I think about it, it sounds downright evil.

pygorex1
You can even add unicode spaces into a function name.
Andrew Grimm
Now that's pure evil
pygorex1
i would like to see someone trying to invoke those functions .. lol
Gaby
Surprised this hasn't been downvoted into oblivion. :)
Jason Orendorff
A: 

Personally I'd write get_user_group() rather than get_group_for_user() since it feels like it reads better to me. Of course, I use a programming language where apostrophes are allowed in names:

proc get_user's_group {id} {#...}

Although, some of the more prolific non-English-native European users use it as a word separator:

proc user'group {id} {#...}

to each his own I guess..

slebetman
A: 

Two points: First, don't use a name that would otherwise require an apostrophe if you can avoid it. Second, you are right in being concerned about ambiguity. For example, you could have:

  • getUsersGroup: gets the group of a list of users. If you are using an object-oriented language, this could have more information than just a group ID string. You could also have something like createUsersGroup, which would create a group object from a list of users passed in.
  • getGroupOfUser: takes in some sort of user object; returns the name of the group of the user
  • getGroupByUserId: takes in the user's name or a unique ID associated with that user; returns the name of the group of the user

The best way to delineate the difference between all of these is to just use standard method comments that explain the method names. This would depend on what language you are working with and what style of method comments your organization conventionally uses.

David