First of all, I'll introduce myself. I've been working on a Python
compiler written in OCaml for about a year now. Some of you might
know me from my talk at Google. One of the list members suggested
this mailing list as a good forum for discussion and bouncing ideas.
I think that one issue to consider are the complex semantics of
functions and method calls. Whenever a function call is made, there
is a lot of checking involved as to 'where' the function is called
from: i.e. whether it's a user-defined function/method, a built-in
function/method, a class function/method or an instance function/
method. Just reading the reference manual section on 'function
objects' is enough to see how many different cases are there.
Of course, this provides tons of flexibility in reusing the same code
for different ways. However, it increases the amount of book-keeping
and pre-processing required for a call. For example, Consider an
object that implements methods 'str' and 'append' (the list object,
for instance). During retrieval of methods, the following default
retrieval method is called (in OCaml syntax, a simplified version).
let list_getattr o attr =
let v = get o.dict attr in (* lookup the attribute in the dictionary *)
match attr with
| String "append" | ... | ->
v.instance = o; v (* set the method's instance to o
before returning it *)
| _ -> v (* else return the method object as is *)
So basically, I have to check for two cases based on the actual names
of the methods being called. This seems like extra work for the runtime.
As a suggestion, I think that adopting a single calling convention
(either 'x.foo()' or 'foo(x)') would have 2 advantages.
1) It would make it easier for users and make for more readable code.
I still find myself having to refer to the docs to find out how a
method needs to be called.
2) It would improve performance by reducing these checks shown above
to one case.
What do y'all think? Would this sacrifice too much flexibility? If
this topic has been discussed on this list before, please feel free
to point me there.