-
Notifications
You must be signed in to change notification settings - Fork 699
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
Added constructor tear-offs #5850
Conversation
Visit the preview URL for this PR (updated for commit 9ce05e2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, but left a few thoughts.
src/content/language/constructors.md
Outdated
|
||
```dart tag=bad | ||
// Instead of a lambda for a named constructor: | ||
var strings = charCodes.map ((code) => String.fromCharCode (code)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be an extra space here between String.fromCharCode
and (code)
.
src/content/language/constructors.md
Outdated
var strings = charCodes.map ((code) => String.fromCharCode (code)); | ||
|
||
// Instead of a lambda for an unnamed constructor: | ||
var buffers = charCodes.map ((code) => StringBuffer (code)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same extra space issue here.
var buffers = charCodes.map ((code) => StringBuffer (code)); | ||
``` | ||
|
||
For visual learners, watch this Decoding Flutter video on tear-offs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or masochists
src/content/language/functions.md
Outdated
You might assign an anonymous function to a variable so that, | ||
for example, you can add or remove it from a collection. | ||
Though you name most functions, such as `main()` or `printElement()`. | ||
you can create nameless functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this clause is missing the "also" from the before version.
"...you can also create nameless functions."
src/content/language/functions.md
Outdated
for example, you can add or remove it from a collection. | ||
Though you name most functions, such as `main()` or `printElement()`. | ||
you can create nameless functions. | ||
These functions are called _anonymous function_, _lambda_, or _closure_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these all be plural?
Then in the anonymous function passed to `forEach`, | ||
each converted string is printed out alongside its length. | ||
Then, the anonymous function passed to `forEach`, | ||
prints each converted string with its length. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the ensuing sample predates this PR and was potentially outside the scope of what you wanted to get into, but it may be worth noting that the code this updated sentence describes directly conflicts with a Dart style guide recommendation: https://dart.dev/tools/linter-rules/avoid_function_literals_in_foreach_calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Took a moment to build the example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Interestingly enough, I don't even like this particular lint and ignore it myself all the time. But, since it is a lint in the style guide, I figure our own docs might as well follow it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #3577