cython-hidapi icon indicating copy to clipboard operation
cython-hidapi copied to clipboard

Suggestion: Separate Python functions/classes from C-based code

Open RobertoRoos opened this issue 4 years ago • 2 comments

I wanted to suggest splitting the Python interface from the C-based code. Something like:

# hid.py

class Device:
    # Regular Python class

    def read():
        # Regular Python method
        hid_ex.read()  # Use C-based function, generated from Cython
# hid_ex.pyx

def read(int ....):
    # Cython function

Advantages:

  • Documentation can be generated automatically (hid_ex could be simply mocked)
  • User IDEs have full code completion / suggestions, since they interface with regular (and by now well-documented) Python
  • Development is made a little easier a recompile is not always necessary

Disadvantages:

  • Speed or performance might be affected, though I'm sure not about it - Functionality remains in C-based Library, only an extra interface is added

I'm curious what you think.

RobertoRoos avatar Feb 11 '21 08:02 RobertoRoos

just my 2 cents as a cython-hidapi user: I see no real advantage in doing so. I think wrapping everything just makes it more fragil...

Documentation can be generated automatically (hid_ex could be simply mocked)

why can't they now? afaik it's only a limitation of tooling

User IDEs have full code completion / suggestions, since they interface with regular (and by now well-documented) Python

again this seems to be a limitation of your IDE.

Development is made a little easier a recompile is not always necessary

does this really count?

bearsh avatar Feb 11 '21 19:02 bearsh

I think wrapping everything just makes it more fragile...

I'm not sure. I don't think it would matter much.

why can't they now? afaik it's only a limitation of tooling

RTD cannot compile the HID C library. In a way. But considering we cannot modify the tool nor is there a real alternative, I think it's acceptable to accomodate for it.

again this seems to be a limitation of your IDE.

Does the code completion work for anyone then? And I think PyCharm is (one of) the most common IDE, so again, accomodating for it seems acceptable.

does this really count?

Well, no :p

RobertoRoos avatar Feb 12 '21 08:02 RobertoRoos