Skip to content

Usage of attribute properties obfuscates CAN IO operations #271

Closed

Description

@sveinse

Awsome library! It enabled me to talk to some CANopen hardware (CanFestival to be exact) with just a couple of lines straight out of the box! Kudos.

I have a topic that is not strictly an issue, but about methodology. I am currently working on an async port of this library (more to follow later). I have encountered a pattern in canopen where the attribute @property decorators and @x.setter setters is used a lot and that they sometimes ultimately end up doing CAN IO. Especially around class Variable. Examples are v = node.sdo['something'].raw or node.nmt.state = 'OPERATIONAL'. While I understand the intent, neatness and orthogonality of doing so, it kind of caught me by surprise, as I didn't expect attribute operations to have such side effects as to make IO requests.

With all due respect, I definitely think the canopen library should have better separation between which methods and mechanisms that generate CAN IO and which that does not. I would love to see that we rather use explicit names for IO-generating operations. To quote 2nd rule from the Zen of Python (PEP20): "Explicit is better than implicit."

In the work of migrating to async, getters and setters does not interact very well with async operation so it will have to be changed for this usage. It will need a paralell explicit get and set mechanism in order to be able to await the deep inner CAN IO. In that use case the user must know when IO happens because it must be awaited, while immediate functions acting locally does not.

Activity

  1. christiansandberg commented on Oct 11, 2021

    @christiansandberg
    Member

    Nice to hear that someone is working on an asynchronous version of this library. I've been thinking about it myself earlier but it felt too difficult making it work for synchronous as well as asynchronous in the same library. But that would be awesome if it could be done!

    The attribute access was something that felt logical at the time. You could for example increment a number or do bit wise operations on a bit field using a single statement. Later on I realized it made it difficult to know where blocking operations were actually done so it is also something I regret to some extent.

    So I wouldn't be against moving to using methods instead, but since users probably rely on these attributes a lot it would be preferable to keep it for backwards compatibility.

  2. sveinse commented on May 16, 2024

    @sveinse
    CollaboratorAuthor

    After a lot of discussion in PR #371 it was concluded that this project will continue with attribute access (using blocking IO) to avoid any code breakage, and that get_* and set_* methods are not desired. I'm closing this issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions