Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper terminology for each type of an identifier?

Take the following code:

IFoo foo = new FooImplementation();

The identifier foo has two types:

  1. IFoo - This is the type the compiler will enforce. I will only be able to call methods that are part of the IFoo contract, otherwise I'll get a compiler error.
  2. FooImplementation - This is the type as known by the runtime. I can downcast foo to a FooImplementation at runtime, and then call non-IFoo methods of FooImplementation.

My question: What is the proper terminology for these two types. I could swear in school we were taught that IFoo is the identifier's static type and FooImplementation is its dynamic type, but after much searching on Google I can't seem to find any reference to this.

like image 562
Mike Christensen Avatar asked Jan 28 '13 23:01

Mike Christensen


People also ask

Which are the correct term used in identifier syntax?

Rules for naming identifiers A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores. The first letter of an identifier should be either a letter or an underscore. You cannot use keywords like int , while etc. as identifiers.

What do you call the identifier?

An identifier is a name that identifies (that is, labels the identity of) either a unique object or a unique class of objects, where the "object" or class may be an idea, physical countable object (or class thereof), or physical noncountable substance (or class thereof).


3 Answers

I would call IFoo and FooImplementation the compile-time and run-time types, respectively. This language is used by C# spec, for example, when talking about virtual methods (section 1.6.6.4):

When a virtual method is invoked, the run-time type of the instance for which that invocation takes place determines the actual method implementation to invoke. In a nonvirtual method invocation, the compile-time type of the instance is the determining factor.

like image 88
Mike Zboray Avatar answered Oct 19 '22 06:10

Mike Zboray


I agree with Mike Z. The usual terminology in C# is "compile time type" and "runtime type".

"Static type" and "dynamic type" are entirely reasonable terms but I would avoid them in the context of C#. "Static type" could too easily be confused with "static class", a class which can only contain static methods. And "dynamic type" can too easily be confused with the dynamic type feature added to C# 4.

like image 29
Eric Lippert Avatar answered Oct 19 '22 06:10

Eric Lippert


The first is the Declared Type. The second is the Concrete Type.

...at least that's what I call them.

like image 43
Justin Niessner Avatar answered Oct 19 '22 05:10

Justin Niessner