Add private named parameters section#7250
Conversation
|
Visit the preview URL for this PR (updated for commit e8a9b84): https://dart-dev--pr7250-private-named-parameters-n56d3tla.web.app |
There was a problem hiding this comment.
Code Review
This pull request introduces documentation and code examples for the new 'Private named parameters' feature in Dart, which allows initializing private fields directly in the constructor parameter list. The changes include updates to the language tour, glossary, and analysis configurations. The review feedback identifies an inconsistent semicolon placement in an enum and suggests a technical correction to the documentation to clarify that the feature also supports super-initializer parameters.
| * **Initializing formals only:** Named parameters in Dart generally | ||
| cannot be private. This feature is an exception that only applies | ||
| to named parameters that are initializing formals (`this._field`). | ||
| You cannot use private names for regular named parameters. |
There was a problem hiding this comment.
The private named parameters feature is not limited to initializing formals (this._field); it also applies to super-initializer parameters (super._field). Updating this constraint will provide a more complete and accurate description of the feature's scope.
| * **Initializing formals only:** Named parameters in Dart generally | |
| cannot be private. This feature is an exception that only applies | |
| to named parameters that are initializing formals (`this._field`). | |
| You cannot use private names for regular named parameters. | |
| * Initializing formals and super parameters only: Named parameters in Dart generally | |
| cannot be private. This feature is an exception that only applies | |
| to named parameters that are initializing formals (this._field) | |
| or super-initializer parameters (super._field). |
| } | ||
| ``` | ||
|
|
||
| ### Private named parameters |
There was a problem hiding this comment.
Should we name this section and references to this capability as "private-named parameters" to clarify the parameter itself isn't private, but rather the name is?
There was a problem hiding this comment.
It's not really just about parameters whose name happens to be private. Dart has already allowed those for positional parameters:
class C {
int _x;
C(this._x);
}It's really about named parameters whose name is private. I thought about calling the feature "private-named named parameters" but that's obviously no fun for anyone to read or say. :) For what it's worth, I think of the feature as "private (named parameters)" more than "(private named) parameters".
But if you think the hyphen will help clarify things for readers, I'm OK with it.
There was a problem hiding this comment.
I think we should keep the title as is to remain consistent with the feature spec (if that matters). Do you have strong opinions about the hyphen @parlough?
Create a new section on the constructors page for the new 3.12 feature Private Named Parameters.