Am 10.11.2022 um 03:08 schrieb Tim Starling:
Clutter, because it's redundant to add a return type declaration when the return type is already in the doc comment. If we stop requiring doc comments as you propose, then fine, add a return type declaration to methods with no doc comment. But if there is a doc comment, an additional return type declaration just pads out the file for no reason.

I agree that we shouldn't have redundant doc tags and return type declarations. I would suggest that all methods should have a return type declaration, but should not have a @return doc tag unless there is additional info to be provided. For example, when the declared return type may is array, we may still want to document @return string[] or @return array<int,PageIdentity>.


The performance impact is measurable for hot functions. In gerrit 820244 I removed parameter type declarations from a private method for a benchmark improvement of 2%.

This raises an interesting issue, one that has bitten me before: How do we know that a given method is "hot"? Maybe we should establish a @hot or @performance tag to indicate that a given method should be optimized for speed. IsĀ  it possible to make phpcs smart enough that it would apply different rules if a method is marked as @hot? In that case, perhaps the use of type hints for parameters and the return type should be discouraged rather than encouraged.

--
Daniel Kinzler
Principal Software Engineer, Platform Engineering
Wikimedia Foundation