-
Notifications
You must be signed in to change notification settings - Fork 701
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
Setup language-tour.md for auto code-refresh from examples/language-tour sources #414
Conversation
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.
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'; |
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.
Why adding types?
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.
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.
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 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?
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 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) |
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.
....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.'; |
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.
...and here...
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.
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".)
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.
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.
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.
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]; |
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.
Ditto: IMHO, this type annotation helps emphasize that we are in the section talking about Lists.
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 would just leave var
.
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.
PTAL at the latest commit. I've removed only two type annotations: for each of the examples of 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. |
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. |
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 comments. I don't feel strongly about it but I would suggest removing the added type annotations.
examples/analysis_options.yaml
Outdated
- language-tour/reference/*.dart | ||
- library-tour/reference/*.dart | ||
- library-tour/async-await/bin/main.dart | ||
# exclude: |
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.
Why not just remove these?
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.
Gone
{% prettify dart %} | ||
// Define a function. | ||
printNumber(num aNumber) { | ||
void printNumber(num aNumber) { |
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 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?
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 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
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 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.
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
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.'; |
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.
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]; |
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 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.
0fa5032
to
ee3d624
Compare
ee3d624
to
edc38df
Compare
[Error]({{site.dart_api}}/dart-core/Error-class.html) or | ||
[Exception]({{site.dart_api}}/dart-core/Exception-class.html). | ||
</div> | ||
|
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.
@kwalrath - I added and "info alert" based on @munificent's suggestion. WDYT?
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, but let's rewrite slightly to be more precise and avoid the unnecessary future tense:
Note: Production-quality code usually throws types that...
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.
Done
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 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> | ||
|
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, but let's rewrite slightly to be more precise and avoid the unnecessary future tense:
Note: Production-quality code usually throws types that...
Reviewers:
You'll probably want to focus your review efforts on
src/_guides/language/language-tour.md
while ignoring whitespace diffs: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:
examples/language-tour
: changed code excerpt marker syntax fromBEGIN
/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.