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

Change naming of APIs for state and fetching state #73

Closed
lawrence-forooghian opened this issue Oct 1, 2024 · 20 comments
Closed

Change naming of APIs for state and fetching state #73

lawrence-forooghian opened this issue Oct 1, 2024 · 20 comments
Assignees
Labels
enhancement New feature or improved functionality.

Comments

@lawrence-forooghian
Copy link
Collaborator

lawrence-forooghian commented Oct 1, 2024

#54 (comment)

@umair-ably wasn’t a fan of:

  • using current as a property to mean "the current state of this object", and would prefer it be named state
    • Note: the naming of current is used in the public API of the SDK, which matches the JS naming and also matches the naming used in the core SDKs, and personally whilst I think it could be clearer ("current" what?), I can also live with it
  • the naming of the RoomLifecycle enum, which he thinks should be called RoomState or RoomLifecycleState
    • Again, this naming comes from JS
    • I agree with this suggsted change but would like to understand the motivation for the current name, ask AndyTWF

See comment for agreed outcome to resolve this issue.

┆Issue is synchronized with this Jira Story by Unito

@AndyTWF
Copy link

AndyTWF commented Oct 1, 2024

using current as a property to mean "the current state of this object", and would prefer it be named state

We went with current for parity with the core SDKs.

We specifically didn't choose state because state often implies a larger, internal state. status on the other hand implies a single value, e.g. "the status of your order: accepted, delivered". We felt in context, it worked well, e.g.:

  room.status.current

In this example it's quite clear that you're getting the current room status.

the naming of the RoomLifecycle enum, which he thinks should be called RoomState or RoomLifecycleState

Initially we wanted to call these enums RoomStatus and ConnectionStatus, but JS's lack of namespaces and conflicting identifiers made it not possible.

We wanted to avoid the term State for reasons mentioned above.

If you feel there's a better name, then happy to discuss alternatives!

@vladvelici
Copy link

@AndyTWF I just had a look at our JS code. I think if we swap the names everything makes more sense.

Current New
The enum of statuses RoomLifecycle RoomStatus
The object you use to get the status or subscribe to changes RoomStatus RoomLifecycle

@umair-ably
Copy link
Collaborator

I agree with context to room room.status.current makes sense but when looking at the lifecycle manager it becomes a bit confusing e.g. RoomLifeCycleManager.current?

I'm also fine with status over state, it's the current being a RoomLifecycle enum that doesn't feel right.

Do we need to achieve parity with the core SDKs? or was this something that felt right but perhaps doesn't matter as long as we try to keep parity between the Chat SDKs?

@AndyTWF
Copy link

AndyTWF commented Oct 1, 2024

Do we need to achieve parity with the core SDKs? or was this something that felt right but perhaps doesn't matter as long as we try to keep parity between the Chat SDKs?

It was a deliberate design decision - we're expecting the Chat SDK to be used in concert with the core SDK in many applications (people using PubSub for other aspects of their app). So we went for parity whenever there's overlapping concepts between the two so that that things are intuitive between SDKs.

We did deviate in one or two places where it was an obvious improvement, however (e.g. the subscribe behaviour).

@AndyTWF
Copy link

AndyTWF commented Oct 1, 2024

I just had a look at our JS code. I think if we swap the names everything makes more sense.

That's definitely a possible!

@umair-ably
Copy link
Collaborator

Ahh I've done some digging... most of my confusion stemmed from the PR this is linked to in which we have a property on the RoomLifecycleManager - private(set) var current: RoomLifecycle.

This is readonly _status: DefaultStatus; in JS which makes a lot more sense, so it seems like we've diverged and this is causing the confusion.

Leaning into @vladvelici's suggestion, the API would make a lot more sense with that change too.

Where we currently have:


class RoomLifecycleManager {
    private(set) var current: RoomLifecycle
}

// impl
lifecycleManager.current = .attached

this would become:


class RoomLifecycleManager {
    private(set) var status: RoomStatus
}

// impl
lifecycleManager.status = .attached

this makes a lot more sense!

Can we confirm we're happy to make the following changes:

  • current becomes status in the ably-chat-swift SDK
  • RoomLifecycle is renamed to RoomStatus
  • RoomStatus is renamed to RoomLifecycle

@paddybyers
Copy link
Member

In the core API we only use current when it's a state change event, and that's when there's also a previous. It's not used anywhere to represent the current state outside of that context. current what anyway? If it's current state, then the field should be state.

@AndyTWF
Copy link

AndyTWF commented Oct 1, 2024

Can we confirm we're happy to make the following changes:

  • current becomes status in the ably-chat-swift SDK
  • RoomLifecycle is renamed to RoomStatus
  • RoomStatus is renamed to RoomLifecycle

SGTM - for JS we'll swap the interface and enum names for consistency, as well as the current -> status change

@umair-ably
Copy link
Collaborator

Sweet, we'll do the same - thanks all! I've also added this to the divergence log

@umair-ably umair-ably changed the title Reconsider naming of APIs for state and fetching state Change naming of APIs for state and fetching state Oct 1, 2024
@lawrence-forooghian lawrence-forooghian self-assigned this Oct 1, 2024
@lawrence-forooghian
Copy link
Collaborator Author

I imagine we want to make the same change for connection lifecycle, right? That is, call the enum ConnectionStatus and the object that emits this status ConnectionLifecycle.

lawrence-forooghian added a commit that referenced this issue Oct 1, 2024
We:

- rename the RoomLifecycle enum to RoomLifecycleStatus (which makes more
  sense);
- rename the RoomStatus protocol to RoomLifecycle and rename its
  `current` property to `status` ("current" what?; it wasn’t clear, and
  was inconsistent with the core SDKs, which only use `current` for state
  _changes_)

The net effect is that instead of writing `room.status.current` you now
write `room.lifecycle.status`, which still seems pretty readable and
gives the benefits listed above.

This change has been agreed with the Chat team and the decision is
recorded in [1]; they will make this change in JS.

As part of this, I’ve also corrected references to room “state” to the
correct terminology of “status” (in [2] Andy explains why they used the
word “status”, choosing to reserve “state” for some larger composite
state).

Outstanding spec question about whether to rename the RoomInFailedState
error [3]; that can wait.

[1] https://ably.atlassian.net/wiki/spaces/CHA/pages/3307405320/SDK+Divergence+Decision+Log
[2] #73 (comment)
[3] https://github.com/ably/specification/pull/200/files#r1783542331
lawrence-forooghian added a commit that referenced this issue Oct 1, 2024
@AndyTWF
Copy link

AndyTWF commented Oct 2, 2024

That is, call the enum ConnectionStatus and the object that emits this status ConnectionLifecycle.

For this we already have ConnectionStatus as the enum. I somewhat prefer Connection as the interface name - I don't think Lifecycle on the end adds anything useful / distinguishes it from something else

@lawrence-forooghian
Copy link
Collaborator Author

For this we already have ConnectionStatus as the enum.

Are you sure about that? From what I’m seeing, ConnectionStatus is the interface that emits the enum and ConnectionLifecycle is the enum.

@AndyTWF
Copy link

AndyTWF commented Oct 2, 2024

For this we already have ConnectionStatus as the enum.

Are you sure about that? From what I’m seeing, ConnectionStatus is the interface that emits the enum and ConnectionLifecycle is the enum.

Ahh sorry, was looking at the wrong file!

Then yes, I agree we should do the same here :)

@sacOO7
Copy link

sacOO7 commented Oct 2, 2024

@AndyTWF Do we need to update this as a part of the spec. I strongly feel, if spec is ambiguous, we need to update it.
Because we are going to implement same naming conventions across SDKs

@AndyTWF
Copy link

AndyTWF commented Oct 2, 2024

@AndyTWF Do we need to update this as a part of the spec. I strongly feel, if spec is ambiguous, we need to update it. Because we are going to implement same naming conventions across SDKs

The spec for Chat doesn't currently specify down to the property level what everything needs to be called - its a work in progress primarily focused on making sure we capture the intended behaviour in clear language, as well as providing testing points for the UTS.

If we decide to add an IDL to the spec - then of course we'll include it.

@vladvelici
Copy link

@AndyTWF wrote CHADR-062 to describe the change, I've left a comment there initially but moving it here to keep the conversation in one place.


I think the room.status.status or room.connection.status.status syntax is not ideal, in whatever language.

The room.status.current next to room.status.onChange makes more sense to me, because it’s clear we talk about the status, it’s on a class that represents the status and nothing else. We can subscribe to changes or see the current value.

In JS, inside the implementation of the class, we actually have private variable called _state (could be renamed to _status) and provided as current via a getter. Can similar be done with other implementations to avoid the room.status.status thing?

@sacOO7
Copy link

sacOO7 commented Oct 2, 2024

@AndyTWF Do we need to update this as a part of the spec. I strongly feel, if spec is ambiguous, we need to update it. Because we are going to implement same naming conventions across SDKs

The spec for Chat doesn't currently specify down to the property level what everything needs to be called - its a work in progress primarily focused on making sure we capture the intended behaviour in clear language, as well as providing testing points for the UTS.

If we decide to add an IDL to the spec - then of course we'll include it.

I strongly feel we should have IDL for the spec. Otherwise, there will be implicit assumptions in the future that will lead to more confusion

@sacOO7
Copy link

sacOO7 commented Oct 2, 2024

Also, it's difficult to keep track of related discussions. I mean current discussion isn't really related to Swift and has impact across other chat SDKs

@lawrence-forooghian
Copy link
Collaborator Author

lawrence-forooghian added a commit that referenced this issue Oct 28, 2024
We apply the changes that we decided upon in [1]; that is, we:

- remove the RoomStatus protocol, moving its functionality directly into
  the Room protocol, and rename the `current` property to `status`;

- rename the RoomLifecycle enum to RoomStatus

As part of this, I’ve also corrected references to room “state” to the
correct terminology of “status” (in [2] Andy explains why they used the
word “status”, choosing to reserve “state” for some larger composite
state).

[1] https://ably.atlassian.net/wiki/spaces/CHA/pages/3410526209/CHADR-062+Renaming+Lifecycle+Types+for+Clarity
[2] #73 (comment)
lawrence-forooghian added a commit that referenced this issue Nov 6, 2024
We apply the changes that we decided upon in [1]; that is, we:

- remove the RoomStatus protocol, moving its functionality directly into
  the Room protocol, and rename the `current` property to `status`;

- rename the RoomLifecycle enum to RoomStatus

As part of this, I’ve also corrected references to room “state” to the
correct terminology of “status” (in [2] Andy explains why they used the
word “status”, choosing to reserve “state” for some larger composite
state).

[1] https://ably.atlassian.net/wiki/spaces/CHA/pages/3410526209/CHADR-062+Renaming+Lifecycle+Types+for+Clarity
[2] #73 (comment)
@lawrence-forooghian
Copy link
Collaborator Author

Done in #92.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improved functionality.
Development

Successfully merging a pull request may close this issue.

6 participants