-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 support for interleaved parameters on method signatures / calls #956
Comments
Set owner to @gbracha. |
Added Accepted label. |
This would of course collide with the current named argument syntax, but a while back I toyed with this in Smalltalk: object doSomethingUsingThing: thing withOtherThing: otherThing Translating to something like this in Dart: object.doSomething(usingThing: thing, withOtherThing: otherThing) |
The named parameter syntax may be revisited, so there are possibilities ... |
This comment was originally written by [email protected] @bob, that seems pretty readable to me, but, correct me if I'm wrong, using named args the method signature is still "doSomething" in each case since there's no method overloading in Dart, meaning that if I were to add another parameter like in "doSomething(usingThing: thing, withOtherThing: otherThing andYetAnotherThing: anotherThing)", this would conflict. So to support the use of the extra parameter, it seems the only way would be to have a very monolithic method that checks for the presence of each parameter in its implementation and does varying behavior conditionally to support all the different combinations of parameters. This seems less maintainable to me. |
The idea is that those "named parameters" would actually be part of the method name itself. So you could think of: object doSomething(usingThing: thing, withOtherThing: otherThing) as being kind of like syntactic sugar for: object doSomething_usingThing_withOtherThing(thing, otherThing) |
This comment was originally written by [email protected] Ah, in that case, that's great too. I'd be happy with either solution. Are you following any other languages' leads on these? Maybe I'm just extremely ignorant, but I don't know any languages where the named params become part of the method signature. In that case, would it also be possible to change the named parameter argument order in a call? I see this as a staple of most named argument implementations that I've seen, but I wonder how it could work if the arguments change the signature. |
Not really. It was just my attempt to get Smalltalk-style keyword selectors to look "right" in a C-derived syntax. (For what it's worth, my hobby language Magpie supports this behavior too, more or less, but going about it in a different way.)
No, it wouldn't. Personally, I think that would be OK because in most places where you would use this there is likely an obviously right order. You would do "example".substring(from: 1, to: 2) but "example".substring(to: 2, from: 1) reads kind of funny. It is very different from named arguments in other languages. It looks the same, but the semantics are very distinct. That's probably the main argument against it. |
This comment was originally written by [email protected] Well for my personal preference, I'd be happy with whichever syntactical format, as long as the result is ultimately more descriptive selectors/signatures. I suppose some could argue that I can already be as descriptive as I want with the regular grouped parameter syntax by having method names like doSomethingUsingThing_andOtherThing_, but this is both generally difficult for humans to parse and is too 'different' to make a convention. I think if the language provides the convention as an option, in a format that seems to mesh with the regular call styles, then more people would be encouraged to use it. But as you said:
The difficulty is going to be to pick the least unfamiliar and least surprising syntactical construct for this to gain acceptance with most c-style familiarized developers. |
This comment was originally written by [email protected] A minor improvement over the current state would be allowing positional arguments to be optionally named. (You'd still have to get the position right). So with: these are equivalent: and these are errors |
This comment was originally written by [email protected] An improvement, yes. I really hope we can do better though, and really hopefully before development of core api's is so far ahead with the existing syntax that it would be too much work to go back and add named versions of the core library apis. |
We decided to keep named parameters rather than introducing keyword sends (as in Smalltalk) into Dart. We realize this is a matter of taste. Added WontFix label. |
This comment was originally written by [email protected] Disappointing. Would there be any consideration for something like "non-optional" named arguments, where essentially calls would look like doSomething(withX:x, withY:y)? Or is this not worth making a request for? |
2020-11-05 [email protected] Fixes #602: New tests for least and greatest closures added. 2020-11-05 [email protected] #926. Rewrite io/Process/start_A01_t02 test to work on precompiled environment 2020-11-05 [email protected] #932. Rewrite HttpRequestUpload/onLoad_A01_t01 test to send correct HttpRequest 2020-11-04 [email protected] Fixes #956. Don't expect extension invocation on type dynamic 2020-11-04 [email protected] Convert some multi-tests to static error framework (#958) 2020-11-03 [email protected] Fixes #602: dynamic tests for least and greatest closures updated. 2020-11-03 [email protected] Fixes #602: tests for least and greatest closures added. 2020-10-28 [email protected] #926. Fix two Process tests to use 'process_test' tool 2020-10-28 [email protected] #926. Rewrite two Process tests to use 'process_test' tool 2020-10-28 [email protected] Fixes #955. Expect less specific error for typed_data tests 2020-10-26 [email protected] Fixes #954. Change the line where we expect an error for CFE 2020-10-20 [email protected] Fixes #912. Abstract variables syntax tests added 2020-10-19 [email protected] #912. More external variables syntax tests added 2020-10-17 [email protected] External variables syntax test added 2020-10-16 [email protected] #912. More test for static analysis of external variables added 2020-10-15 [email protected] #912. Test for static analysis of external variables added 2020-10-14 [email protected] #912. Test for static analysis if abstract variables added Cq-Include-Trybots: dart/try:analyzer-nnbd-linux-release-try,analyzer-nnbd-win-release-try,dart2js-nnbd-linux-x64-chrome-try,ddc-nnbd-linux-release-chrome-try,front-end-nnbd-linux-release-x64-try,front-end-nnbd-win-release-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-x64-try,vm-kernel-nnbd-mac-release-x64-try,vm-kernel-nnbd-win-release-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-precomp-nnbd-win-release-x64-try Change-Id: Id9cde784918faa4e891da8c4cb448d415a7a18aa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170680 Reviewed-by: William Hesse <[email protected]> Commit-Queue: Alexander Thomas <[email protected]>
This issue was originally filed by [email protected]
I understand that Dart is shooting for a familiar feel to most c languages and therefore I would expect support for the familiar "dot notation" method call style and grouped parameters. But for those of us that like languages that give the ability to have self documenting code, why not add support for smalltalk-esque keyword messages as well? It wouldn't have to be something as unfamiliar as:
object doSomethingUsingThing: thing withOtherThing: otherThing.
But how about something like:
object.doSomethingUsingThing(thing)withOtherThing(otherThing);
This would be supported with the associated method declaration syntax:
void doSomethingUsingThing(Thing aThing)withOtherThing(Thing otherThing) { ... }
The language could allow calling this method with both styles provided some formatting standard is agreed to, so using the usual calling syntax this could also be called with something like:
object.doSomethingUsingThing_withOtherThing_(thing, otherThing);
Would this really be any more unfamiliar to most Java/JavaScript developers than the equally unfamiliar optional named parameters?
The text was updated successfully, but these errors were encountered: