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

Setup language-tour.md for auto code-refresh from examples/language-tour sources #414

Merged
merged 10 commits into from
Nov 8, 2017

Conversation

chalin
Copy link
Contributor

@chalin chalin commented Nov 1, 2017

Reviewers:

You'll probably want to focus your review efforts on src/_guides/language/language-tour.md while ignoring whitespace diffs:

  • The code diffs that you will see are the result of having refreshed the code excerpts from their originating sources. (After this PR is merged, I'll set this up so that it happens automatically.)
  • In very few places I adjusted the Tour prose and/or examples -- but usually only after discussing the proposed change with you via email.

TL;DR

The purpose of this PR has been to adapt the Language Tour, and its example sources, so that we can use the code_excerpt_updater to auto-refresh code excerpts in the Language Tour markdown.

For the most part, the language tour markdown already contained embedded paths to the source files it uses, and the source files contained some form of code excerpt markers. Consequently, most changes made in this PR are "lexical" and minor:

  • Sources under examples/language-tour: changed code excerpt marker syntax from
    • BEGIN/END to
    • #docregion/#enddocregion.
  • src/_guides/language/language-tour.md: changed inline code excerpt comments
    • <!-- path/to/source --> to
    • <?code-excerpt? "path/to/source"?> processing instructions.

Doc regions were manually adjusted to ensure that the code excerpts remained unchanged (except for genuine updates done to the code since the markdown was written).

In a few cases files were relocated because they were in a wrong folder (e.g., deprecated was moved to metadata).

Contributes to #407

What is left to do: I haven't touched code excepts that are in the Gists used with DartPad.

@chalin chalin added infra.structure Relates to the tools that create dart.dev a.libraries Relating to the Dart standard libraries. labels Nov 1, 2017
@googlebot googlebot added the cla: yes Contributor has signed the Contributor License Agreement label Nov 1, 2017
@chalin chalin requested review from kevmoo and filiph November 1, 2017 21:44
Copy link
Member

@kevmoo kevmoo left a comment

Choose a reason for hiding this comment

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

In general it looks good, except for all of the types being added.

Especially within a function, var is great!

What's the reasoning here?

{% prettify dart %}
final name = 'Bob'; // Or: final String name = 'Bob';
final String name = 'Bob'; // Or: final String name = 'Bob';
Copy link
Member

Choose a reason for hiding this comment

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

Why adding types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Type annotations like these are appearing because the code excerpt is now synced with its originating source file. dart-archive/dart-up-and-running-book#53 is the PR in which most of these type annotations were introduced.

Here is a direct link to the change made to the code excerpt you commented on: https://github.com/dart-lang/dart-up-and-running-book/pull/53/files#diff-9c88f184c7d08c6ebcfb3ff1909212db:

- final name = 'Bob'; // Or: final String name = 'Bob';
+ final String name = 'Bob'; // Or: final String name = 'Bob';
  // name = 'Alice';  // Uncommenting this causes an error
  // END(final_initialization)
  
- final name2 = 'Roberta';
+ final String name2 = 'Roberta';
  ...

In this, and many other cases, I believe that type annotations were added because the type_annotate_public_apis analyzer rule.

If this isn't what we want, then we'll need to drop that analyzer rule and fix the source files. Let me know what you prefer.

Copy link
Member

Choose a reason for hiding this comment

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

This is kinda tough.

If we're just showing folks "here's how you set a variable", that code – IMHO – should be in a main method or something.

These are more tricky. v2 inference will mean even public fields – like these – won't strictly need types.

@munificent – thoughts here?

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 code – IMHO – should be in a main method or something.

Agreed. I can review each of the code diffs (that add extra type annotations), and remove the annotation if it isn't meaningful for that particular example.

{% prettify dart %}
const bar = 1000000; // Unit of pressure (dynes/cm2)
const atm = 1.01325 * bar; // Standard atmosphere
const int bar = 1000000; // Unit of pressure (dynes/cm2)
Copy link
Member

Choose a reason for hiding this comment

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

....and here?

var s2 = "Double quotes work just as well.";
var s3 = 'It\'s easy to escape the string delimiter.';
var s4 = "It's even easier to use the other delimiter.";
String s1 = 'Single quotes work well for string literals.';
Copy link
Member

Choose a reason for hiding this comment

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

...and here...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These variable declarations appear in the section on "Strings", which may be why the variables are declared as String. (The same is true of the use of int and double above, in the sections on "Numbers".)

Copy link
Contributor

Choose a reason for hiding this comment

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

But — the original page doesn't have the type annotations, right? https://www.dartlang.org/guides/language/language-tour#strings

Let's keep it that way.

Copy link
Contributor Author

@chalin chalin Nov 8, 2017

Choose a reason for hiding this comment

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

Let's keep it that way.

Ok, I'll revert those code changes that were done before the code was copied over into this repo.

{% prettify dart %}
var list = [1, 2, 3];
List<int> list = [1, 2, 3];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto: IMHO, this type annotation helps emphasize that we are in the section talking about Lists.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would just leave var.

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.

@chalin
Copy link
Contributor Author

chalin commented Nov 2, 2017

PTAL at the latest commit. I've removed only two type annotations: for each of the examples of final and const, I've left one declaration w/o a type and kept one declaration with a type annotation.

I've looked at all other cases, and the places where type annotations were added make sense to me (see my inline comments). Let me know what you think.

@kwalrath
Copy link
Contributor

kwalrath commented Nov 6, 2017

I don't think we should use types anywhere that we wouldn't in our own well-written code. If need be, we can mention the type in a comment or the text.

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 comments. I don't feel strongly about it but I would suggest removing the added type annotations.

- language-tour/reference/*.dart
- library-tour/reference/*.dart
- library-tour/async-await/bin/main.dart
# exclude:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just remove these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gone

{% prettify dart %}
// Define a function.
printNumber(num aNumber) {
void printNumber(num aNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, in language tour, we can actually make omissions like this (no void) for the sake of smoother beginnings. Does that break the code-excerpt pipeline? If this is because of a lint, maybe we want to use // ignore_for_file annotations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think, in language tour, we can actually make omissions like this (no void) for the sake of smoother beginnings.

Ok

Does that break the code-excerpt pipeline?

Not at all.

If this is because of a lint, ...

Yes. I'm thinking that we have too many lint rules. Maybe we should opt for the same list that we recommend for Angular: https://github.com/dart-lang/stagehand/blob/master/templates/web-angular/analysis_options.yaml

@kwalrath @filiph WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think in general it's good to have as many lint rules turned on for samples as possible (because by default, samples should be exceptionally "standard" code). I'd rather we keep them on but that we're not afraid to use // ignore_for_file where it makes sense.

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

var s2 = "Double quotes work just as well.";
var s3 = 'It\'s easy to escape the string delimiter.';
var s4 = "It's even easier to use the other delimiter.";
String s1 = 'Single quotes work well for string literals.';
Copy link
Contributor

Choose a reason for hiding this comment

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

But — the original page doesn't have the type annotations, right? https://www.dartlang.org/guides/language/language-tour#strings

Let's keep it that way.

{% prettify dart %}
var list = [1, 2, 3];
List<int> list = [1, 2, 3];
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just leave var.

Code excerpts are preceded by an HTML comment containing a path to the file from which the excerpt originates. Replace each such path with a `<?code-excerpt?>` processing instruction.

This results from a global search and replace. Corrections will follow.
Adjust / set `#docregion`s in Language Tour examples sources, so that we can properly extract the code excerpts into the language-tour.md.
Adjusted all `<?code-excerpts?>` instructions to ensure that they are referring to the right source file and region.

Then did a refresh of all code excerpts.
@chalin chalin force-pushed the chalin-language-tour-code-sync-1101 branch from 0fa5032 to ee3d624 Compare November 8, 2017 01:23
@chalin chalin force-pushed the chalin-language-tour-code-sync-1101 branch from ee3d624 to edc38df Compare November 8, 2017 01:25
[Error]({{site.dart_api}}/dart-core/Error-class.html) or
[Exception]({{site.dart_api}}/dart-core/Exception-class.html).
</div>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kwalrath - I added and "info alert" based on @munificent's suggestion. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, but let's rewrite slightly to be more precise and avoid the unnecessary future tense:

Note: Production-quality code usually throws types that...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@kwalrath kwalrath left a comment

Choose a reason for hiding this comment

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

I'd like one small change, but otherwise LGTM. Thanks for doing this!

[Error]({{site.dart_api}}/dart-core/Error-class.html) or
[Exception]({{site.dart_api}}/dart-core/Exception-class.html).
</div>

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, but let's rewrite slightly to be more precise and avoid the unnecessary future tense:

Note: Production-quality code usually throws types that...

@chalin chalin merged commit 05cc6f3 into dart-lang:master Nov 8, 2017
@chalin chalin deleted the chalin-language-tour-code-sync-1101 branch November 8, 2017 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.libraries Relating to the Dart standard libraries. cla: yes Contributor has signed the Contributor License Agreement infra.structure Relates to the tools that create dart.dev
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants