[Pyrex] Just some thoughts

Tomasz Primke tprimke at interia.pl
Sun Apr 23 21:53:58 CEST 2006


> > 1) The syntax of integer-loops: I find it too long. In my opinion,
> > instead of writing:
> >
> > for i from lower_bound <= i < upper_bound:
> >   ...
> >
> > it would be better (and easier, faster, more convenient) to write just:
> >
> > for i from lower_bound <= upper_bound:
> >   ...
>
> Your proposed syntax is crap.  It doesn't explicitly relate lower_bound,
> i, and upper_bound (which could cause confusion for learning, reading,
> etc.). A better syntax that avoids the same double-typing is...
>
>     for lower_bound <= i < upper_bound:

Personally, I don't care if the syntax is

        for i from lower_bound <= upper_bound

(that is a crap, indeed!), or

        for i from lower_bound .. upper_bound

(that is also a crap), or

        for lower_bound <= i < upper_bound

(that is much better and don't repeat the loop variable name).

All I had on my mind was the fact, that the loop variable has to be written 
twice (and - in my opinion - it is annoying).

> <snip>
> > 2) I think that Pyrex should offer some low-level memory managment
> > routines. I think of sizeof operator, as well as the C standard *alloc
> > and free functions. It would be also nice to have something like the
> > g_new macro known from the GLib library.
>
> I disagree.  Pyrex is not C.  If you want the memory management
> capabilities of C, write interfaces in C, and use it in Pyrex. (...)

I know, that Pyrex is not C - Pyrex is "designed to bridge the gap between 
the nice, high-level, easy-to-use world of Python and the messy, low-level 
world of C". Nevertheles someone likes it, or not, programming in low-level 
world of C sometimes requires memory management (e.g. in order to write 
faster code). Therefore I still think, that it would be nice for a 
programmer to have such a routines in Pyrex instead of writing them on 
him/herself (and reinventing the wheel again).

And to be clear: I don't think about building such a routines into the Pyrex 
core - I'm thinking about "cimporting" such a routines distributed as a 
ready to use module with Pyrex. You would use them, if - and only if - you 
wanted them.

> <snip>
>
> Which specific array rutines do you like in SWIG?

Perhaps I'll present a simple example from my old code in SWIG:

   %include "carrays.i"
   %array_functions( int, intArray )

and after writing such a code in "SWIG", I could do the following things in 
Python:

   >>> a = new_intArray( size )
   >>> a.set_item( index, value )
   >>> b = a.get_item( index )

Although I don't like the Python arrays API, the ability to get such a 
functions by writing just _two_ lines in a "SWIG" file is something 
good.

I would be happy, if I could get such a (C) functions in Pyrex by writing 
just two lines in my Pyrex code. For now I have to write all such routines 
for myself (what a waste of time - instead of bothering myself with 
high-level algorithms, I have to lower to some low-level problems... It 
should be possible to do with a single cimport).


Best regards,

	Tomek



More information about the Pyrex mailing list