What is a line length "soft limit" and how do I interpret this in the PSR-2 convention?

ChocoDeveloper picture ChocoDeveloper · Feb 19, 2013 · Viewed 8.9k times · Source

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.

Answer

ThiefMaster picture ThiefMaster · Aug 28, 2013

It's pretty easy:

  • 0-80: Always ok
  • 80-120: Acceptable (if there's a good reason for it, e.g. a string where wrapping it would be ugly)
  • 120+: Lint tools, IDEs, etc. MUST show a warning (but never an error!) since the line might be ugly/unreadable/...