Reputation: 409
I have two classes, an appointment class and a calendar class. The calendar class has an array of appointment objects. Should the appointment array name be plural or not? I.e.:
appointment[] appointment;
or
appointment[] appointments;
Is there an agreed syntax for this situation?
Update: Also, do class names start with a lowercase or uppercase letter?
Upvotes: 0
Views: 1415
Reputation: 153909
There are no real universal conventions. If you're working in a team, the team should establish conventions, and everyone should adhere to them. With regards to the conventions: it's important to be able to recognize type names, since you cannot parse C++ without knowing whether a symbol is a type name or not. One frequent convention is to have type names start with an upper case character, and other names (functions, variables, etc.) to start with lower case. It's not universal, however. In theory, at least, it should be clear from the name itself: the usual "rule" is that type names are unqualified nouns, variable names qualified nouns, and functions verbs. In practice, the distinction between qualified and unqualified nouns isn't always that clear, and (in English, at least), it's not always certain whether a word is a verb or a noun. I find it useful to distinguish 1) types from other symbols, and 2) members from non members.
With regards to plurals, it depends. I find that the distinction
between e.g. appointment
and appointments
isn't very visible.
Depending on context, I may feels it's sufficient, and use
appointments
anyway, but in many cases, I'll go a step further, and
call it setOfAppointments
or listOfAppointments
, or something else
which clearly indicates a container. This is, probably, just laziness
on my part; I should really find a better name (a qualified noun,
indicating what kind of appointments: allAppointments
, if nothing
else).
Upvotes: 1
Reputation: 64223
Should the appointment array name be plural or not?
Yes, off course. Because it contains multiple appointments.
Is there an agreed syntax for this situation?
That depends on the coding conventions within your organization, team or department. How you are going to name variables, classes, etc depends on this.
Upvotes: 1
Reputation: 81
There is no particular convention.
I will suggest HUNGARIAN notation.
please read following article: http://msdn.microsoft.com/en-us/library/aa260976%28v=vs.60%29.aspx
This will give you good idea what to do.
Upvotes: 0
Reputation: 106096
There is no convention, but you'll need to use distinct names for the type identifier and variable identifier. I tend to capitalise type but not variable identifiers, but it's a matter of personal taste. In this specific case of member data, a prefix or suffix also serves.
Also personal taste, I do tend to use the plural for a container, and have a suspicion it's more common. But, countering that, I've often thought it makes sense when talking about the entire container, while from an English reading perspective "appointment[3]" as "appointment three" reads better than "appointments three".
Upvotes: 2
Reputation: 227400
There is no agreed naming convention, but I would make two suggestions:
std::vector<appointment>
appointments_
or m_appointments
Personally, I find the plural form more intuitive when referring to a collection.
Upvotes: 1