An object is an instance (or not)?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Jan 28 04:09:35 EST 2015
Ben Finney wrote:
> Ned Batchelder <ned at nedbatchelder.com> writes:
>
>> On 1/27/15 3:12 PM, Mario Figueiredo wrote:
>> > This is a follow up from a previous discussion in which it is argued
>> > that the following code produces the correct error message terminology,
>> > considering that in Python an object is also an instance.
>>
>> I don't know what the difference is between "object" and "instance".
>> An object is an instance of a class. The two words are
>> interchangeable as far as I know.
>
> Not in English grammar, IMO. To say “foo is an instance” implies the
> sentence isn't finished; the term “instance” only makes sense in the
> context of a relationship to some class. To say “foo is an object”
> doesn't have that implication.
I'm sure that there is a grammatical term for this, but I don't know it.
Regardless of the terminology though, "foo is an instance" is a complete
sentence fragment:
"foo is an instance" (of some unspecified class)
is the same grammatical construct as:
"George is a soldier" (of some unspecified army)
"Pluto is a cartoon animal" (of some unspecified species)
"Bearhugger's Old Peculiar is a drink" (of some unspecified type)
"Herbie is a car" (of some unspecified make and model)
etc. In Java, the term "object" as a synonym for "instance" is unambiguous,
because in Java all classes are subclasses of Object, and no classes are
themselves instances of a class. But that's not the case with Python.
>> A common mistake is to believe that "OOP" is a well-defined term.
>> It's not it's a collection of ideas that are expressed slightly
>> differently in each language.
>
> Right. The common meaning of “object” shared by all OOP systems is
> surprisingly small.
Agreed. There really is no widespread agreement on what OOP means
*precisely*. Wikipedia states:
"Attempts to find a consensus definition or theory behind objects have not
proven very successful" and there is little agreement of the fundamental
features of OOP:
http://en.wikipedia.org/wiki/Object-
oriented_programming#Fundamental_features_and_concepts
[...]
> In Python, every class is an object. Every class has the full range of
> behaviour that we expect of objects. A class just has the additional
> feature that it can be instantiated.
We can also define an "is-a" relationship between classes and their
instances:
[1, 2, "spam"] is-a list;
but not list is-a [1, 2, "spam"]
However, in Python that breaks down at the very bottom of the inheritance
hierarchy, thanks to the circular relationship between type and object:
py> isinstance(type, object)
True
py> isinstance(object, type)
True
type is-a object
object is-a type
--
Steve
More information about the Python-list
mailing list