1 Code Generation and Optimisation Issues
2 =======================================
3
4 Python's dynamic nature provides a few issues which obstruct the generation of
5 optimised code.
6
7 Attribute and Method Selection
8 ------------------------------
9
10 Python provides a kind of shadowing of attributes so that objects which do not
11 provide a particular attribute can still appear to provide such an attribute
12 via the object's class or base classes. If access via the object or the class
13 are both possible for a particular case, two different kinds of access would
14 need to be provided at that location in the program.
15
16 Unlike other languages, methods and non-method attributes are interchangeable
17 and are provided by objects or classes. Consequently, distinctions between
18 attributes and methods, with special rules for method selection (virtual vs.
19 non-virtual) do not exist. Moreover, unlike some languages such as C++ where
20 explicit qualification of an object's type can be used to reference an
21 attribute - for example, by saying that an object is of type X, an attribute
22 can be located using knowledge of the structure of instances of X - such
23 qualification does not take place in Python programs, and such knowledge must
24 be provided by other means.
25
26 Parameter Structures
27 --------------------
28
29 Python provides some complicated ways of passing parameters to functions and
30 methods, such as keyword arguments and "overflow" parameters (star and dstar
31 parameters). Consequently, if parameter values are to be put on a stack and
32 given to a function, resolution of keyword arguments and "excess" arguments
33 (of both positional and keyword varieties) must take place. This is made even
34 more complicated by the possibility that at a given invocation site, many
35 potentially incompatible functions may be called, each with their own optimal
36 parameter ordering.