You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Passing port listener to port is clunky and errorprone #87
Thanks @Omnieboer. I see nothing errorprone in our existing example that is fixed in the PR, I find this statement to be incorrect. If you can provide evidence that it will result in errors, please add them to the issue description.
clunky
In regards to "clunky", the statement specifically references an example on the wiki, which you helped create in #85 😉 . In my experience it's sane to store a pointer to the SerialPort object and then reuse that to read bytes when events are fired, which would avoid passing a reference to the constructor. I realize this makes an assumption that the listener is constructed within (or externally exposed from) the same class as the SerialPort, but I don't know an easy way to avoid one or the other, and I certainly don't find pointer encapsulation like our example uses to be either "clunky" or "errorprone" (or at least I don't see it being better in the PR).
I think the underlying design decision to do this -- and it being perceived as "clunky" -- stems from matching (or more proper, the inability to match) a String (portName) to an Object (SerialPort instance) or inability to obtain the SerialPort reference from the caller, but this is fairly common in listeners in my experience. Since these events are fired by CPP and can be a one-to-many relationship, I'm not sure how to handle it better. Stashing a reference may also break the 1:many relationship of the listener.
I've shared more thoughts over in #86. If the thread gets too long, it may make sense to take it over onto Slack.
Activity
tresf commentedon Apr 30, 2021
Thanks @Omnieboer. I see nothing errorprone in our existing example that is fixed in the PR, I find this statement to be incorrect. If you can provide evidence that it will result in errors, please add them to the issue description.
In regards to "clunky", the statement specifically references an example on the wiki, which you helped create in #85 😉 . In my experience it's sane to store a pointer to the
SerialPortobject and then reuse that to read bytes when events are fired, which would avoid passing a reference to the constructor. I realize this makes an assumption that the listener is constructed within (or externally exposed from) the same class as theSerialPort, but I don't know an easy way to avoid one or the other, and I certainly don't find pointer encapsulation like our example uses to be either "clunky" or "errorprone" (or at least I don't see it being better in the PR).I think the underlying design decision to do this -- and it being perceived as "clunky" -- stems from matching (or more proper, the inability to match) a String (
portName) to an Object (SerialPortinstance) or inability to obtain the SerialPort reference from the caller, but this is fairly common in listeners in my experience. Since these events are fired by CPP and can be a one-to-many relationship, I'm not sure how to handle it better. Stashing a reference may also break the 1:many relationship of the listener.I've shared more thoughts over in #86. If the thread gets too long, it may make sense to take it over onto Slack.
tresf commentedon May 3, 2021
I think this is workable, proposed a diff over in #86 that I think does what you're looking for, at least mostly. :)
Pass the bytes along with the SerialPortEvents (#86)