27

Why is the Objective-C object type called 'id'? As opposed to, say, 'object'?

5 Answers 5

48

It is called id because that, literally, is all the type represents - an identifier.

Quoting Brad Cox from Object Oriented Programming: an Evolutionary Approach (actually, the first edition, one of the first OO books I bought): An id consumes a fixed amount of space, wide enough to identify as many objects as may exist at any one time. This space is not the same as the space occupied by the private data in the object itself. Object identifiers are fixed-sized numbers,...

0
8

I guess the other possibility not mentioned here would be that the Objective-C folks were Latin buffs and based it off the singular nominative/accusative (subject/object) forms of the Latin pronoun id (meaning "it"). It is sort of a generic word directed at a specific object, and id is a pointer to a generic object, so, you never know:).

0
2

Maybe it's the id of the class system (as in Freud's id/ego/superego) - that would make a bit of sense given the id is the basal nature of an organism. Not that I believe any of that Freud rubbish anyway :-).

Or, maybe the developers of Obj-C came from the UNIX school of namers (with "ls" or "cd") rather than the VAX school (with its "show directory" and "set directory").

Or, it could stand for instance data, which is probably more likely.

1
  • 1
    The idea that it's a reference to the id would fit with the copious references to self.
    – Tommy
    Commented Aug 27, 2015 at 13:18
2

Theory without proof :

How about 'identity' because it is a pointer to any unique object.

0
0

As Ryan notes, it is actually a pointer: IIRC it is NSObject *.

As for the naming - maybe the namer uses a Dvorak key-layout. 'id' is really easy to type in that case (it's like typing 'gh' on Qwerty).

3
  • 1
    It is a pointer, but it's a pointer to an object of type struct objc_object, not a pointer to NSObject.
    – mipadi
    Commented Jan 30, 2009 at 2:25
  • 3
    Cocoa has other root classes besides NSObject; id could reference NSProxy, for instance. Commented Jan 30, 2009 at 4:20
  • id is not an NSObject*. An interesting comment thread in question 4150054 on this subject disappeared when the question it was attached to got sent to the bit bucket. Commented Nov 12, 2010 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.