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.
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!
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 commit(childpost)
Which is pretty nifty. Traversing the comment tree is now just a recursive function that acts on objects – no SQL needed.