Sunday, 1 December 2013

Source code structure evolution

Kadu source code evolved over years. Directory structure evolved along with it. It all stared with single code directory (named kadu), single autotools one (named admin) and a few with libgadu library sources. Above chart shows this evolutions as number of directoriesd use for different categories during last 12000 commits.

Lets start with boring ones: varia line shows how many icon and sound themes we had. During development some were added (like modern Adium themes) and some removed (because of licence issues or pure ugliness).

Modules and plugins lines shows how many code was kept our of core source for modularity. First modules emerged just after a few years: autoresponse, voice, sms... They were responsible for most of new directories for a very long time. Big switch from modules to plugins shows that we didn't think that all of them were worth the transition (there is subtle technical difference between module and plugin in Kadu terminology).

Count of classes in each files and files in kadu (now kadu-core), where core source is kept, directory was growing very fast from the beginning to the point where code was almost unmanageable. So the Big Split era was started. Each "business" object family got it own directory (buddies, contacts, chats, accounts, avatars, status and so on...). GUI code was split between widgets and windows and separate directories for configuration were created. This is all represented by core line on above chart. Lately speed of expanding this structure increased - some widgets got whole directories instead of just files. Number of support classes for handling ChatWidget (12)ChatWindow (7) and GroupTabBar (4) increased so much that it stopped to make sense to keep them with other widgets code. It all happens for our believe in Single Responsibility Principle.

For me it is very important to keep everything as clean as possible. When your code grows in lines be sure it also grows in number of files and number of directories. Keeping too much code in one class, too much classes in one file or too much files in one directory will eventually lead to Big ball of mud architecture. It is very easy to smuggle 1000 lines of code to a place that already has 10000 than to add small method to small class. Keep good structure on every level - it will force everybody to think deep about new code placement.

No comments:

Post a Comment