Background
At first, HeadsetControl only supported one device and one feature. No device registry, no feature handling, etc.
That's why in the past, there couldn't be a distinction between C and C++ - it would have been the same code.
However, the project grew considerably: supporting multiple devices, multiple output types, and many features. At some point libusb was switched to libhidapi for better cross-platform support. However, there was never a switch from C to C++.
Why Consider C++ Now?
Pros:
- Would save ~20% duplicate code (device init boilerplate, repeated error handling patterns)
- Some parts are already object-oriented (device registry, vtable-like pattern with function pointers)
- Development would be easier (inheritance, RAII, std::string vs manual malloc/free)
- Access to more libraries if needed (e.g., JSON output, CLI parsing)
- Modern C++ has features we currently work around (asprintf, string handling)
Cons:
- Almost none - performance would be the same, C++ compilers are bundled with C compilers
Why Not Other Languages?
- Binary needs to stay small and performant
- HIDAPI would require wrappers
- Modern C++ with the right tools can be just as productive
Options
- Full migration to C++ - rewrite everything
- Hybrid approach - keep C API, migrate device implementations to C++ classes
- Stay in C - refactor to reduce duplication with helper functions
Thoughts are welcome
Background
At first, HeadsetControl only supported one device and one feature. No device registry, no feature handling, etc.
That's why in the past, there couldn't be a distinction between C and C++ - it would have been the same code.
However, the project grew considerably: supporting multiple devices, multiple output types, and many features. At some point libusb was switched to libhidapi for better cross-platform support. However, there was never a switch from C to C++.
Why Consider C++ Now?
Pros:
Cons:
Why Not Other Languages?
Options
Thoughts are welcome