On Sun, Apr 26, 2009 at 2:27 AM, Robert Bradshaw <rober...@math.washington.edu> wrote: > > On Apr 26, 2009, at 2:08 AM, Ondrej Certik wrote: >> So when I am exposing a new class, i it's quite a lot of typing, >> especially the name of the C++ class has to be copied over and over >> again (e.g. in the definition of the new constructor, etc). Compared >> to swig, it was much easier to do it in swig, where you basically just >> copy the C++ header file and swig does the rest. That said, the Cython >> way is of course much cleaner in the end, once I have it written >> already. > > Yes, one of the differences between Cython and swig is that swing > provides automated wrappers, whereas Cython lets you use the library > directly, not just wrap it. Of course wrappers can still be done, > it's more manual work (sometimes this is good as it allows a more > "pythonic" interface to the underlying library) There was someone who > prototyped a tool to do auto-generate classes (I believe he called it > ccython) which read in C++ files and generated .pyx files. Not sure > how far it went.
I would like to stick to Cython and I don't want any magic behind the scene, e.g. I like the Cython way. But still I believe it could be made simpler. Currently one basically uses a C like syntax to handle C++ classes. And of course one can do OO programming in C, but it's just a lot of typing. That's why I actually prefer C++ for OO stuff, becuase I don't have to type that much --- the syntax for defining a class+methods is way less verbose than doing a C struct and then constructor, destructor, etc. as C functions. So my idea was that maybe Cython .pxd definition could be similarly less verbose. As an example, I could imagine going from: cdef struct c_WeakForm "WeakForm": void add_biform(int i, int j, ...) void add_biform_surf(int i, int j, ...) void add_liform(int i, ...) void add_liform_data(int i, void *data) void add_liform_surf(int i, ...) c_WeakForm *new_WeakForm "new WeakForm" (int neq) to something like: cdef class WeakForm: WeakForm(int neq) void add_biform(int i, int j, ...) void add_biform_surf(int i, int j, ...) void add_liform(int i, ...) void add_liform_data(int i, void *data) void add_liform_surf(int i, ...) I don't know --- obviously, the current Cython way is very explicit, and I like that. But it's just like with numpy arrays --- one can also use the explicit way, but you already added some syntactic sugar into Cython to simplify things, so maybe something similar could be done for C++ classes too. > >> Another area of improvement is that if the C++ contains hierarchy of >> classes, I need to store a pointer to for example the ancestor and >> then retype it everytime I want to use it in subclasses, like here: >> >> >> http://github.com/certik/hermes2d/blob/ >> b4ddf0e825180f1360304d93cd3a081ba22b101e/python/hermes2d/ >> hermes2d.pyx#L125 >> >> >> it'd be nice to have some easier way to handle C++ subclasses in >> Cython. I don't know how it should be done though. > > Good point. If we can declare inheritance information, I believe we > can use the same type infrastructure we use for cdef classes to > handle this smootly. Yes. If it could be made simpler, it'd be awesome. Ondrej --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---