Skip to main content

How to deal with long URLs in comments that exceed the 80 characters limit? [Resolved]

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:

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

Question Credit: Flux
Question Reference
Asked July 9, 2019
Posted Under: Programming
2 Answers

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.

credit: Kain0_0
Answered July 9, 2019

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.

credit: Berin Loritsch
Answered July 9, 2019
Your Answer