I don't understand this part of php's PSR-2 convention:
The soft limit on line length MUST be 120 characters; automated style checkers MUST warn but MUST NOT error at the soft limit.
Lines SHOULD NOT be longer than 80 characters; lines longer than that SHOULD be split into multiple subsequent lines of no more than 80 characters each.
I thought "soft limit" meant "try to stick to this limit, but a few characters extra are not a problem". But then I read the second line and now I don't get it.
Traditional line length research, limited to print-based text, gave a variety of results, but generally for printed text it is widely accepted that line lengths fall between 45 and 75 characters per line (cpl), though the ideal is 66 cpl (including letters and spaces).
Deprecated - As of 2019-08-10 PSR-2 has been marked as deprecated. PSR-12 is now recommended as an alternative. This guide extends and expands on PSR-1, the basic coding standard. The intent of this guide is to reduce cognitive friction when scanning code from different authors.
The PHP Standard Recommendation (PSR) is a PHP specification published by the PHP Framework Interoperability Group (PHP-FIG). It serves the standardization of programming concepts in PHP. The aim is to enable interoperability of components. The PHP-FIG is formed by several PHP frameworks founders.
Ruder concluded that the optimal line length for body text is 50–60 characters per line, including spaces (“Typographie”, E. Ruder). Other sources suggest that up to 75 characters is acceptable.
Overview 1 Code MUST follow a “coding style guide” PSR [ PSR-1 ]. 2 Code MUST use 4 spaces for indenting, not tabs. 3 There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less. More items...
There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less. There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of use declarations.
There MUST NOT be a hard limit on line length. The soft limit on line length MUST be 120 characters. Lines SHOULD NOT be longer than 80 characters; lines longer than that SHOULD be split into multiple subsequent lines of no more than 80 characters each. There MUST NOT be trailing whitespace at the end of lines.
This guide extends and expands on PSR-1 , the basic coding standard. The intent of this guide is to reduce cognitive friction when scanning code from different authors. It does so by enumerating a shared set of rules and expectations about how to format PHP code.
It's pretty easy:
There is no hard limit in PSR-2.
The MUST (NOT) refers to automated style checkers, not to you as a programmer.
Also note the section that says that no error
should be issued when exceeding the soft limit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With