On commenting systems

Having been left to set up the discussion sections, I spent some time looking around and comparing what’s out there.  There are basic forums out there, akin to the BBS style of communication, and there’s even a nice site to compare them all ( forummatrix.org ).  Want it to be in a given language?  Free/opensource/proprietary/paid?  MySQL/Postgres/Oracle/SQLite/Flat file?  Do you want to support threaded comments?  You can search and filter by all these options (and more!).  So I looked for an existing forum that fit our needs – the biggest two being MySQL-based and a threaded commenting system.

However, it looks like the traditional forums don’t really do threading, not in the sense that the posts have a tree-like structure where a child post has a relation to the parent post; all of the threaded forums seemed to only implement threading as a visual feature and not a backend feature.  Not a big deal if you’re presenting comments in chronological order, but if you were to add weights to each node in the tree and wanted to present the tree sorted with respect to weight, then this model is useless.

An example of a typical forum with "threaded" discussion support. Posts are primarily displayed in chronological order.

I remembered other commenting systems that might work – Disqus came to mind, along with a few of their competitors.  I’ll just say that Disqus is the market leader for a reason, and leave it at that.  However, as of the last time I checked, their commenting system still displays posts in chronological order.  Yes it has threading, but it’s essentially like the screenshot above.

So then I asked myself “Self, what commenting systems out there do I like?”  I really like the Slashdot and Reddit comment trees.  They both allow for the most flexibility in terms of being able to have separate forked conversations as well as being able to sort by whatever metadata you define.  And as it happens, both have open-sourced their engines!

A threaded conversation on Reddit, with some visual candy provided by Reddit Enhancement Suite and Greasemonkey.

So I took a look…and it would be a significant amount of work to rip out the commenting engine and then integrate it into our own.  The alternative would be to set up a clone of Reddit or Slashdot and do low-level database queries to tie together the commenting engine with our own site – again, lots of work, and really messy to do.

So after talking with one of our advisors, I decided to just code it myself.  The initial backend work took about a day and a half (with minimal testing).  I’m happy to report that SQLAlchemy supports self-referencing relationships.  What this allows me to do is create a list of children for each parent post while still maintaining the object model when querying the database.  So for example, I can write something like this:

for rootPost in getPostsForDiscussion(discussion):
    for childPost in rootPost:
        childPost.data = "Ha, now all secondary level posts are mine!"
        childPost.parent.changes += 1

Which is pretty nifty.  Traversing the comment tree is now just a recursive function that acts on objects – no SQL needed.

1 Comment

  1. Chris says:

    Code snippets are so cool!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: