Using correct terminology: What is a "class reference" versus a "class variable"?

Viewed 120

In an effort to ensure the use of proper terminology when describing certain aspects of code, I'm asking for clarification of use in the following context:

If we write

int myIntTest;

we say "We have an int variable"

Assume that we have an Employee class, and when we write

Employee myObjectTest;

we say "We have a reference for an Employee object"

My question is:

Is it corret to say "myObjectTest is a Employee class' variable"?

3 Answers

I usually say "myObjectTest is a variable of type Employee" or if I want to be very specific "myObjectTest is a variable referencing an Employee instance (or null)".

I'm not sure if there's one definitive answer. Maybe somebody knows and can point you to the correct section of the specification :)

Here's what I found:

Types

Value types differ from reference types in that variables of the value types directly contain their data, whereas variables of the reference types store references to their data, the latter being known as objects.

and

Variables

Variables represent storage locations. Every variable has a type that determines what values can be stored in the variable.

So it seems like that the C# spec talks about a variable having a type. Thus, "myObjectTest is a variable of type Employee" matches the spec's language.

For the variable itself I would say it's "A variable of type Employee":

//"variable of type Employee" or
//"employee variable"
Employee e;

If an instance of the Employee class has been assigned to it I would probably say it's "an Employee instance":

//"employee instance e"
e = new Employee("John", "Smith", "Manager");

In general conversation terms between e.g. two developers you'll tend to find that the variable, as a placeholder, typically fades in importance compared to the data it holds. You might talk about variables employeeA and employeeB but what you'll actually be talking about are the Employee instances assigned to those variables - "why do employeeA and employeeB have the same name and role? Hmmm. Oh look, they're pointing to the same instance"

If you're saying something is a class variable it's a bit vague, but would probably be interpreted as "a class wide variable" - a variable that is a data member of the class. It may be best to avoid the phrase and instead use the same terms that the documentation uses for those (fields, properties, methods, constructors etc are all class members). If you're determined to use "variable" don't mention "class" - just say "Employee variable" as in "the constructor uses two Employee variables". If you're talking about variables in the specification of a method, call them parameters or arguments or say that the method "takes (class name)" - "the constructor has two Employee arguments" or "this method takes an array of Employees"

As stated, no - myObjectTest represents a variable intended to hold a reference to an instance of Employee. To say "Employee class' variable" implies a variable that belongs to the Employee class, not one that represents an instance of the class.

Related