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

Inconsistent names between List and Map methods #26544

Open
jabraham17 opened this issue Jan 15, 2025 · 3 comments
Open

Inconsistent names between List and Map methods #26544

jabraham17 opened this issue Jan 15, 2025 · 3 comments

Comments

@jabraham17
Copy link
Member

In #21395, we decided to remove the various get* methods on map (getReference(), getBorrowed() and getValue()). These were added to avoid accidentally transferring ownership of classes, but in #21395 the decision was made to have a single get()/this() method that just was carefully implemented to work with owned classes.

However, in making this decision, list seems to have been overlooked. list has a getValue() and getBorrowed() (as well as a this()), instead of a single get()/this() like map. While there doesn't seem to be anything inherently wrong with the implementation, the asymmetry of the names is unfortunate and potentially confusing for users.

I propose making similar updates to list, where getValue() and getBorrowed() are replaced with a single get. However, this is a breaking change and will need to be handled accordingly.

@mppf
Copy link
Member

mppf commented Jan 15, 2025

Can the new get() be added as a non-breaking change?

@lydia-duncan
Copy link
Member

I think so, but we will also want to update this() for consistency. A get() update could be staged independent of that

@jabraham17
Copy link
Member Author

Perhaps something important to note is that map.get takes two arguments, a key and a sentinel value. It either returns the value of the key, or the sentinel if the map doesn't contain the key. The map.this accessor may throw a KeyNotFoundError error if the key isn't in the map, or add it and default initialize the value (if the value type is default initializeable).

This is very different semantics from what a list.get method would look like, where accessing an invalid index should halt.

I did not fully internalize this when opening this issue, and would adjust my suggestion slightly to say "lets just deprecate and remove 'getValue' and 'getBorrowed'". Which is the breaking part of this change :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants