Monday, August 4, 2014

Just a quick code review

So, home from a refreshing month in Scandinavia and back to work. I decided I would start by reviewing what I'd done so far, a few thousand LOC in a couple dozen modules, just so it would be fresh in mind. Also, I have some internal documentation, mainly a spreadsheet listing all the public methods by module, and I knew it was out of date, so bring that current as I go.

But basically a quick code review, barely more than a read-through.

Yeah, no.

I started with fonts.py and colors.py, two simple modules that store global choices about, duh, font and color choices. Someday there'll be a Preferences dialog that will use these; for now they only ever set the programmed defaults. And it took over an hour each. Two, 250-line modules. But the prologs were out of date with the code, and the code wasn't in a logical sequence, and some comments weren't clear, and some things weren't being logged that should be...

I actually found one small bug, a typo, in colors.py. But mostly it was tidy tidy tidy format format format.

Then after lunch I tackled another simple module, dictionaries.py, which is the basic interface to spellcheck. It knows how to find the *.dic and *.aff files for Hunspell, how to make a list of available tags, and set up a spellcheck object given a tag.

Except that it needs to know where the user wants to look for those dictionaries. Back in version 1, there was only one place, extras/dicts, a folder of dictionaries I collected and distributed with the app. But that makes it hard for the user to introduce new dicts or custom dicts, because PPQT only looks in extras/dicts and that folder gets replaced if the user downloads a new version. So I've known all along that arrangement had to be broken for V2. There will be a Preference for where to look for extras itself, so the user can copy that to some other location where a new version won't clobber it. And a Preference for what folder to search for dict files, defaulting to extras/dicts.

Actually if the user wants to change dicts while editing a document, there's a two-level search, first in the document's folder, then in the chosen dicts folder. So you can drop a custom dic/aff pair in alongside the book file and we will use that, over another with the same tag in the dicts folder. Anyway, where was I?

Oh yeah, reviewing dictionaries.py. Which had a half-assed version of this logic, and which depended on the mainwindow module telling it where the extras folder was. That shouldn't be mainwindow's job. In fact, I realized, I should have a module that "knows about" the extras and dicts folders, the same way I have one that "knows about" colors and one for fonts. It's just another sub-section of Preference recording. So the next two hours were spent in creating this new module and its test driver, which is about half-done, and then I will be modifying mainwindow and dictionaries to use it.

Just a simple code review.

No comments: