Singular or plural? That is the question.

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Singular or plural? That is the question.

Post by Chris »

I did an internship a while back at a software company that specializes in Microsoft XRM.

While I was there a colleague of mine taught me to only ever talk in singular form, the reason being that at the end of the day one piece of data will always be in its own right unique.

When I program, I have a tendency to stick to the rule he taught me, and I have to admit it definitely makes perfect logical sense. What I personally hate is people pluralizing the name of a function or variable.

So here's the main goal:
  • It's not the "users" table, it's the "user" table, why?
    • The row data will always equal one user, so call the table "user". It is the user structure.
    • When you want to relate to the table, "users_id" won't make sense unless you meant "user's_id" or "id_of_user", it should be "user_id"
    • Why call it the users object? It's the user object.
  • It's not the "getUsers()" function, it's the "getUserList()" function. Why?
    • It's not the Users object, it's the User object, you want a list of them.
    • A list is a singular form of data containing more singular forms of data.
    • Pluralizing the name of the forms of data restricts the amount of variability of the word list. It's the form of data that is variable, not a list.
  • It's not $users, it's $userList. Why?
    • The object is not called Users, it's the User object, and you are storing more than one of them.
    • It's not the $buckets, it's the $bucketList.
What is your opinion list on this? :D
Fighting for peace is declaring war on war. If you want peace be peaceful.
Sim
Posts: 410
Joined: Sat Dec 26, 2009 5:37 pm

Re: Singular or plural? That is the question.

Post by Sim »

I think I follow that. Now, does that same rule follow for naming of database tables, you think?

For example: you could have a "user" table, but if it had a prefix , wouldn't it be "game_users" ?
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Singular or plural? That is the question.

Post by Chris »

No, it would be "game_user", unless you mean "user_of_game" or "game's_user" (which is not possible), if you are making a many to many relationship with that table, it will be "game_has_user".
Fighting for peace is declaring war on war. If you want peace be peaceful.
Sim
Posts: 410
Joined: Sat Dec 26, 2009 5:37 pm

Re: Singular or plural? That is the question.

Post by Sim »

Seems right. I got a fix of table names, but for my field names, they seem good.

For example: I got 'game_users' for table name then fields like "userID' , userHandle, not usersID, usersHandle.

Makes sense like your saying. Its just proper English.
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Singular or plural? That is the question.

Post by Chris »

What database are you using Sim?
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Singular or plural? That is the question.

Post by Jackolantern »

I mostly tend to follow that, except in a few places where it is .NET convention to pluralize, such as with database contexts and Entity Framework Code First object collections. For example, sometimes you have:

Code: Select all

public List<Employee> Employees;
But that is because it is actually a collection of Employees.
The indelible lord of tl;dr
Sim
Posts: 410
Joined: Sat Dec 26, 2009 5:37 pm

Re: Singular or plural? That is the question.

Post by Sim »

Chris wrote:What database are you using Sim?

Custom one.
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Singular or plural? That is the question.

Post by Chris »

Jackolantern wrote:I mostly tend to follow that, except in a few places where it is .NET convention to pluralize, such as with database contexts and Entity Framework Code First object collections. For example, sometimes you have:

Code: Select all

public List<Employee> Employees;
But that is because it is actually a collection of Employees.
I was taught to call the variable in this case EmployeeList:

Code: Select all

public List<Employee> EmployeeList;
Sim wrote:
Chris wrote:What database are you using Sim?

Custom one.
Maybe I should have been more specific :P, what RDBMS are you using?
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Singular or plural? That is the question.

Post by Jackolantern »

Chris wrote:I was taught to call the variable in this case EmployeeList:

Code: Select all

public List<Employee> EmployeeList;
You could, but then you are going against Microsoft best practice.
The indelible lord of tl;dr
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Re: Singular or plural? That is the question.

Post by Verahta »

Hmm, seems there is a conundrum here! One guy says Microsoft says Employees and the other says Microsoft says EmployeeList... Thus, only fair and balanced way to solve this is for Jack and Chris to cage fight in the Thunderdome. 8-)

Image
"In order to understand recursion, one must first understand recursion".
Post Reply

Return to “Coding”