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

Too much complexity and too many type arguments #23

Open
samcrow opened this issue Mar 31, 2023 · 0 comments
Open

Too much complexity and too many type arguments #23

samcrow opened this issue Mar 31, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@samcrow
Copy link
Owner

samcrow commented Mar 31, 2023

A lot of the Cyphal implementation code in this repository has interfaces that look confusing and are difficult to use correctly.

In particular:

  • Clock, Instant, and Duration types wind their way through the entire stack from the application to the driver.
  • There are many options for transfer ID trackers, numbers of various things that can be stored, and other settings that lead to very long types like this:
pub type UavcanNode = BasicNode<
    CoreNode<
        Stm32MicrosecondClock,
        CanTransmitter,
        CanReceiver,
        TransferIdFixedMap<CanTransport, TRANSFER_IDS>,
        QueueDriver,
        MAX_PUBLISHERS,
        MAX_REQUESTERS,
    >,
>;
  • There are too many error types, and they are too complex. They handle driver errors, subscription-related errors, and out of memory errors from many different layers.

These are some possible changes that would help with this:

  • Make Instant and Duration non-generic. They could just be 32-bit numbers of microseconds. That would overflow about every 35 minutes, which probably won't be a problem.
    • Is there any good way to make the Clock type parameter not so widespread?
      • Use a function pointer instead: fn() -> Instant (for embedded applications, this would not be compatible with drivers that use objects to restrict access to resources)
  • Move the Clock and other type-based settings and constants into some kind of Config type, so the Nodes don't need so many different type parameters
  • Remove MinimalNode and rename other node types (the node types have confusing names, and I don't know when anyone would actually use MinimalNode instead of one of the other two)
  • Make the error types a little less informative so they can be simpler, possibly by having a single non-generic value for driver errors
@samcrow samcrow added the enhancement New feature or request label Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant