Skip to content

Conversation

@scoder
Copy link

@scoder scoder commented May 4, 2014

note: integer size fixes which require corresponding changes in itertoolz.pxd

note: integer size fixes which require corresponding changes in itertoolz.pxd
@eriknw
Copy link
Member

eriknw commented May 5, 2014

Awesome, everything in here looks great. I am a little abashed at writing such dirty code in the first place, so thanks for cleaning it up! I'd like to look at this a little more closely, but I think we can get this merged very soon.

By the way, @scoder, I think you've done a fantastic job with lupa. Merging Lua and Python is one of my guilty pleasures. When writing complicated functionality for Lua, I find I prefer to first write it in Python along with a test suite, and then it's trivial to port it to Lua and test it from within Python. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional bindings go in "cytoolz/cpython.pxd".

I would actually like to use different names for the C API functions defined in that file. For example, perhaps function names should use PyPointer_ prefix if the new binding returns a pointer, such as:

cdef extern from "Python.h":
    PyObject* PyPointer_GetItem "PyObject_GetItem" (object o, object key)

Is this common practice, and what naming conventions make sense?

@scoder
Copy link
Author

scoder commented May 5, 2014

Additional bindings go in "cytoolz/cpython.pxd".

I'm aware of that, just thought you might want to have some fun cleaning more things up, too. :)

Note that there are lots of similar cases in the other modules where writing explicit C-API calls can be avoided. As a rule of thumb, I'd always write things down in Python syntax first, and then look at the C code ("cython -a module.pyx" will give you an HTML view on it, especially nice with the latest Cython master branch and Pygments installed). Only if Cython happens to generate suboptimal code, I'd consider working around that. In many cases, adding a hint like "this isn't None" or an explicit assignment will already help enough.

PyPointer_GetItem

Something like PyObject_GetItemPointer() or ...Ptr() sounds better to me. I don't think there is a convention. I agree that it's better to distinguish the names. Looking through the code, I often went "why is the author calling that function here instead of just using normal Python syntax?" and in some cases, it was because the code was actually lying to me and doing something different from what it said.

@eriknw
Copy link
Member

eriknw commented May 5, 2014

I'm aware of that, just thought you might want to have some fun cleaning more things up, too. :)

I plan to, and thanks for getting this started :) . I agree with your rules of thumbs (and all of your changes), and I know I didn't look at the annotated output ("cython -a") nearly often enough.

A brief history: this project began as a way for me to get my hands dirty with Cython, and I became curious how much toolz could be improved. I didn't know cytoolz was going to be the result! @mrocklin just gave a talk at PyData yesterday that included CyToolz, and I did well to match Toolz' API and to make it pip-installable in a limited amount of time. So, yes, I expect that a little cleaning and revision may be needed, and I greatly appreciate the feedback and contributions that have already been given.

Something like PyObject_GetItemPointer() or ...Ptr() sounds better to me. I don't think there is a convention. I agree that it's better to distinguish the names. Looking through the code, I often went "why is the author calling that function here instead of just using normal Python syntax?" and in some cases, it was because the code was actually lying to me and doing something different from what it said.

Yeah, we should definitely use different and more descriptive names. There aren't many additional C bindings, so I guess it's too soon to come up with conventions as long as the name of each individual binding makes sense.

@eriknw
Copy link
Member

eriknw commented May 5, 2014

Merging.

eriknw added a commit that referenced this pull request May 5, 2014
clean up some unnecessary C-API usages and fix integer sizes
@eriknw eriknw merged commit 049b728 into pytoolz:master May 5, 2014
@mrocklin
Copy link
Member

mrocklin commented May 5, 2014

Thanks @scoder !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants