Skip to main content
1 of 5
Shog9
  • 159.4k
  • 177
  • 1.2k
  • 1.2k

First off, Stack Overflow already has a URL shortening service: s.tk. It's mostly used internally and for ad campaigns, but it exists, we maintain it, and in rare cases it can be useful. Note that only a few people have access to create links using it, and that's probably not going to change for the reasons outlined in other answers and comments.

Second, Stack Overflow already offers short URLs for things like questions and answers: /q/[id] and /a/[id] are interchangeable and redirect handily to the question or answer associated with the ID. For internal links, this should be more than adequate: [this question](/q/319962) -> this question.

Finally, shorteners are completely unnecessary and actively harmful in ordinary Q&A. Links break frequently enough already; adding another layer of indirection just makes them harder to find and harder to fix, and adds yet another point of failure. You have 30,000 characters to play with here; that should be enough in most if not all circumstances. Let's face it: we don't have the markup structure to handle long articles in the way that (say) Wikipedia does; if your answer is exceeding 30,000 characters, you should probably break it up into multiple answers so that folks can find and link to the important bits. Or... y'know... learn to be slightly more concise. If I can fit my rambling into these constraints, I know you can.

That just leaves...

##Comments

Comments are always problematic. In this case, the slim 600-character limit can potentially create a real hardship that simply doesn't exist for ordinary posts. It's not surprising then that folks have used URL shorteners in comments for a long time.

...But what have they been used for? I sat down last night, determined to find out.

First, I collected a list of shortened URLs from comments on Stack Overflow, comments that hadn't been deleted and weren't attached to deleted posts. I collected only URLs shortened via bit.ly, goo.gl, and tinyurl.com. Here's the list of 25K+ URLs, if you're interested.

Turns out the 30 most common short URLs were:

Ok, so this is mildly interesting... Primarily because none of those URLs are even long; heck, several are just links to questions on Stack Overflow, which (as I noted above) can be linked to using SO's own built-in short-form URLs. Several of them have some value as easy-to-remember URLs, but it's worth noting that two of those have been broken for a year and a half. Nick did a big search & replace back then on Jon's behalf, but of course these were obscured by the damn short URL... In theory, whoever created those short links could've updated them to point to the blog post, but... They didn't. So a thousand+ links that no one can edit are just sitting there, broken.

But enough about the top 30; they only account for about 50% of the short URLs used in comments, and as usual there's a long tail... I wonder how much is being obscured by these mostly-opaque URLs?

Since I had LINQPad open anyway, I decided to see if I could find out where all these links were pointing to:

// world's crappiest shorturl resolver
// don't do this at home, kids: find someone who knows what they're doing 
// and ask 'em to teach you about rate-limiting and backoff
foreach (String url in shortened)
{
    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
    req.Method = "HEAD";
    req.AllowAutoRedirect = false;
    try
    {
        using (WebResponse resp = req.GetResponse())
        {
            var location = resp.Headers["Location"];
            var loc = "failed";
            if ( !string.IsNullOrEmpty(location) )
            {
                try
                {
                    loc = (new Uri(location)).Host;
                }
                catch (UriFormatException)
                {
                    loc = location;
                }
            }
            Console.WriteLine("{0}, {1}", url, loc);
        }
    }
    catch(WebException we)
    {
        Console.WriteLine("{0}, {1}", url, "failed");
    }
}   

A half hour or so later, I got some results to look at. Here are the top 30 hosts being directed to by those short URLs:

  • stackoverflow.com x2799
  • en.wikipedia.org x2230
  • php.net x2105
  • uk.php.net x1970
  • wiki.hashphp.org x1703
  • msmvps.com x1123
  • lmgtfy​.com x786
  • news.php.net x764
  • wiki.php.net x577
  • gcc.godbolt.org x521
  • github.com x497
  • failed x394
  • msdn.microsoft.com x271
  • meta.stackoverflow.com x249
  • developer.apple.com x222
  • codeblog.jonskeet.uk x202
  • www.google.com x166
  • www.tutorialspoint.com x142
  • developer.android.com x141
  • docs.google.com x141
  • www.dropbox.com x139
  • drive.google.com x137
  • code.google.com x129
  • blogs.msdn.com x93
  • groups.google.com x89
  • dl.dropbox.com x83
  • docs.oracle.com x81
  • gist.github.com x66
  • www.typescriptlang.org x65
  • www.lmgtfy​.com x64

Ok, so... This is kinda embarrassing. The most common use for URL shorteners in Stack Overflow comments is to point to posts on Stack Overflow. Rounding out the top three we have Wikipedia and php.net, neither of which are exactly famous for extremely long URLs. Seeing the long-banned LMGTFY in the top 10 isn't exactly a great feeling either. We do finally get to gcc.godbolt, a site that might legitimately need a shortener to be used in comments, at #10, two spots ahead of the not-quite-400 links that completely failed.

...About that... All those broken links to Skeet's blog were kinda bothering me. How many broken links are we hiding behind these short URLs?

I dropped the AllowAutoRedirect line from my crappy resolver above, and let it run while I went to bed and slept the good sleep of a decaying body in a broken world. And woke to yet another big list, which revealed that roughly 14% of these links are utterly broken. They'll likely never be fixed, most of them can't even be found, but there they sit. A little more grit in the machine.

In total, the compiler services identified by Ajedi32 in the other thread account for a hair over 3% of the total, with most of that being links to gcc.godbolt.org (which has a work-around in place now).

##Final thoughts

The classic argument against blocking stuff like this is that folks will inevitably find a way around it. This is true. A blacklist is a rough tool, and no doubt some number of people will just pick a more obscure shortener and go on with what they were doing, our efforts to dissuade them wasted.

In spite of this, I cannot look at these results and not feel ashamed for waiting so long to implement this restriction. These links - and comments that depend on them - are a blight, and by failing to dissuade folks from their use (which we can now see was nearly always unwarranted even in comments), we've allowed them to take hold.

Shog9
  • 159.4k
  • 177
  • 1.2k
  • 1.2k