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

front: drop PathStep.ch #8633

Merged
merged 1 commit into from
Dec 5, 2024
Merged

front: drop PathStep.ch #8633

merged 1 commit into from
Dec 5, 2024

Conversation

emersion
Copy link
Member

@emersion emersion commented Aug 29, 2024

This information is duplicated in PathItemLocation.secondary_code. This has several downsides.

First, the field secondary_code is inherited in the PathStep type event if it's never set (we omit() it when receiving the train schedule path from the backend). As a result writing "pathStep.secondary_code" in code is valid even if it would never contain anything. Additionally, the field needs to be converted back and forth from/to ch when sending HTTP requests.

Second, the field is always defined even for path steps for which a ch doesn't make sense. For instance, if the path step is an operational_point or is a TrackOffset, the ch property would still be defined (and always be empty).

All of this makes it easy to trip over and use "ch" or "secondary_code" in contexts where it doesn't make sense. While this is easily discovered in testing when initially writing a feature, any subsequent refactoring may subtly break the rest of the code.

To fix this, drop the "ch" field and only use the auto-generated "secondary_code" field. This forces any code making use of ch to verify (with the "in" keyword) that accessing the field makes sense.

Depends on:

@emersion emersion self-assigned this Aug 29, 2024
@emersion emersion force-pushed the emr/drop-path-step-ch branch 3 times, most recently from 8ca55d3 to 131a5b3 Compare November 21, 2024 14:36
@emersion emersion force-pushed the emr/drop-path-step-ch branch from 131a5b3 to 4a4ef04 Compare November 26, 2024 12:54
@github-actions github-actions bot added the area:front Work on Standard OSRD Interface modules label Nov 26, 2024
@emersion emersion requested review from clarani and theocrsb November 26, 2024 12:58
@emersion emersion marked this pull request as ready for review November 26, 2024 12:59
@emersion emersion requested a review from a team as a code owner November 26, 2024 12:59
Copy link
Contributor

@theocrsb theocrsb left a comment

Choose a reason for hiding this comment

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

LGTM

@emersion emersion force-pushed the emr/drop-path-step-ch branch from 4a4ef04 to fae6a1c Compare December 3, 2024 11:16
Copy link
Contributor

@clarani clarani left a comment

Choose a reason for hiding this comment

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

LGTM ✅

This information is duplicated in PathItemLocation.secondary_code.
This has several downsides.

First, the field secondary_code is inherited in the PathStep type
event if it's never set (we omit() it when receiving the train
schedule path from the backend). As a result writing
"pathStep.secondary_code" in code is valid even if it would never
contain anything. Additionally, the field needs to be converted
back and forth from/to ch when sending HTTP requests.

Second, the field is always defined even for path steps for which
a ch doesn't make sense. For instance, if the path step is an
operational_point or is a TrackOffset, the ch property would still
be defined (and always be empty).

All of this makes it easy to trip over and use "ch" or
"secondary_code" in contexts where it doesn't make sense. While
this is easily discovered in testing when initially writing a
feature, any subsequent refactoring may subtly break the rest of
the code.

To fix this, drop the "ch" field and only use the auto-generated
"secondary_code" field. This forces any code making use of ch to
verify (with the "in" keyword) that accessing the field makes
sense.

Signed-off-by: Simon Ser <[email protected]>
@emersion emersion force-pushed the emr/drop-path-step-ch branch from fae6a1c to 1f6c1f4 Compare December 5, 2024 10:30
@emersion emersion added this pull request to the merge queue Dec 5, 2024
Merged via the queue into dev with commit 94d3a84 Dec 5, 2024
27 checks passed
@emersion emersion deleted the emr/drop-path-step-ch branch December 5, 2024 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:front Work on Standard OSRD Interface modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants