Line Length (Max 80 Characters)
-
Rule: Lines of code SHOULD NOT be longer than 80 characters.
-
Reason: Keeping lines within 80 characters enhances code readability and maintainability. It helps developers easily view the code in various editors without horizontal scrolling.
-
Action for long lines: If a line exceeds 80 characters, it SHOULD be split into multiple lines of no more than 80 characters each. Alternatively, a comment can be added explaining why the line exceeds the limit.
Example of Splitting a Line:
// Good example: Split a long line into shorter lines
$someLongVariableName = someFunctionThatReturnsAVeryLongString(
'This is a very long string that needs to be split into multiple lines',
'to comply with the 80 characters per line rule.'
);