-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
How should interfaces for core functionality be named? #1058
Comments
One observation about the Rust-like names is that they tend to read as actions ("add" or "multiply" or "index"), whereas names in current Carbon read as properties ("addable" or "multipliable"). This isn't necessarily fundamental to the approach, however: the Haskell names read as properties too ("numeric" or "ordered"), and some Carbon names that have been discussed aren't properties (" This naming question has some influence on other parts of the language design. In particular, the We could perhaps accept that Another concern is that many of these interfaces will have a single method, and we need to pick a name for that too. In Rust, |
Another option is to give these interfaces short names, but put them some namespace that clarifies these are ops, like |
Recent discussions of this issue: |
Are these intended to be pulled in by the prelude, or would they require an explicit import? I think it could function either way, but it affects name collisions. i.e., |
Some operators work particularly badly under the
These problems don't occur for Rust- or C++-like naming. |
FWIW, I agree about But the other points are all pretty strong IMO. Two things I'd like to understand:
|
I would expect us to want these in the prelude given that they directly interact with the core language.
I agree that collisions are something to think about. Personally, I still think that the prelude should only alias a (very) small subset of names as being available without saying |
I'm not entirely confident of that. I could imagine finding we want variants of the operator as additional methods:
|
We've discussed this several times, and I wanted to write up a rough summary of where I think we're starting to converge at least initially. There are a few patterns that end up guiding what naming scheme to use. (1) Interfaces that implement a specific language expression syntaxOne category of interfaces here are the ones with a specific 1:1 correspondence with a expression syntax, mostly operators. Where have this really strong correspondence I think there is also a growing interest in the following pattern:
One big question I don't have a good answer for is how to choose the short names for the interfaces. When should they be abbreviated? Above, I used the names that seem most natural to me, but they are a complete mixture. Options:
(2) Interfaces that contribute usefully to creating consistent APIs on typesFor some interfaces, it is useful for the function name to be reasonable when embedded into a types API with an internal implementation to create consistent and idiomatic type APIs. While we may want to introduce "spaceship" style syntax ( We still need to name the interface, and there were still some concerns when the name might overlap with the names in the useful method names. We could repeat the names ( One candidate guide for naming the interface that seemed interesting was: if the desired name of the interface might collide with one of its member names, either exactly or as two parts of speech like
However, one unanswered question is what to do when the desired name is already an adjective and completely distinct from any likely member name. Some candidates might be
My current leaningI really happy with any of the (1) variations, slight preference for (1c), then (1b), and (1a) least. I less confident but still pretty happy with (2a). I don't think I'd like (2b) -- I'd like to see if we end up having any real difficulty deciding when to use a suffix before trying to add more rigid rules around it. |
I would like there to be a policy around constraints whose primary role is to express a property, rather than expose methods. Examples: concrete, sized, trivially destructible, has unformed state, is a data class, and so on. |
To clarify, since I don't think I expressed that well: I think there is a third category of constraints that are not really in category (1) since they are not about a specific operation and are more like an adjective than a verb, and not really in category (2) since they don't have members you would want added to your type by implementing them internally. You talk about them as part of category (2), but I don't think they fit there. Also, what category would you put things like |
Just wanted to update this to call out that in open discussion there seemed to be:
Not sure this is fully consensus yet, but wanted to track the discussion. |
I think the leads are good w/ (1c) and (2a) from my earlier comment: #1058 (comment) This includes the clarification of (2a) to mean -- minimally use suffixes like And we'll start with the initial list of abbreviations in (1c) alone: |
Add concrete design for interfaces for comparison. Rename interfaces for arithmetic following current thinking in #1058. Update rules for mixed-type comparisons for data classes following #710. Co-authored-by: Chandler Carruth <[email protected]>
Add concrete design for interfaces for comparison. Rename interfaces for arithmetic following current thinking in #1058. Update rules for mixed-type comparisons for data classes following #710. Co-authored-by: Chandler Carruth <[email protected]>
Does this still need a proposal given #1178 and related work? |
I think this is done now. |
Notable changes from p0157: - Syntax and semantics are updated to reflect subsequent design work, especially on variable declarations, generics, and classes. - `Matchable.Match` is now `Match.Op`, following the resolution of carbon-language#1058.
We have various choices for how to name interfaces that correspond to core functionality, such as overloaded operators, implicit conversions, etc. Some possible considerations:
Mul
,Deref
,Index
, and Haskell usesEq
,Ord
,Num
.__double_underscore__
names such as__mul__
.AddableWith
, and we have accepted proposals usingCommonTypeWith
,As
, andImplicitAs
.operator*
,operator[]
. This would deviate from Carbon's normal naming rules, but this is perhaps a place where we could afford such deviation.Relative to Carbon's goals, the most important aspects are likely:
Probably the two most plausible options are more-abbreviated Rust-like naming and more-verbose naming following our current proposals.
The text was updated successfully, but these errors were encountered: