-
Notifications
You must be signed in to change notification settings - Fork 207
Description
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.