-
Notifications
You must be signed in to change notification settings - Fork 676
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
Library tour example tests, up to but excluding dart:html #440
Conversation
Contributes to dart-lang#407 and dart-lang#416.
I forgot to mention that like for the Language Tour, the main file to review in this PR is |
@@ -984,6 +974,49 @@ Future objects appear throughout the Dart libraries, often as the object | |||
returned by an asynchronous method. When a future *completes*, its value | |||
is ready to use. | |||
|
|||
|
|||
#### Basic usage |
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.
This subsection isn't new, I just moved it up so that basic usage (explaining Future.then()
etc) comes just before "Using await".
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.
FWIW, I'm not sure this is a good move. Most developers, most of the time, will want to use async/await
. Maybe we want to call this section "low-level usage" and move it back?
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.
That's what I figured, but the presentation seemed off on first reading. I.e., the "Using await" section, when first, uses an example of "Basic usage" to motivate the use of await.
Anyhow, I'll revert to the original order.
/* Handle exception... */ | ||
} | ||
{% endprettify %} | ||
|
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.
Given that the subsection before this one already covers "Using await", it seemed to make sense to include a version of the example code that uses await rather than then()
chaining
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.
Just bookmarking in case you do decide to go with my suggestion to move "Basic usage" back to where it was. Not sure if it changes anything about the reasoning here. (I think it doesn't.)
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.
Not sure if it changes anything about the reasoning here. (I think it doesn't.)
Agreed. Leaving this as is.
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 with minor comments
import 'dart:async'; | ||
// #enddocregion import | ||
|
||
void miscDeclAnalyzedButNotTested() { |
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.
Is there a rule/heuristic for when code snippets are tested and when they aren't? If so, it would be good to document it somewhere.
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.
Ok, I'll add a few lines to the README when it is revised to have adopt writer-oriented perspective. How's this:
Most code excerpts should be tested, unless they are so incomplete that they require extensive supplemental support infrastructure (which isn't being shown in the tour), just to get something executable.
IMHO, it makes more sense to invest in testing complete samples, when they exist, than to have to create considerable support code. Also, once the code samples are setup for processing of docregion
s, then we could replace some of the tour code excerpts with snippets from complete samples.
scripts/analyze-and-test-examples.sh
Outdated
@@ -34,7 +34,9 @@ echo | |||
travis_fold start analyzeAndTest.tests.vm | |||
echo Running VM tests ... | |||
|
|||
pub run test --reporter expanded --exclude-tags=browser | tee $LOG_FILE | |||
TEST="pub run test" # --reporter expanded |
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.
What are we disabling here with commenting out --reporter expanded
, exactly? Might want to just delete it or make a separate comment. This way it looks like a malformed explanation comment.
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.
Ah, I had meant to clean that out, thanks. (Running pub run test
from a script makes --reporter expanded
the default.)
Done.
[int,]({{site.dart_api}}/{{site.data.pkg-vers.SDK.channel}}/dart-core/int-class.html) | ||
[double,]({{site.dart_api}}/{{site.data.pkg-vers.SDK.channel}}/dart-core/double-class.html) and | ||
[num.]({{site.dart_api}}/{{site.data.pkg-vers.SDK.channel}}/dart-core/num-class.html) Also see | ||
[int,][int] [double,][double] and [num.][num] Also see |
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.
nit: [num][num].
I think the period and the commas should be outside the link.
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.
Also, I believe you can just say [num][]
in this case.
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.
@@ -536,18 +525,20 @@ Although Map doesn’t implement Iterable, you can get Iterables from it | |||
using the Map `keys` and `values` properties. | |||
</div> | |||
|
|||
Use `isEmpty` to check whether a list, set, or map has no items: | |||
Use `isEmpty` or `isNotEmpty` to check whether a list, set, or map has items: |
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 wonder if we should add a comment explaining why the core library even has isNotEmpty
. Something like "Practice showed that developers use !list.isEmpty
a lot and so — after careful consideration — we decided to add isNotEmpty
. It's redundant, but developers find it handy, readable and pragmatic."
cc @kwalrath
Consider this non-blocking. I'd love to get Kathy's opinion once she gets back.
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.
SGTM, I'll add this to a list of topic to review with Kathy when she returns.
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 don't want to add a comment this to the tour, since it generally tries to be as succinct as possible. If there's a place that talks about designing APIs (e.g. Effective Dart), that might be an appropriate place to mention this.
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 is some form of justification given in this Effective Dart Usage Dont': https://www.dartlang.org/guides/language/effective-dart/usage#dont-use-length-to-see-if-a-collection-is-empty
Shall I make "Use isEmpty
or isNotEmpty
" a link to this entry?
@@ -984,6 +974,49 @@ Future objects appear throughout the Dart libraries, often as the object | |||
returned by an asynchronous method. When a future *completes*, its value | |||
is ready to use. | |||
|
|||
|
|||
#### Basic usage |
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.
FWIW, I'm not sure this is a good move. Most developers, most of the time, will want to use async/await
. Maybe we want to call this section "low-level usage" and move it back?
/* Handle exception... */ | ||
} | ||
{% endprettify %} | ||
|
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.
Just bookmarking in case you do decide to go with my suggestion to move "Basic usage" back to where it was. Not sure if it changes anything about the reasoning here. (I think it doesn't.)
await Future.wait([ | ||
deleteLotsOfFiles(), | ||
copyLotsOfFiles(), | ||
checksumLotsOfOtherFiles() |
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.
Nice.
Style-wise, this looks like a good place for a trailing comma (dartfmt will be forced to always put each element on its own line, and moving elements around is much easier).
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.
Yes, good point. Done.
{% prettify dart %} | ||
main(List<String> arguments) async { | ||
... | ||
Future main(List<String> arguments) async { |
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 wonder if we can elide the return type Future
in this section, just to keep the code at a minimum.
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.
While we elided return type annotations for main()
functions at the start of the Language Tour to keep the code as light as possible, IMHO, our Library Tour should illustrate the recommended practice of specifying the return type of public APIs.
Generally speaking, I find it easy to gloss over the "async" keyword, whereas the "Future" annotation at the start of the method signature is usually grabs one attention :).
I'd vote to keep it. If you'd still like for me to remove it, let me know.
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'd prefer to remove the type before main(). It doesn't seem to help, and it obscures the method name.
@@ -2695,3 +2668,63 @@ sampling of what you can install using pub. | |||
|
|||
To learn more about the Dart language, see | |||
[A Tour of the Dart Language](/guides/language/language-tour). | |||
|
|||
[AnchorElement]: {{site.dart_api}}/{{site.data.pkg-vers.SDK.channel}}/dart-html/AnchorElement-class.html |
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.
Thanks for doing this! It really makes the markdown read much better.
@filiph, thanks for the quick feedback! Changes submitted. |
Contributes to dart-lang#407 and dart-lang#416. Continuation of dart-lang#440
Contributes to dart-lang#407 and dart-lang#416. Continuation of dart-lang#440
Contributes to dart-lang#407 and dart-lang#416. Continuation of dart-lang#440
Contributes to #407 and #416.
cc @Sfshaza