[DependencyInjection] Implementation/usage docs #6218
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The DependencyInjection component lacks usage documentation for implementors.
For starters, I've added documentation for service scopes and synthetic services, which I had to search the net for, and only by coincidence, I thankfully found some pretty essential answers in a forum thread.
Extracted from https://groups.google.com/forum/#!msg/symfony-devs/Uq6dC09O8cg/G6aOeGVaQ-IJ
It's not exactly clear what the best place for these docs inside of Symfony is, so I'm putting this up for initial review and discussion.
In general, my stance is that code documentation should be split into the following areas, which each have their own audience and thus require different content and details:
Inline comments: Clarify the technical reasons for why something is done exactly in the way it is done. Do not state what is being done, unless the code is complex or if it is not obvious.
Audience: Developers who may touch the code in the future in order to change it. If they cannot figure out why code was written in the way it was, they will introduce regressions. Tests cannot protect against that.
Function-level phpDoc: State exactly what the method is doing, and what it does not. Clarify when the function should be used, and under which circumstances it is invalid to use it. Clarify which parameters exist, if necessary their syntax/format, and most importantly, clarify what their purpose and effect is.
Audience: Implementors/users who already know (or [mistakenly] believe) that they want or need to use a function.
Exception: If a method is defined by an interface, the method's phpDoc should live on the interface, instead of the implementation. The implementation should not duplicate the interface documentation.
Class-level phpDoc: Explain what the purpose of the class is (and what is not its purpose), who or what is responsible for instantiating it, how the class and its methods are typically supposed to be used, and how its functionality is involved in the overall big picture.
Audience: Implementors/users who are trying to make sense of the architectural design and evaluating how to properly implement the component into their own, custom application.
Component-level Readme: Provide a high-level introduction to describe the component's purpose, features, and functionality, including simple/common examples. Users seeking for advanced implementation and usage instructions expect to find details in phpDoc, which shouldn't be contained in the Readme, since that has a too high chance of becoming out of date.
Audience: First-time evaluators of a component, who intend to use it but don't have the slightest idea on how yet. The file is read only once by a single person.
Online manual: Explain a component's purpose and features with typical use-case scenarios, focusing on how-tos, tutorials, and examples. Focus on content like help and examples, which cannot or should not be part of the source code.
Audience: Raw/first-time evaluators of a component, who either do not know yet that they want to use it, or who already attempted to use it, but ran into use-case/scenario-specific problems/questions.
Due to this, my proposal is to add this documentation to the
Definition
class, which is essentially the (second) place where I expected to find it, after starting my dive inContainerBuilder
. (Due to that, I first considered to add it there, but AFAICS, that class needs an entirely different explanation and amount of documentation to clarify its differentiation fromContainer
and relation to involved interfaces and classes likeDefinition
.)Lastly, I'm perfectly aware that the above list of documentation areas goes way beyond this issue, but alas, one always needs to start somewhere ;)
What do you think?