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

Allow trailing required positional parameters #22136

Closed
DartBot opened this issue Jan 23, 2015 · 2 comments
Closed

Allow trailing required positional parameters #22136

DartBot opened this issue Jan 23, 2015 · 2 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jan 23, 2015

This issue was originally filed by @seaneagan


Problem: It's much more readable to pass callbacks as the last argument to a function call so as not to bury other args behind a long code block. But that's not currently possible if:

  • the callback is required
  • the function call also has optional args

since optional args must go after positional args.

Either of issue #4188 or issue #15398 would solve this problem for when the optional args are named.

But the following proposal (this issue) solves this problem for when the optionals are positional:

Allow trailing required positional parameters:

task(String name, [List<String> dependencies = const []], callback()) {
    // ...
}

task('init', () {
    // Long
    // code
    // block.
});

task('build', ['init'], () {
    // Long
    // code
    // block.
});

The best we can currently do is:

task(String name, depsOrCallback, [callback()]) {
    var deps = callback == null ? const [] : depsOrCallback;
    if (callback == null) callback = depsOrCallback;
    // ...
}

which:

  • Loses the type (and thus documentation and checked-mode safety)
  • Loses the default value (and thus documentation and auto-initialization)
  • Requires extra logic to assign the parameters correctly.
@floitschG
Copy link
Contributor

Added Area-Language, Triaged labels.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Jan 27, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
@munificent
Copy link
Member

Duplicate of #15398.

@munificent munificent added the closed-duplicate Closed in favor of an existing report label Dec 15, 2016
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-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants