Wednesday, June 20, 2007

Abstract Base Class - a poor name. Role is better.

For someone new to programming, or maybe from a non-maths background 'Abstract Base Class' sounds foreign, and weird. Whereas Role rolls off the tongue - giving me language elegance goose bumps.

How many people can guess what an Abstract Base Class is from the name? Even given it's context of 'relating to objects'. I think more people could guess from the name Role.

Reading about Abstract Base Classes over time always gave me troubles. Even reading the PEP now I find it hard to answer the question 'What is an Abstract Base Class'. A simple question don't you think?

Maybe the name is too abstract.

When discussing objects to people I could talk about classes, then about instances, inheritance, and interfaces. When I begin to talk about Abstract Base Classes then blank looks jump out. Maybe it's that the name is so long. The abbreviation into the acronym ABC makes even less sense - as it is using an existing term and changing its meaning. Not that the world needs another acronym being used.

Is Role a good name for what Abstract Base Classes are? Or is there a better name for them?

I think this question needs to be answered:
'An Abstract Base Class is [...]'.

This is the part of the PEP 3119 which describes what Abstract Base Classes are.

"This PEP proposes a particular strategy for organizing these tests known as Abstract Base Classes, or ABC. ABCs are simply Python classes that are added into an object's inheritance tree to signal certain features of that object to an external inspector. Tests are done using isinstance(), and the presence of a particular ABC means that the test has passed.

In addition, the ABCs define a minimal set of methods that establish the characteristic behavior of the type. Code that discriminates objects based on their ABC type can trust that those methods will always be present. Each of these methods are accompanied by an generalized abstract semantic definition that is described in the documentation for the ABC. These standard semantic definitions are not enforced, but are strongly recommended."

From a dictionary, the meaning of Role:
1. a part or character played by an actor or actress.
2. proper or customary function: the teacher's role in society.
3. Sociology. the rights, obligations, and expected behavior patterns associated with a particular social status.

I think the word Role should be used instead of Abstract Base Classes. It's shorter, and makes much more sense.

If not Role, then anything but Abstract Base Classes.

PEP 3133 is another PEP which uses the term Role - that has been rejected.


Chris Arndt said...

Interesting question. What's the difference between an ABC and an interface anyway?

Paddy3118 said...

I like Role, but Abstract Base Class is more enterprisey

- Paddy.

Paddy3118 said...

I missed the smiley at the end :-)

- Paddy.