0

Suppose I have a class called Person with a property for their name.

Is it bad practice to name that property "personName"? Wouldn't just "name" suffice since "person" is implied already?

Then you end up with syntax like: person.personName, which looks silly and redundant

cas5nq
  • 413
  • 5
  • 11

2 Answers2

1

IMHO it is redundant, and I only do that if a second name (in this case) would be needed so that anyone could know the difference.

Luis Font
  • 70
  • 4
  • What if Person has two properties: name and companyName, the latter of which is derived from a foreign key relation to a Company table. In this case would it appropriate to leave the person's own name as just "name" rather than being redundant, since Person is the implied context unless otherwise stated? This is how I think intuitively. – cas5nq Aug 22 '14 at 20:37
0

Be verbose enough to be clear, but extra words that add no information are just noise and make code harder to read and understand. In this case, any reference to a Person carries the type information and (we hope) a label indicating the variable's role. Adding the class name to the field name contributes nothing, and it should be omitted.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152