-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add RFC for explicit self member access. #173
base: main
Are you sure you want to change the base?
Conversation
One possibility would be to combine explicit |
Let's talk about this again next week. |
Discuss more next week. |
To quote the "Zen of Python", "Explicit is better than implicit." For those who might think it shouldn't be necessary to specify an argument whose name is predetermined, using a name other than @sylvanc's proposal would even improve C++ because the arity of a member function would always match its declaration's whether it's
|
Personally, I don't treat "explicit is better than implicit" as a valid argument on its own in most cases, as it can be use to justify a great deal of proposals that we could probably all agree aren't desirable for the language (e.g. "the language should require us to explicitly specify which assembly registers to use for our function parameters"). There are always things that are implicit in your semantic model (that's just the nature of abstraction), and it wouldn't be "better" to make all of those things explicit. Perhaps a better formulation would be "unsurprising is better than surprising", as this way of stating it acknowledges explicitly (oh, the irony!) the implicit premise that you expect your users to have a certain base level of understanding, and you should make explicit anything that would be surprising/unexpected given that base of understanding. And this gets you to the point of debating the real issue - which is deciding exactly what base level of understanding should be expected, allowing you the option of improving your learning materials to help users meet that base level rather than rejecting every proposal that might expect them to learn more. Note that this is not a comment about Sylvan's proposal, but just me explaining why I tend to dismiss the "explicit is better than implicit" line of argument - because it isn't specific or explicit enough to be good advice in every case in which people may try to apply it. |
I'm going to try doing a modification to a source file and see how I feel about |
The general consensus I heard during sync today was that everyone preferred "explicit over implicit" -- myself included, but not verbalized. I am personally in favor of using some symbol for member access, if not My preference is for a symbol rather than explicit |
I'm wary of a symbol for "self" access. Especially as we already have I tried out I'm not coming out against a symbol, but I am leaning away from it. I would definitely prefer if there is a symbol to not make all FFI using code have to change as well. I'd rather introduce a new symbol but I don't really see any available except |
I appear to be an incrementalist at the moment. I find myself not in favor of adding a new symbol at this time. And rather only want consider the explicit self member access which effectively creates a new named scope. @ergl on the last sync call raised the important point about the intersection of explicit self member access + named parameters. It's true that with named arguments using For me, I'd like to resolve the named argument issue (perhaps via explicit self member access and requiring Then I'd also like to resolve the issue that I feel #174 addresses which is what can become an incredibly verbose (but usually fine) field initialization with object that have tons of fields like those seen in the GitHub Rest API. I'm happy to resolve them in either order, but I would definitely like to consider options outside the current context of the two RFCs. For example, perhaps the overly verbose and occasionally bug inducing issues that I feel #174 is an attempt to address would be better resolved via having a macro system. I feel that both RFCs from @jemc, #173 and #174 are addressing import points but, I want to consider other alternatives as well. |
I have a question for folks, please respond directly on this comment with thumbs up/thumbs down reaction (and not adding additional comments for now that bust up the flow of conversation here). One way to address the "where" problem with named arguments is to have parameters "live in a different namespace" from fields and methods. The approach we've discussed so far has only been "change rules to access fields and methods". How would folks feel if instead of a required fun double(x: U64): U64 =>
param.x * 2 I'm dubious myself (for a number of reasons), but I want to explore all ideas for "parameters are in a different namespace from fields and methods". |
One option covered in the sync call is to require the The advantage of this would be that it would be a backwards-compatible change: class Foo
let x: U8 = 0
fun set_x(x: U8) => x = x // ambiguous, needs this.x
fun add_x(delta: U8) => x = x + delta // not ambiguous, this. not needed |
I tried out explicit |
We discussed at sync and for now, we can't come to an agreement on this so we are leaving behind for now. If we are making a very large breaking change then we should revisit as we are more likely to find agreement on this. In particular, if there was a very large breaking change, I would be more open to the |
I propose that Example:
Pros:
Cons:
Notes:
Skip this next part if you've already read enough -- this is way out on a tangent:
|
We discussed @adrianboyko's proposal comment above in today's sync call - that idea has parsing ambiguity issues, including in an example like this: .foo()
.bar() |
This PR adds my RFC for explicit self member access.
Note: I have also filed another RFC that builds on this one