-
Notifications
You must be signed in to change notification settings - Fork 702
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
Asynchronous programming codelab: consider updates to example code #2128
Comments
Yes |
@galeyang has kindly agreed to review notes about any UX considerations that were relevant here. Outside of that, I'm totally open to adding the type annotations you've suggested. Does this capture the proposed changes? (Note for posterity: these screenshots are included because the code under review is currently hosted in GitHub gists, and was therefore not explicitly compared in the GitHub UI within the relevant PR.) |
Thanks @galeyang! Thanks for the code diffs Jon, although I'm not sure how clear they are with the docregion tags. PR #2114 now contains the original code, so the simplest way to visualize the suggested code changes would be to submit a PR with the changes made (that way we could use the GitHub diff). That being said, the main suggested code changes are:
Other points are raised in the original comment of this issue. Also, a minor suggested change is to write |
Agreed that ideally we can review these changes in a GitHub PR, but since the code still lives in gists, we can't compare updates in the PR to the prior code (i.e. the diff will simply be new code, as opposed to a diff of changes to the old code), or have I missed something @chalin ? |
I'm assuming you meant that once #2114 is merged we'll be able to raise the changes in a GitHub PR, which works for me. It's worth noting that we don't have an ETA on merging that PR yet, correct? |
Oh, I'm sorry if it wasn't clear. I just added #2114 (comment) to clarify that #2114 now uses the same code as the Gists, modulo running dartfmt. So the code in the code blocks of
AFAIK, it is possible to submit a PR over a PR (and then to view the new PR's delta, just look at the new PR's single commit diff). |
This note was initially put at the end, a user (via survey) suggested us to move it upfront (issue). I'm fine with either having
|
I just found in the Effective Dart, it has recommendations |
I think that recommendation was pointed at fully typed older code that used either That said, I think the pedantic package might now complain if we don't type |
Yes: Which is why the Async codelab code in #2114 is sprinkled with |
Summing up (referencing @chalin 's original proposal) it sounds like we're all OK with: So these changes should go in! Does anyone want to weigh in on using arrow functions as proposed? @kwalrath ? |
Do we generally agree that codelab, tutorial and pretty much all example code should be free of analyzer issues when configured with the pedantic options? |
(Unless, of course, it is meant to, e.g.: illustrate errors, or be an incomplete starting point for an exercise.) |
Speaking for myself: yes, absolutely. Thanks Patrice! |
+1 for using
+1 for changing the name between Also, see #2134 We should rename all |
There are still some points from this issue that haven't been addressed. Reopening. |
@chalin Can you specify which points from this issue haven't been addressed? |
|
Moving the discussion from #2114 (comment) to this issue so that PR #2114 can contain only the original code. Copying the relevant parts of the discussion below.
Also consider that the analyzer (with the package using the
pedantic
analyzer options), raises issues with quite a few samples of the code, including:await_only_futures
,argument_type_not_assignable
,invalid_assignment
,type_annotate_public_apis
(which is the most common, but probably the least problematic). This should probably be addressed. In #2114, we usedignore
directives to silence the analyzer.Here's part of the old code that is relevant to this discussion:
Here's the reasoning behind the changes I made, along with comments about what I think is peculiar about the original code:
At the start of (original) Working with futures: async and await we write:
So, ...
Future<void>
tomain()
if we never do so in the codelab?Pedagogically, I find it strange that as we work through the codelab,
String createOrderMessage()
starts off with a semantically meaningful name and consistent return type. Then later we repurpose the function to merely print the order message (rather than return it) and so change the signature tovoid createOrderMessage()
. By doing so we're introducing an incongruity. One solution would be to change the function name toprintOrderMessage()
.Regardless of our choice of function name in the previous point (say,
void printOrderMessage()
), by using a return type ofvoid
we're again not following our own guideline (the guideline I mention in point 1), and we're not explaining why we're deviating from our own guideline.Thoughts?
Btw, when
createOrderMessage()
is declared asvoid
, we get the following issue reported by the analyzer:The text was updated successfully, but these errors were encountered: