Use a better name for methods creating a new receiver #215
Replies: 4 comments 3 replies
-
FYI @frequenz-floss/python-sdk-team I think I prefer the I do really think it will be a mistake to keep the current approach if we want to make an SDK that is suitable for newcomers and not super experienced people. |
Beta Was this translation helpful? Give feedback.
-
I don't understand the adding extensions example. You seem to be using both of your suggestions in it? |
Beta Was this translation helpful? Give feedback.
-
I like the |
Beta Was this translation helpful? Give feedback.
-
We agreed to proceed with this: |
Beta Was this translation helpful? Give feedback.
-
The Problem
Right now the
LogicalMeter
(and soon theBatteryPool
and probably theEVChargerPool
) name functions returning a receiver after the data that comes from the receiver.Examples:
This can be a bit obscure for people that are new to programming with channels, senders and receivers in general and specifically new to the SDK.
People might think that the method (which sounds like a regular getter) might be idempotent so calling:
is OK, while in reality is creating multiple receivers, which adds overhead to the channel processing. Also if the channel has the option to always return the last value, it will receive a repeated value if there was nothing new between the first
receive()
and the second.Suggested solutions
For me it is important to name functions after what they are really doing, so in this case the function should be called something that suggests it is creating a new receiver, because that's really what it is doing, and anything else is misleading.
Some options are:
p.new_WHAT_receiver()
p.WHAT.new_receiver()
p.new_WHAT_receiver()
Pros:
Cons:
p.WHAT.new_receiver()
Pros:
Reads clean and nicely.
Allows for adding extensions, new ways of retrieving the data, for example:
It is well structured, a pool or logical meter is providing access to some data, and each data can be retrieved in some particular way
Cons:
Beta Was this translation helpful? Give feedback.
All reactions