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

LocalePreferences: bikeshed #5786

Closed
sffc opened this issue Nov 6, 2024 · 9 comments · Fixed by #5990
Closed

LocalePreferences: bikeshed #5786

sffc opened this issue Nov 6, 2024 · 9 comments · Fixed by #5990
Assignees
Labels
C-locale Component: Locale identifiers, BCP47 needs-approval One or more stakeholders need to approve proposal S-small Size: One afternoon (small bug fix or enhancement)

Comments

@sffc
Copy link
Member

sffc commented Nov 6, 2024

LocalePreferences landed in #5729. Two things I want to decide about it before it gets shipped:

  1. Name. Not a big fan of the name. These are not preferences for a locale. It is a locale associated with a preference bag. I think PreferencesLocale is a better name, but would also be happy with naming it "what it is" such as LanguageIdentifierWithRegionExtensions, for example.
  2. Public fields. I don't consider the design of this type 100% finalized. The CLDR spec it is implementing is still a concept, not yet landed in UTS 35. I would prefer it to have private fields. EDIT: Moved to Discuss: Should LocalePreferences have public fields #5785

@zbraniecki @robertbastian

@sffc sffc added C-locale Component: Locale identifiers, BCP47 needs-approval One or more stakeholders need to approve proposal labels Nov 6, 2024
@sffc sffc added this to the ICU4X 2.0 ⟨P1⟩ milestone Nov 6, 2024
@sffc sffc changed the title LocalePreferences: bikeshed and decide on public fields LocalePreferences: bikeshed Nov 6, 2024
@sffc
Copy link
Member Author

sffc commented Nov 7, 2024

  • @zbraniecki To reiterate my reasoning: I don't think there is value of this struct beyond ergonomics of internal operations. For me, it is almost the same as if we listed the field in the main preference bag. These are the "preferences related to locale". I would be opposed to PreferencesLocale because it conveys that this is a type of locale that has value as a standalone struct, but I see the only value is storage of fields and conversion to DataLocale.
  • @sffc OK.
  • @robertbastian I like having the type.
#[non_exhaustive]
pub struct ListFormatterPreferences {
    pub locale_prefs: LocalePreferences,
}
  • @robertbastian The fields of ListFormatterPreferences should be private, right?
  • @sffc You shouldn't ever convert a Locale to a LocalePreferences in user code, because you want to retain other Unicode extensions like numbering system. No strong opinion on the field being public overall
  • @zbraniecki If we make them private, we can make them public later

Conclusion:

  • For naming: keep LocalePreferences.
  • Make the locale_prefs field of preferences bags private.

LGTM: @sffc @zbraniecki @robertbastian

@Manishearth
Copy link
Member

Make the locale_prefs field of preferences bags private.

A quick attempt to do this doesn't work; the prefs_convert macro needs them. Should these be doc(hidden)? or perhaps private with a __get_locale_prefs() hidden method?

@Manishearth
Copy link
Member

If we're making this private, we should probably document that these preferences are here, and have some form of way of setting them from the locale?

@sffc
Copy link
Member Author

sffc commented Jan 6, 2025

Now that we have prefs_convert, which didn't exist when we made the LGTM above, I'm a little bit less concerned about this field being public. However, I am concerned that LocalePreferences is marked as exhaustive:

#[allow(clippy::exhaustive_structs)] // this type is stable
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LocalePreferences

@Manishearth
Copy link
Member

@sffc Should I close #5955 then, or do you think this change is still valuable?

Overall having these types have all-public fields does feel nice from the POV of documentation, at least. When I made locale_prefs private I immediately felt like the Preferences types would need some documentation to replace that, since it's pretty common to understand types by looking at their fields from the docs.

However, I am concerned that LocalePreferences is marked as exhaustive:

This should be fixed by #5785 , yes? I can work on that next.

@sffc
Copy link
Member Author

sffc commented Jan 6, 2025

It's a bit confusing since these were both discussed on the same day, but given that we decided to make the fields of LocalePreferences be private, I think on this issue I might be of the opinion that locale_prefs should remain public (but maybe be renamed to locale_preferences???)

@Manishearth
Copy link
Member

@zbraniecki @robertbastian what do you feel about the above proposal?

@zbraniecki
Copy link
Member

I'm ok keeping it public

@Manishearth Manishearth added the S-small Size: One afternoon (small bug fix or enhancement) label Jan 7, 2025
@Manishearth Manishearth self-assigned this Jan 7, 2025
@Manishearth
Copy link
Member

Current plan: rename the field to locale_preferences, move forward with making LocalePreferences internally private #5785

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-locale Component: Locale identifiers, BCP47 needs-approval One or more stakeholders need to approve proposal S-small Size: One afternoon (small bug fix or enhancement)
Projects
None yet
3 participants