phpDocumentor / fig-standards

Standards either proposed or approved by the Framework Interop Group
http://www.php-fig.org/
Other
361 stars 85 forks source link

There should be a recommendation regarding line feeds between tags. #107

Closed Fleshgrinder closed 9 years ago

Fleshgrinder commented 9 years ago

This is actually something that I always wondered about and apparently many others do to, e.g. FriendsOfPHP/PHP-CS-Fixer#55.

Something that I often see in many projects (e.g. Symfony) is that people tend to align their stuff like this:

/**
 * Lorem Ipsum
 *
 * ... dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
 * penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu,
 * pretium quis, sem. Nulla consequat massa quis enim. 
 *
 * @param string|null $something             Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
 *     ligula eget dolor. Aenean massa. Cum sociis ...
 * @param bool        $parameterWithLongName Lorem ipsum...
 * @param string      $foo                   Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean ...
 *
 * @return int Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.
 *
 * @throws \InvalidArgumentException Lorem ipsum...
 */

This is actually something I never understood, because it requires contributors to constantly realign the documentation. Additionally it does not really support readability to have everything align in a single line. In my projects I always put the description on the next line indented with two/four spaces (depending on the coding styles indent level) to avoid this and of course to highly increase readability (compare for yourself):

/**
 * Lorem Ipsum
 *
 * ... dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
 * penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu,
 * pretium quis, sem. Nulla consequat massa quis enim. 
 *
 * @param string|null $something 
 *     Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum
 *     sociis ...
 * @param bool $parameterWithLongName
 *     Lorem ipsum...
 * @param string $foo
 *     Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean ...
 * @return int
 *     Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.
 * @throws \InvalidArgumentException
 *     Lorem ipsum...
 */

You might know already that I am a fan of consistency and reasoning, so we might find terms here to give a recommendation for people who are interested in such details. Note that this should only be a RECOMMENDED and not at all change anything in the definition of the PSR (well, maybe the formatting of the examples).

I also hope that we can start a discussion here without arguments like “but most people are doing this or that,” because I would prefer reasons that are really comprehensible.

jacobsantos commented 9 years ago

I believe others have already stated that such a recommendation won't be made in the PSR. The PSR isn't a standard guide for how to write phpDoc. This could made per project basis. I think the hardest part is not bikeshedding the standard and having devs reject it on the basis of arbitrary whitespace recommendation.

I usually use 2 spaces, but I do see how 4 spaces can appear better.

I will say that I would rather see the examples use some best practices, but for every person that uses a new line, one doesn't. For every one that uses 2 spaces to tab, there is one that doesn't and another that uses 4 or 6. If you took a survey, you would find enough projects that are members that probably don't use newlines.

jacobsantos commented 9 years ago

Take for example this suggestion to limit the lines to 80 characters. Would you agree with this?


/**
 * Lorem Ipsum
 *
 * ... dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget
 * dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient
 * montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque
 * eu, pretium quis, sem. Nulla consequat massa quis enim. 
 *
 * @param string|null $something 
 *     Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
 *     ligula eget dolor. Aenean massa. Cum sociis ...
 * @param bool $parameterWithLongName
 *     Lorem ipsum...
 * @param string $foo
 *     Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean ...
 * @return int
 *     Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
 *     ligula eget dolor.
 * @throws \InvalidArgumentException
 *     Lorem ipsum...
 */

Maybe not. There are those that won't. If you did, would it be 80 soft limit or hard limit? What about 100 characters like yours seemed to be?

Going down this road would lead to madness. Who is right? Does it really matter? Having code conform to a standard is good, but is it really necessary for docblock documentation?

mvriel commented 9 years ago

This PSR is intended as a technical description of the PHPDoc format. Since whitespace between tags is not meaningful for the way DocBlocks are parsed I have intentionally omitted such recommendations.

If people have a need for a standard on how to format their DocBlocks then I recommend starting a new proposal for a PSR that describes this.

Fleshgrinder commented 9 years ago

As I said, I am not thriving for a standardization, only a recommendation. This is also important for the examples that are included in the PSR. For instance, why do we have new lines between tags in the examples? No explanation is given and people are left in the dark with their questions. The only possibility for them would be to search the issues that might go missing at some point in history.

We need clear guidelines for the examples and we need to document them!

It is not about defining a standard for spaces, line lengths, or anything. I hope you understand/spot the difference and the need for it.

PS: 80 characters would actually make sense for the PSR because the PSR website and GitHub have a very limited viewport that has issues with 120 characters (see example code in this issue).

jacobsantos commented 9 years ago

While I think a docblock style guide is good. I think it should be made in a few years after enough projects have went over different formats, and a best practices for docblocks could be created.

I'm not a FIG member, so it isn't my decision. The only interest I have is that I write phpdoc comments, like phpdoc comments and I hope that the standard is good.

Fleshgrinder commented 9 years ago

I think PHPDoc is old enough to justify the formatting of the examples in the PSR and thus give an informal pointer on how projects could write theirs. Currently it is just random.