Skip to content

Conversation

@creativecreatorormaybenot
Copy link
Contributor

@creativecreatorormaybenot creativecreatorormaybenot commented Feb 14, 2021

This PR aims at improving the docs for lifecycle methods in AbstractNode, Element, and State.

For these methods, it is usually crucial that the paradigm of calling the inherited method first or last is followed. The reason for that is that there might be some preliminary setup or disposal of resources that has to happen first/last.

Not following it is an easy source of error when adding mixins or not looking up all ancestor overrides. I assume this is also why at this time the notes are already present in State - I simply added them to AbstractNode and Element as well.
I noticed that some people writing RenderObject subclasses are not following it, so establishing a paradigm via the docs should be beneficial.


There is no issue for this because this is just my attempt at improving the docs - maybe my assumptions are wrong after all.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Feb 14, 2021
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@google-cla google-cla bot added the cla: yes label Feb 14, 2021
/// same [owner].
///
/// If you override this, make sure your method starts with a call to
/// `super.attach(owner)`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The Flutter API docs voice avoids telling the reader what to do -- because we don't know if the reader wrote the code they care about, or if they are just trying to learn how someone else's code works. So we use the passive voice or talk about the code itself, without reference to the reader or the programmer, as in "Implementations of this method should start with a call to the superclass, as in `super.attach(owner)`.".

Copy link
Contributor

Choose a reason for hiding this comment

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

(comments along these lines apply below as well)

Copy link
Contributor

Choose a reason for hiding this comment

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

(we should fix the existing text too)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Hixie Thanks, makes sense! Adjusted it in the new and existing docs.

@Hixie
Copy link
Contributor

Hixie commented Feb 14, 2021

(test exempt: documentation changes)
(that said, bonus points if you can write a test to catch patterns like using "you" in the API docs...)

@creativecreatorormaybenot
Copy link
Contributor Author

creativecreatorormaybenot commented Feb 14, 2021

bonus points if you can write a test to catch patterns like using "you" in the API docs

@Hixie
I conducted some research for this and found that "you" is not mentioned excessively (which is a good start). Occurences of "you" (word) in lib/:

Screen Shot 2021-02-14 at 21 31 23

The number is a bit higher than I thought after initial search in path, however, there are of course many duplicate occurences as it is docs.

Many occurences are indeed violations of the rule, which would make writing a test feasible.

However, there are also a lot of occurences like the following:

/// * [Theme.of], which allows you to select colors from the current theme
/// rather than hard-coding colors in your build methods.

In this case, I do not think that "you" really violates the voice policy because it is more of a passive "you" in this case.
I have no idea how I would fit these semantic exceptions into a test case.

Furthermore, I do think that using "you" in general should be forbidden because it would likely limit the language in the docs beyond the voice.

@Hixie
Copy link
Contributor

Hixie commented Feb 15, 2021

Wow thanks for looking into that. I agree that that's a little beyond the scope of this PR! :-)

Copy link
Contributor

@Hixie Hixie left a comment

Choose a reason for hiding this comment

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

LGTM

@fluttergithubbot fluttergithubbot merged commit c51fba9 into flutter:master Feb 18, 2021
gnprice added a commit to gnprice/flutter that referenced this pull request Jul 16, 2023
Fixes flutter#115525.

On [AbstractNode.detach] and its two progeny [RenderNode.detach]
and [Layer.detach], the docs said both to call the inherited method
before detaching children, and to end by doing so.  The former
advice is what's enforced by an assertion in the base implementation,
so cut out the other.

The corresponding [attach] methods redundantly said twice to
call the inherited method first, so cut the redundancy.
Leave in place the version more recently added (in flutter#76021), because
that PR shows the old version must have been easy to overlook.
auto-submit bot pushed a commit that referenced this pull request Jul 19, 2023
…#130688)

Fixes #115525.

On [AbstractNode.detach] and its two progeny [RenderNode.detach]
and [Layer.detach], the docs said both to call the inherited method
before detaching children, and to end by doing so.  The former
advice is what's enforced by an assertion in the base implementation,
so cut out the other.

The corresponding [attach] methods redundantly said twice to
call the inherited method first, so cut the redundancy.
Leave in place the version more recently added (in #76021), because
that PR shows the old version must have been easy to overlook.
LouiseHsu pushed a commit to LouiseHsu/flutter that referenced this pull request Jul 31, 2023
…flutter#130688)

Fixes flutter#115525.

On [AbstractNode.detach] and its two progeny [RenderNode.detach]
and [Layer.detach], the docs said both to call the inherited method
before detaching children, and to end by doing so.  The former
advice is what's enforced by an assertion in the base implementation,
so cut out the other.

The corresponding [attach] methods redundantly said twice to
call the inherited method first, so cut the redundancy.
Leave in place the version more recently added (in flutter#76021), because
that PR shows the old version must have been easy to overlook.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants