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

Library tour example tests, up to but excluding dart:html #440

Merged
merged 2 commits into from
Nov 21, 2017

Conversation

chalin
Copy link
Contributor

@chalin chalin commented Nov 20, 2017

Contributes to #407 and #416.

cc @Sfshaza

@chalin chalin added Docs fix.examples Adds or changes example test.general Relates to unit, integration, perf testing labels Nov 20, 2017
@chalin chalin requested a review from filiph November 20, 2017 20:09
@googlebot googlebot added the cla: yes Contributor has signed the Contributor License Agreement label Nov 20, 2017
@chalin
Copy link
Contributor Author

chalin commented Nov 20, 2017

I forgot to mention that like for the Language Tour, the main file to review in this PR is src/_guides/libraries/library-tour.md. Most of the changes to that file are updated <?code-excerpt?> paths, but a few of the code excerpts have been updated too.

@@ -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
Copy link
Contributor Author

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".

Copy link
Contributor

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?

Copy link
Contributor Author

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 %}

Copy link
Contributor Author

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

Copy link
Contributor

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.)

Copy link
Contributor Author

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.

Copy link
Contributor

@filiph filiph left a 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() {
Copy link
Contributor

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.

Copy link
Contributor Author

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 docregions, then we could replace some of the tour code excerpts with snippets from complete samples.

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but those render in the HTML as external links, which have an arrow icon afterwards:

screen shot 2017-11-21 at 08 12 21

Kathy much prefers having the punctuation before the "external" icon.

@@ -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:
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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 %}

Copy link
Contributor

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()
Copy link
Contributor

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).

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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.

@chalin
Copy link
Contributor Author

chalin commented Nov 21, 2017

@filiph, thanks for the quick feedback! Changes submitted.

@chalin chalin merged commit 783590c into dart-lang:master Nov 21, 2017
@chalin chalin deleted the chalin-lib-tour-1119 branch November 21, 2017 13:45
chalin added a commit to chalin/site-www that referenced this pull request Nov 21, 2017
chalin added a commit to chalin/site-www that referenced this pull request Nov 22, 2017
chalin added a commit to chalin/site-www that referenced this pull request Nov 22, 2017
chalin added a commit that referenced this pull request Nov 22, 2017
@atsansone atsansone removed the docs label Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Contributor has signed the Contributor License Agreement fix.examples Adds or changes example test.general Relates to unit, integration, perf testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants