[Pyrex] Too much overloading? And other stuff
Edward C. Jones
edcjones at erols.com
Mon May 19 15:25:30 CEST 2003
As you may have noticed by the questions I ask, I have had difficulties
learning Pyrex. This is despite considerable programming experience in
Python, C, and several other languages.
When I am a newbie, I get confused easily. One of the things in Pyrex
that causes confusion for me is the four different meanings of "=". Here
is a sample piece of code with the key C code output by "pyrexc".
def fun():
cdef int i
cdef int j
i = 77 # __pyx_v_i = 77;
j = i # __pyx_v_j = __pyx_v_i;
m = 88 # __pyx_1 = PyInt_FromLong(88); __pyx_v_m = __pyx_1;
n = m # __pyx_v_n = __pyx_v_m;
i = m # __pyx_2 = PyInt_AsLong(__pyx_v_m); __pyx_v_i = __pyx_2;
n = j # __pyx_1 = PyInt_FromLong(__pyx_v_j); __pyx_v_n = __pyx_1;
There is a C assignment, a Python assignment and two conversions.
Also "." may be over overloaded. It has three meanings: C ".", C "->",
and Python ".". Why were the C "*" (*p is the thing p is pointing at)
and "->" operators eliminated?
My conclusion is that "things that are different should look different".
Today I Google searched for "programming language design philosophies".
I found "Seven Deadly Sins if Introductory Programming Language Design"
by Linda McIver and Damian Conway. The URL is
"http://www.csse.monash.edu.au/~damian/papers/PDF/SevenDeadlySins.pdf".
They call this problem "syntactic homonyms".
I suggest that Pyrex be strongly typed. In Python I never make mistakes
because of the dynamic typing. But when C is around, it might be better
to consistently use C's strong typing. Moreover, conversions should be
explicit. The result is
def fun():
cdef int i
cdef int j
object m
object n
i = 77
j = i
m = 88
n = m
i = Cvar(m)
n = object(j)
I also suggest Python/C++ style casting:
int i
float x
x = float(i)
i = int(x)
-------------------------------------------------------------------
I suggest a function type() or typeof() that works on both C and Python
variables.
-------------------------------------------------------------------
Here is a C macro that is difficult to wrap with Pyrex:
#define CV_IMAGE_ELEM( image, elemtype, row, col ) \
(((elemtype*)((image)->imageData + (image)->widthStep*(row))[(col)]))
One of the macro variables is a type. It is feasible to eventually
include some sort of C++ style templates in Pyrex? If necessary, Pyrex
could generate C++ code.
-------------------------------------------------------------------
Buglet: Line 1980 of ExprNodes.py is
error(self.pos, "Cannot take sizeof incomplete type '%s'" % arg_code)
The "arg_code" probably should be "arg_type".
Thanks,
Ed Jones
More information about the Pyrex
mailing list