0
magis
8y

Is it bad practice to write a line of code longer than the screen, meaning you need to scroll on the X? I've had one lecturer who hates it and one who doesn't give a shit and I'm not sure of the standard

Comments
  • 0
    If it's more efficient than writing multiple lines go for it. Most languages provide syntax such that you can newline and tab inwards and they'll recognize multiple lines as one as long as there's no semicolon (or whatever your end line is, if your language is Python, then I think you're screwed).
  • 0
    The 80 character limit mainly seems opinion based, but you may find that it depends more on if you're sharing code with a team. Look to see if there are standards for your language, team or projects that you want to contribute to and use that as a basis.

    Ultimately, besides that, if it works for you, do it, and worry more about the actual code :)
  • 1
    I think it's more a question of practicality. Don't make an obscenely long line, but let it run long if it makes sense.

    @lurch, Python allows multiple lines, and even escaping line breaks in long strings, which is nice when writing SQL in your code.
  • 1
    Ah, SQL can be great fun for line length! One of the reasons I love ORM packages :)
  • 1
    Some editors wrap long lines. All of Jetbrains IDEs I think and probably others do too. Everybody wins.
  • 0
    @beningreenjam ReSharper does it for you as well.

    it's a readability thing. Some prefer it, others don't care.
  • 0
    I once read that the average person's ability to easily understand a line of text starts to drop after 10 standard word lengths.
    That said, I would keep lines under 120 characters for the people who still print code (happens a lot in academia).
    Or, barring that, I wouldn't write lines that are so long that you have to scroll. It gets aggravating really quickly, especially in large code bases.
  • 1
    @lreading isn't Resharper a Jetbrains product as well?

    Can I be entirely justified in loving those guys? 🙌🏻 🙌🏻 🙌🏻
Add Comment