Plural naming convention for composite objects
Asked Answered
R

1

9

The question is about the correct way to name variable or identifiers that groups collections of two or more "things". Let me explain a little further with example and question...

  • If you something that holds an id you may name it with the identifier "id"
  • If you got somethign that holds an appoinment you may name it "appointment" as identifier
  • If you got multiples ids (for example, an array) you may name it "ids"
  • If you got multiples appointments under an array you may name it "appointments"
  • If you got multiples appointments' ids, how may i name it?
    • appointmentIds?
    • appointmentsIds?

I'm not an english native speaker.

Rubio answered 14/4, 2020 at 15:18 Comment(1)
i try to attach to one of 2 and be consistent across the source files (regardless in correctness in grammar sense).. but sometimes my mind autoswitch for one convention to other... and is not only me, often in the projects there are several with the same " issue".. so... any recommendation would be appreaciated.Rubio
S
8

In your example you'd name it "appointmentIds", as it's multiple Ids for your appointment type i.e. Ids for many different appointments.

"appointmentsIds" would imply the relationship between an appointment and its Ids i.e. the appointment (singular) has many different Ids, which from your example is not likely! I'd suggest reading up on nouns and the possesive (I appreciate English is not your first language, English is hard!)

Slighting answered 14/4, 2020 at 21:54 Comment(3)
"appointmentIds" would be then; and is much way better than "idsFromDistinctsAppointments" :D, i have to study further... thanks!!Rubio
@Ben Smith, how should you name it, if there is a list of appointmentId? List<AppointmentId> ???. will be appointmentsIds?Caneghem
even if the relation between appointments and ids would be m-n and one appointment would have multiple ids, you should not name your variable "appointmentsIds" because it is not grammatically correct and harder to read. Check this related topic: #2773981Primrose

© 2022 - 2024 — McMap. All rights reserved.