Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isMemberOfClass Terminology - Why is it named the way it is?

I should preface this with saying I come from a Java/Android background which has colored my understanding of the word "member". That said, I'm starting to learn Objective-C and I ran across the isMemberOfClass method and the name confuses me.

I understand that isMemberOfClass returns a Boolean value that indicates whether the receiver is an instance of a given class. However, I don't understand why it is called isMEMBER when it checks if it is an INSTANCE.

Is there something about the language protocol that I don't know that would make sense to name it this? Does member mean something different in Objective-C than it does in Java?

The way I understand the definition of member, it is something a class HAS (method or data), rather than something a class IS (a type).

Can anyone clear this seemingly odd naming convention up for me? Thanks for helping a newbie!

like image 749
foshoshin Avatar asked Dec 26 '22 20:12

foshoshin


2 Answers

The key note here is that Cocoa (and SmallTalk before it), does not use the word "member" to mean "instance variable" or "function of" or any of the other ways that the word "member" is used in Java or C++. There's a useful paper on SmallTalk from Harry H. Porter III that gives some context:

As mentioned earlier, each object contains zero or more fields. The term "field" is preferable, but other languages use the term "data member" for the same concept. Smalltalk uses the term "instance variable" to mean a field, so we say, "An object contains several instance variables" to mean the same thing as "An object contains several fields" or "An object contains several data members." We will use the terms "field" and "instance variable" interchangeably.

...

In Java or C++, the programmer may add "static data members" and "static member functions" to any class. Smalltalk has a similar ability, although static data members are called "class variables" and static member functions are called "class methods". (Recall that Smalltalk calls normal fields "instance variables" and it calls normal member functions "instance methods".)

In Cocoa, the term "member" is typically used in the context of a collection (see [NSSet member:]). The question being asked by isMemberOfClass: is "is this object a member of the set of all instances of this specific class."

That's not to say isInstanceOfClass: would have been an un-Cocoa-like name. It's just that "member" doesn't have the same meaning here as in some other languages.

like image 189
Rob Napier Avatar answered Mar 15 '23 04:03

Rob Napier


The concept of a member as a component of a class (method or data) does not exist in the iOS framework. The framework is also built around verbose and often lengthly method or variable names to promote "added readability" (in quotes because it isn't always necessarily the result).

It easily could be named isInstanceOfClass, but that may have caused some confusion with subclasses. isMemberOfClass just happens to be a simple method name that doesn't collide with any principles of the iOS framework and is quite self explanatory. I don't think the logic extends beyond that.

like image 45
Mike A Avatar answered Mar 15 '23 04:03

Mike A