Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RobertoRoos opened this issue Feb 11, 2021 · 2 comments
Open

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

RobertoRoos opened this issue Feb 11, 2021 · 2 comments

Comments

@RobertoRoos
Copy link
Contributor

RobertoRoos commented Feb 11, 2021

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.

@bearsh
Copy link
Contributor

bearsh commented Feb 11, 2021

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?

@RobertoRoos
Copy link
Contributor Author

RobertoRoos commented Feb 12, 2021

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

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

No branches or pull requests

2 participants