Skip to content

A long overdue refactor

February 27, 2010

For the last couple of weeks, my time on Witter has been spent refactoring the code to be more managable. And hopefully allow easier addition of things like multiple account support.

To be honest it was very ugly code, pretty much a single ‘monolithic’ code base, hacked together for speed of initial development. I knew that I would just be building up a big refactoring job, but I chose to do it that way anyway.

Why? Because I have very limited time in which to develop Witter, and it’s supposed to be fun. If I had tried to learn all the right ways to do things in python before I started, I probably would have gotten bored before it did anything. This way, I’ve had fun building up a bunch of usful function, and learned a lot of python as I went. So now I can refactor a little into some sensible architecture, and know when I’ve got it right, because all of the functions will work again.

I’m mostly done at this point. I’ve broadly split things into 3. The account object, which handles fetching and storing dfferent tweet timelines (dms,mentions etc), a gui object where I’m trying to put all the gtk-ness. And a controller object which ties the two together. I’m sure as I go on I’ll make further structural changes, hopefully each will be easier than the last. I still wouldn’t go so far as to say it’s good code, but it’s deffinately better than before.

Amongst my reworking I spotted a really stupid performance bug. At some point I decided that switching views, and checking what the current view is could be done by comparing the current treeview model, with the various ones it could be.
So:
If (self.treeview.get_model() == self.timeline):
Elif (self.treeview.get_model() == self.mentions):
Etc etc
what this meant was that I was comparing list store objects for eqaulity, where those objects are growing over time as more tweets arrive. And worse, for any view further down, it has to do 5/6 failed object compares before it gets there. This I suspect is responsible for witter slowing down over time for switching views.
I offer no particular excuse, I wasn’t thinking clearly, it probably seemed the easiest thing to do at the time.

In anycase, I have now declared some constant integer values, and set and compare these. Funily enough, computers are much faster at comparing small ints than they are at comparing large object structures.

So now it’s
curView = self.ui.getCurrentView()
If (curView == self.ui.TIMELINE_VIEW):
Elif (curView == self.ui.MENTIONS_VIEW):
Etc…

Now that things are mostly working again, I’m working on storing account objects nicely. I’d hoped to just pickle them to disk, but it seems there are limitations on what can be pickled. So I’ll have to look for some other options.

At this point I’m actually quiet keen to get witter to a point where I can put it on a back burner, and start playing with some of the other cool things people have been doing, such as face tracking with the front camera and text recognition. It is starting to feel like there are going to be some really cool capabilities added to the n900 over the next 6 months. Who knows, I may even put avatar support in witter just so I can focus on new things without on going requests for it.

About these ads
No comments yet

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

Follow

Get every new post delivered to your Inbox.

Join 95 other followers

%d bloggers like this: