summaryrefslogtreecommitdiff
path: root/pypers/meta/proposal2.txt
blob: 70b16c2c0408c48a76af750974285dc2325a7252 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Proposal for a new paper METACLASS PROGRAMMING IN PYTHON - PART 2
--------------------- -------------------------------------------

In the early days, metaclasses were considered an esoteric subject, for 
wizards only. After the coming of Python 2.2, they have been better exposed 
to the programmer, but still their usage has been considered mysterious by 
most users. However, nowadays, this perception is changing and more and more
 programmers are beginning to explore this fascinating topic.

In our earlier paper on metaclass programming in Python, we introduced 
the concept of metaclasses, showing how powerful they are, and
how they can be used in real life, for solving problems such as
dynamic customization of classes and libraries at run-time.

This paper has proved quite popular, and we followup by
filling in some of the gaps in our initial summary, that was
necessarily compact. 

There are many subtilities in the usage of metaclasses, which deserves
to be better explored. Based on the feedback of our readers and the 
discussions in comp.lang.python, we think that the following points are 
crucial for the programmer wanting to master metaclasses:

1) understanding the subtle differences and interactions between 
metaclass-oriented programming and more traditional object-oriented
programming that utilizes multiple inheritance and mix-in classes.  
Many programmers become confused on the subtle distinctions, since
inheritance in metaclasses works differently than usual inheritance.  

2) Python 2.2 has added the built-in 'staticmethod()' and 'classmethod()' 
that allows to call methods from classes. Superficially, that overlaps with
the behavior of methods defined in metaclasses, but nonetheless differ 
importantly. This has also generated a lot of confusion in the mind of
many programmers.

3) understanding the origin and the resolution of metatype conflicts, 
that becomes ubiquitous at the moment when the user wants to use more
than a single custom metaclass. This amount to understanding the issue of
composition (in the sense of multiple inheritance) of metaclasses.

As well as clarifying these OOP concepts, this paper provides several
additional concrete examples where metaclasses ease programming
tasks.


---

D. Mertz
M. Simionato                                            4-30-2003