On Taking Shortcuts, Part 1

A former colleague had a spiffy quote about good programmers and laziness, and I wish I could remember it right now.

The gist of it is almost axiomatic in the world of software development: when it comes to solving puzzles of the technical sort, a good programmer should look at the problem with a lazy eye and and a visceral aversion to repetitive tasks, in order to arrive at a solution that is efficient, and can be applied beyond the original challenge.

The simplest of examples will help to illustrate: if you’re given a list of words in a file, one per line, and asked to alphabetize them in the same format, you’re faced with a choice of methods and tools.  If there are fewer than 10 words, in the absence of an automated solution you might be inclined for example to do it by hand: cutting and pasting the words into the right order yourself.  The basic solutions break down quickly, however – and with a list of any more than a dozen words you find yourself turning to things like spreadsheet or database tools, where you can easily paste a word list into the program’s interface and use pre-built macros within to sort the list without (or with little) overhead.  Even as a novice programmer, you might find a way to create a rudimentary program that not only sorts the words but handles the file input and output for you automatically.

The cognitive benefits of the higher-order solutions, however, not to mention the time-saving ones, are best left to a separate discussion – given that I have a more concrete puzzle in front of me today that I’m trying to work out by writing it out and chronicling my stumbling towards a more interesting, non-brute-force approach.

Warning: some degree of familiarity with the Disqus platform and its APIs will be needed to find the rest of this discussion useful.

In an effort to make [our website’s] comments more portable, a few months ago we moved away from URL-based disqus-identifiers and began using tag-based ones instead.  The new identifiers match the ATOM ids used for each post.  Unfortunately, we also deployed this change on our desktop site without thorough regard for our mobile site, which at the time had a separate source for its JavaScript and therefore continued to use the old identifier format.  Two months later, having resolved the disparity, we find ourselves with over 600 “twin threads” – 600+ posts, published while the comment embedding scripts did not have matching disqus-identifiers, for which two Disqus threads were created: one was displayed on the desktop site, and a different one was displayed on the mobile site.

The understanding of the problem was clouded by a compounding issue: the comment-embedding script was not being excluded from pages during the preview of unpublished posts, so comment threads were being created with post URLs that did not match the SEO-friendly URLs given to posts once they were ultimately published (and were given different titles, too, but that’s a Disqus puzzle for a different day).

We thought we had a resolution in the bag because the Disqus dashboard provides a thread migration tool that can be used to merge threads.  Take each thread URL, we thought, append a comma, the new thread identifier we want to use, and upload the resulting CSV file to the migration tool.   Our 600+ twinned threads would, in one fell swoop, be combined into 600+ single conversations.  Just one snag – the migration tool requires a comma-separated value file – but our new disqus-identifier values, like our post ATOM ids, contain commas!

To be continued…

Leave a Reply

You must be logged in to post a comment.