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

parameter-freedom proposal: possible enhancements #21

Closed
tatumizer opened this issue Nov 27, 2018 · 0 comments
Closed

parameter-freedom proposal: possible enhancements #21

tatumizer opened this issue Nov 27, 2018 · 0 comments

Comments

@tatumizer
Copy link

tatumizer commented Nov 27, 2018

The trick used by parameter-freedom proposal is cute: to stop infestation of the code with "child" and "children" boilerplate, turn these parameters into positional ones.
However, the idea creates some new problems that better be avoided.

  1. it's difficult to visually identify positional parameters - they lack visual cues
  2. backwards compatibility is broken
  3. proposal extends the syntax much further than we can justify based on known use cases

Suggested solution:

  1. to avoid intermixing positional and named parameters, let's introduce a new type of parameter. Let's tentatively call it 'trailing parameter'.
  2. Trailing parameter can be single-valued (like child) or vararg (like children)
  3. Only one trailing parameter! (vararg counts as one)
  4. trailing parameter can be passed as name:value pair, like a named one (e.g. child: value or children:[value, value,...]) - in any position, or without name, as a last parameter in the parameter list. This keeps the design backwards-compatible.
  5. support special marker (e.g. +) as (optional?) visually identifiable prefix for trailing parameter (in case of vararg, this applies to each value)

Example:

Widget build(BuildContext context) {
  return Container(
    height: 56.0,
    padding: const EdgeInsets.symmetric(horizontal: 8.0),
    decoration: BoxDecoration(color: Colors.blue[500]),
    +Row(
      +IconButton(
        icon: Icon(Icons.menu),
        tooltip: 'Navigation menu',
      ),
      +Expanded(title),
      +IconButton(
        icon: Icon(Icons.search),
        tooltip: 'Search',
      ),
    ),
  );
}

Note: this proposal doesn't apply to argument blocks. In argument blocks, positional parameters cannot be expressed without introducing new rules, which is beyond the scope here.
But because trailing parameter can function also as a named one, no new problems are created with respect to child/children.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant