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

Add support for interleaved parameters on method signatures / calls #956

Closed
DartBot opened this issue Dec 24, 2011 · 13 comments
Closed

Add support for interleaved parameters on method signatures / calls #956

DartBot opened this issue Dec 24, 2011 · 13 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Dec 24, 2011

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?

@dgrove
Copy link
Contributor

dgrove commented Jan 2, 2012

Set owner to @gbracha.
Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Jan 3, 2012

Added Accepted label.

@munificent
Copy link
Member

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)

@gbracha
Copy link
Contributor

gbracha commented Jan 3, 2012

The named parameter syntax may be revisited, so there are possibilities ...

@DartBot
Copy link
Author

DartBot commented Jan 4, 2012

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.

@munificent
Copy link
Member

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)

@DartBot
Copy link
Author

DartBot commented Jan 5, 2012

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.

@munificent
Copy link
Member

Are you following any other languages' leads on these?

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.)

In that case, would it also be possible to change the named parameter argument order in a call?

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.

@DartBot
Copy link
Author

DartBot commented Jan 6, 2012

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:

It looks the same, but the semantics are very distinct. That's probably the main argument against it.

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.

@DartBot
Copy link
Author

DartBot commented Jan 27, 2012

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:
class Point {
  void move(int x, int y);
}

these are equivalent:
move(x:4, y:2);
move(4, 2);
move(4, y:2);

and these are errors
move(x:4);
move(y:4, x:2);

@DartBot
Copy link
Author

DartBot commented Mar 8, 2012

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.

@anders-sandholm
Copy link
Contributor

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.

@DartBot
Copy link
Author

DartBot commented May 9, 2012

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?

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels May 9, 2012
@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
dart-bot pushed a commit that referenced this issue Nov 6, 2020
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 closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants