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

Rename "value" to "message" and other minor breaking changes #281

Merged
merged 10 commits into from
Mar 6, 2024

Conversation

llucax
Copy link
Contributor

@llucax llucax commented Mar 6, 2024

This PR replaces the term "value" with "message" as "value" is too generic and used in many other contexts.

It also makes Selected.was_stopped a property and make some function taking only one obvious argument positional-only, to avoid having the argument name being part of the interface (we actually renamed those arguments too, but that's not included in the release notes as they are not part of the public API any more anyways).

We also do some other minor internal renaming and changing of arguments to positional-or-keyword-only.

@llucax llucax requested a review from a team as a code owner March 6, 2024 09:26
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) part:channels Affects channels implementation part:synchronization Affects the synchronization of multiple sources (`select`, `merge`) part:core Affects the core types (`Sender`, `Receiver`, exceptions, etc.) part:utilities Affects the utility receivers (`Timer`, `Event`, `FileWatcher`) labels Mar 6, 2024
@llucax

This comment was marked as outdated.

@llucax llucax self-assigned this Mar 6, 2024
@llucax llucax added this to the v1.0.0 milestone Mar 6, 2024
llucax added 10 commits March 6, 2024 10:41
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
We are already using properties for anything that can be trivially
calculated, so this looks like a good candidate too to make the
interface more consistent.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
We prefer to use the term "message" as what's transported in a channel,
as "value" is too generic and used in many other contexts.

This means changing the code too, so `Selected.value` is now
`Selected.message`.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
This is just to make the code extra obvious but it also affects one
function signature: `Sender.send()`, so it is a breaking change.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
This is just for consistency and extra clarity.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Also for extra clarity and consistency.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
This is to make the code more readable/consistent.

Note that `Select` is actually public, but the constructor is not meant
to be used by users.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax llucax requested a review from shsms March 6, 2024 09:41
Copy link
Contributor

@shsms shsms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment. Approving anyway because it might not be so bad to leave as it is.

@@ -228,16 +228,9 @@ def exception(self) -> Exception | None:
"""
return self._exception

@property
def was_stopped(self) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selected.was_stopped feels a bit ambiguous to me. Might be worth renaming to Selected.receiver_stopped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it clear enough but I'm also OK to rename it. Will wait a bit in case anyone else wants to chime in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the suggested name is more precise. Even though the new documentation will clear up any ambiguity I'd also suggest to rename it

Copy link
Contributor Author

@llucax llucax Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I was doing the change but then wondered what about exception and message, should they also be receiver_exception and receiver_message? I'm not super convinced about introducing an inconsistency where some stuff in Selected has a receiver_ prefix and some not, but also find a bit overkill to prepend everything with receiver_ as it is pretty clear to me that Selected is wrapping a receiver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other possible options:

  • Selected -> SelectedReceiver (but it might be misleading because it is not really a receiver, just a wrapper)
  • Remove was_stopped and force the user to use exception instead

Not sure why I'm listing them because I think I like them even less than the other options above 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shsms ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of was_stopped, but that doesn't mean I can't accept it.

The issues I have with it are that it could mean other things - like the select was stopped/interrupted, etc. Also the past tense was is also confusing. Does that mean we don't know what the present state is?

And it doesn't even qualify that it should be checked within a type narrowed scope of selected_from. It feels like it could be anything.

But of course, nothing wrong with keeping something ambiguous to discourage its use of force people to read the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other fields don't need the receiver_ prefix, because we don't have a was_exception or was_message to begin with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that was_ is probably unnecessary, stopped is already a binary state, I think I used it because it read more nicely with if selected.was_stopped than if selected.stopped. Also I think the past tense is still correct. It was stopped when it was used to receive, we don't know if it got somehow restarted since then.

And it doesn't even qualify that it should be checked within a type narrowed scope of selected_from. It feels like it could be anything.

I didn't get this.

The other fields don't need the receiver_ prefix, because we don't have a was_exception or was_message to begin with.

I don't get the difference. exception and message are actual objects, not binary states, so it doesn't make sense to have a was_. I thought you suggested the prefix to indicate that it's talking about the receiver, not the Selected object.

In any case, to wrap up, if you are not completely opposed to it and there is no consensus on a better choice, I'd say we just keep the status quo to be able to move forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge this PR, as it is really a separate issue if we want to rename this or not. Feel free to create a issue for it @shsms and we can keep discussing it there.

@llucax llucax mentioned this pull request Mar 6, 2024
@llucax llucax added this pull request to the merge queue Mar 6, 2024
Merged via the queue into frequenz-floss:v1.x.x with commit e7b98d1 Mar 6, 2024
14 checks passed
@llucax llucax deleted the value-message branch March 6, 2024 13:26
@llucax llucax modified the milestones: v1.0.0, v1.0.0-rc.1 Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:channels Affects channels implementation part:core Affects the core types (`Sender`, `Receiver`, exceptions, etc.) part:docs Affects the documentation part:synchronization Affects the synchronization of multiple sources (`select`, `merge`) part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) part:utilities Affects the utility receivers (`Timer`, `Event`, `FileWatcher`)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants