Terminology request: instances of structs vs instances of enums

Are there established terms that distinguish instances of structs (or enums, for that matter) vs instances of classes? If so, are they documented anywhere? It's not in the lexicon.

Is "object" a catch-all term for an instance of any kind of type, or only instances of classes?

1 Like

I tend to call them "values" (instances of enums/structs) vs "objects" (instances of classes) but not sure if this is established terminology.

As a side note, what I found really confusing is the term "class variable", as some people use it to denote "instance variables" and others - "class (static) variables". Python makes the situation doubly confusing with its unique dual "instance/static" variable allocation.

1 Like

I would say that's just simply incorrect. Better terms would be instance properties or fields.

Python makes the situation doubly confusing with its unique dual "instance/static" variable allocation.

Heh, Ruby has class variables (@@x), but its classes are objects (instances of Class), which can themselves have instance variables (@x). So you have class variables, and instance variables on classes :smiley:

My take on this is that types (all types, whether reference or value types in the Swift sense) have instances, and instances contain values.

We can only tell instances (of a particular type) apart when they are at different locations (at different "memory addresses", when that concept applies): this instance over here; that instance over there.

Values don't have a location — they are abstract representations which can be read from or written to a location.

So, for example, different Int variables are different instances of the Int type. The value of an Int variable is a bit pattern, which is how different instances can have the same value.

As for the value type vs. reference type distinction, I think all the above applies, but we just don't have a common use for "value" in regard to class instances, and we don't have a common use for "instance" in regard to enum and struct types.

Finally, when we say something like "2 is a value of type Int", I think we mean that 2 is a value having type Int. The "of" shouldn't be taken too literally.


From The Swift Programming Language:

An instance of a class is traditionally known as an object. However, Swift structures and classes are much closer in functionality than in other languages, and much of this chapter describes functionality that applies to instances of either a class or a structure type. Because of this, the more general term instance is used.

If you want a term for an instance of a structure or enumeration, you could say "instance of a value type".


It should also be noted that "object" is used by libraries to refer to instances of classes — AnyObject, ObservableObject, StateObject, ObservedObject, EnvironmentObject

1 Like

This is my vocabulary, with the added wrinkle that the value of a variable of class type is a reference to an object.

1 Like

The term "value" is used officially, more often over time, to mean "instance". E.g.

AsyncPublisher.values (which could have been e.g. "outputSequence"), and