How to Handle Long URLs in Comments Exceeding 80 Characters

coding-standardscoding-stylecommentsurl

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?

Best Answer

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.