I generally try to adhere to the 80 character limit for each line of code to satisfy my colleagues, to satisfy the linting tools, and to maintain an image of professionalism when random people look at my code.

However, sometimes I have URLs that I wish to embed in the comments, and some of these URLs are very long (exceeding 80 characters). Exaggerated example: https://github.com/django/django/blob/42b9a23267f14be39b9b00958e18d5746783208e/django/contrib/auth/management/commands/changepassword.py#L17-L21

How do professional software engineers deal with this problem? Do they make an exception to the 80 characters rule for long URLs?

  • There is no official rule that says URLs have a character limit. The practical limit by most browsers is much longer than you will see in real life. If you want to display it on a page, then you probably need to put it in a DIV that has horizontal scrolling. Commented Jul 5, 2019 at 2:53
  • 1
    @BerinLoritsch The issue is not about character limits for URLs. The issue is that long URLs force the programmer to break the 80 character limit on source code lines if those URLs were to be placed into comments in the source code.
    – Flux
    Commented Jul 5, 2019 at 2:55
  • 3
    80 character limit on source code? Seriously? That sounds extremely dated, from the VT-100 era. If it's more readable on one line, it should be on one line, regardless of length.
    – John Wu
    Commented Jul 5, 2019 at 3:01
  • 3
    Code style rules and guidelines are fine, but we shouldn't be slaves to them. If some rule does more harm then good, just ignore it (and if possible, configure your tools to make exceptions). P.S. "random people look at my code" - like who? If they are programmers, nobody is going to be like "Oh! This one line is longer than 80 characters! So unprofessional!". That's ridiculous. If they are not programmers, it's all hieroglyphics to them. Commented Jul 5, 2019 at 3:15
  • 1
    My rule is that I do diffs side by side, and I want to see two lines side by side on the screen. I tend to stay below 100 characters, I don't care if it's a bit longer, I reformat if it is a lot longer. I've seen 400 character lines and that I consider ridiculous.
    – gnasher729
    Commented Jul 23, 2019 at 10:31

3 Answers 3


Follow an arbitrary rule they said.

It'll be fine they said.

We have discovered the source of all perfection they said.

There can never be anything that breaks the rules they said.

They obviously never wrote code...

Having a formatting guide is great, it helps people answer the same question with a predictable answer.

But - and there is always a but - you are writing code, because it has never been needed to be written in this way, for this purpose, before.

Therefore it is new, it is novel (even if it is an unoriginal copy, paste, and rename), and they have never seen it before.

How could they have written a 'rule' that is universally applicable without having considered the entire universe? Hint - They could not have...

At its best this 80 character limit might be a generally useful rule of thumb. And I can see that it does have some basis in print media, and well formatted documents.

However you have forgotten something - utility. Which I presume to be the original intent of the rule of thumb 80 character limit.

  • The url does not work if you manually line-wrap it by inserting needless whitespace.

Now which one is more professional for a news-columnist, a book author, or a web designer? Probably line-wrapping the link at about 80 characters, using the conventions and standards of their medium, to clue the reader into, or using the technologies available to present the link in a utilisable manner.

Which one is more professional for a programmer?

If you had a choice of hiring between two programmers:

  • one who pretty formatted the url,
  • and one who did not.

But equal in every other way. Which one would you hire?

I would hire the one who did not, for they were professional enough to understand the goal, by not making life harder for the next developer.

  • 1
    So long as the intent of adding this comment is to make it something people can copy and paste into a browsers URL then absolutely yes. Respecting how it'll be used over following advice written by people who weren't thinking of this is the professional thing to do. If this causes your team consternation then just update the style document with this exception. Commented Jul 5, 2019 at 14:59

The origin of the 80 character limit was from an era where screens could only handle 80 characters, and that was only if you had something new enough. It lasted a little longer because early printers could only handle 80 characters with print that was legible and 1 inch borders.

Now, our screens can handle well over 100 characters per line, and the only reason to limit is what can reasonably fit on a printed page. For that reason most coding guidelines have been updated to 100 or 120 characters per line. The primary reason for that is for people who actually print out code. I still do occasionally when I am familiarizing myself with a complex piece of legacy code I need to understand.

However, in the days of 1080p monitors being the baseline norm, and printing code is something that happens very rarely, the only limit for the character limit for a line of code is what is readable.

There are other questions you have to ask yourself:

  • Why are URLs in your source code to begin with?
    • They change often enough that you should really consider making them configuration items
  • Are there other items you are making part of the source code that will force you to recompile if the world around you changes?
  • Are there better ways to deal with those URLS?
    • If they are in comments to reference something outside your project, what about the project wiki? Then you can click on it and the URL will work.
    • Do the URLs actually help understand the code when you are reading the comments? probably not.
  • The URL is in a comment, so making it configurable… well, it would be an amusing monstrosity, as long as you don't have to use it. And the links by themselves are unlikely to be useful, as they only point to a fuller explanation / whitepaper, you have to actually follow them. Commented Jul 5, 2019 at 14:31
  • Questioning the reason for the URLs being in source is not helpful to answering the question, which is purely about adherence to a given styling rule.
    – GHP
    Commented Jul 5, 2019 at 16:41
  • It's always useful to question why you do things. That's how we grow. Bottom line is the styling rule is too restrictive. I've rarely found URLs in comments to be useful, or even still live when I attempt to use them. Commented Jul 5, 2019 at 19:33
  • FWIW, the 120 characters per line comes from usability studies that show that it takes longer to comprehend lines that are excessively long. Our ability to skim lines and pick up the gist of what's going on is hampered by increasingly long lines.
    – user53019
    Commented Jul 9, 2019 at 2:33
  • @GlenH7 But those studies are referring to people reading lines of text written in plain language, not lines of code. If I have a line of code that is simply a method invocation, and there's 100-200 characters of parameter values that come after it, I do not always need to read/comprehend all those values to understand what the line of code is doing. URLs are like this as well, I do not need to read the entire URL to understand what it is.
    – GHP
    Commented Jul 11, 2019 at 15:28

Whether your limit is 80 or 100 or 120 characters, you will have cases exceeding it.

But in most languages it is possible to split string literals over many lines. In C quite trivial: "This " "is " "a " "single " "string " "literal." If your editor does its own formatting, figure out how to write the code so its nicely formatted even after the editor tries to reformat it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.