Skip to main content

When it comes to line wrapping, what is meant by hard and soft limits?

  1. Hard Limit: This is a strict boundary for the line length. No line of code should exceed this limit under any circumstances. If a line reaches this limit, it must be wrapped to the next line. It's a non-negotiable rule, and it ensures that the code remains readable and maintainable. In many coding standards, you might find a hard limit of 80 or 120 characters.

  2. Soft Limit: This is a more flexible guideline. You should generally try to keep lines within this limit, but it's not a strict rule. If a line slightly exceeds the soft limit, it's usually considered acceptable as long as it doesn't reach the hard limit. The soft limit encourages developers to keep lines concise but allows for some flexibility when needed.

For example, if you have a soft limit of 80 characters and a hard limit of 100 characters, you'd aim to keep lines under 80 characters, but you wouldn't absolutely need to wrap them until they reach 100 characters.

PHPstorm has setting for these. How does a "soft limit" work then?

The soft limit for line wrapping works as a visual guideline rather than a strict rule.

Here's how it functions:

  1. Visual Guide: The soft limit in PHPStorm is represented by a vertical line in the code editor. It's a visual cue to show you where you should ideally wrap your lines, but it doesn't force you to do so.

  2. Flexibility: You can exceed the soft limit without any warnings or errors. It's more of a suggestion rather than a requirement. It allows you to write code that's slightly longer than the soft limit if it makes sense for readability or other reasons.

  3. Configuration: You can set the soft limit in PHPStorm by going to File > Settings (or Preferences) > Editor > Code Style, and then choose the language (e.g., PHP). You'll find an option for "Right margin (columns)" where you can set the soft limit.

  4. Integration with Hard Limit: If you have a hard limit set up in your coding standards (like through PHPCS), PHPStorm won't enforce it directly at the soft limit line. The soft limit is purely a visual guide, while the hard limit would be enforced through your coding standard tools.

So, in essence, the soft limit in PHPStorm is a friendly reminder to keep your lines concise, but it won't scold you if you step over the line a bit. It's all about keeping that code clean and readable, but with a bit of leeway for those special cases.