Friday, January 21, 2011

"extends" or "extended" ??

I've just read a post on the Django-users mailing list. It was a simple mistake, and quickly corrected by other participants of the list; but it made me think a bit about semantics...

The point was about Django template inheritance: as most OOP languages, Django lets you define a 'base' template and then another 'derived' template that 'extends' the base one. The user in question then used the base template and expected it to contain the 'derived' parts. As everybody pointed, he should have called the 'derived' template instead. Again, just like on OOP languages, where you instantiate the derived classes, and they inherit behavior from its base class(es).

But this kind of mistake seems to be a common one among those first approaching template inheritance. Why is this so? My guess: because 'extends' is a transitive verb.

Lets say I have a chair, and everybody around here knows what a chair is and how it looks. Then I come with some tools and "extend the chair" maybe add some armrests. What do I have now? the same chair, with armrests. If somebody else asks for "the chair", he'll get the 'extended' chair.

But that's not how OOP inheritance works: a class that 'extends' another doesn't make any change to the base one. It's a new class with inherited behavior. That's old news to any programmer.

Don't you think that the 'extends' keyword in Django templates and Java class declarations is a little misleading? I understand that it means "I'm just like that, but extended"; but how come it uses 'extends'? To me, it sounds like some pompous marketing: "this newfangled gizmo copies and extends the old system"