Creating quality software · 2008-09-13 15:56 by Wladimir Palant
It got quiet around Adblock Plus again after some great strides towards Adblock Plus 0.8. That doesn’t mean however that nothing is happening, on the contrary. However, when I was about to add another small user interface change (one of the few that are still due for 0.8 release), I noticed that this is way more complicated than it should be. Why?
You have to look at the history of Adblock Plus. Most of the original code was written on two days in December 2005. Goal was to create a cleaned up version of Adblock, and I was in a big hurry because I was afraid that Adblock project maintainer would soon loose interest again and go back to Adblock 0.6 (which was never released). There was not much time to do code design, but there also was no real need — that original code only had the features you would find in Adblock, and it was a very simple extension (even after it was released a little later with some additional features, it was only 25 kB as opposed to the 64 kB of the then-current Adblock version).
And where are we now? Yes, much has changed. My original code was never released as Adblock, instead I had to fork the project. The filters are no longer a plain list of strings stored in prefs.js where there are only two types of filters (simple filters and regular expressions). There are far more options now (whitelisting, comments, element hiding, filter options etc), there is also various metadata stored for each filter (enabled/disabled, hit count etc), filters are organized hierarchically (mostly due to filter subscriptions), and instead of bloating prefs.js with all that data we now have our own storage file with its own storage format. And rather than matching each URL against all filters, different filter types are applied in a different way and better (and more complicated) matching algorithms are used. The code size almost quadrupled. And still, the core Adblock Plus code remains almost as unstructured as it was at the very beginning.
You see the problem? We got to the point where changing anything in the core is very risky and requires many (sometimes non-obvious) considerations. And while so far regressions in Adblock Plus releases were very uncommon (largely thanks to the efforts of the development build users), this isn’t a good situation to be in. So after we have been largely rethinking Adblock Plus user interface for Adblock Plus 0.8 I decided to go a step further and redesign the core code as well.
The new code defines classes instead of using in-line objects for data. It makes use of inheritance to define properties similar to multiple classes. It divides responsibilities cleanly between components instead of requiring that each code part “knows” all the details. It has well-defined and documented interfaces that these components can use to communicate. And it has automated testing to make sure that bugs that happen in unlikely situations are still caught.
Of course, the increased use of object orientation comes at a cost. Memory use didn’t change but performance got somewhat worse again. But I think it is very well worth it, especially if you consider that it will be easier for people to contribute.
If you look at the source code repository, this code isn’t checked in yet. Reason is that while the core code already works well, some of the user interface still needs to be adapted (especially the Preferences dialog). Also, while there are now almost 500 automated tests, I still need tests for subscription downloads which have a large number of possible edge cases. But the work is progressing. And I will look into having JSDoc documentation of the core code published here and updated automatically.
Commenting is closed for this article.