[openlp-dev] Refactors and Code Quality

Raoul Snyman raoul at snyman.info
Tue Oct 10 03:06:49 EDT 2017


Hi everyone,

In order to get our QtWebEngine changes into OpenLP, we've needed to do 
some refactoring. This weekend, I decided to try to refactor smaller 
parts at a time and get them into trunk before WebEngine hits trunk in 
order to make the set of changes smaller. Unfortunately, this means that 
I ended up shaving the yak[0] for most of the weekend.

There are tons of circular (or cyclic) imports, and a number of 
incorrect imports (e.g. importing "translate" from "lib" instead of 
"common" where it was defined).

With this in mind, I've started a page on the wiki to explain, track and 
discuss how we should be doing things: 
https://wiki.openlp.org/Development:Structure

A quick overview of some of the changes I made:

- no more imports into openlp.core.common. If you need Registry, get it 
from openlp.core.common.registry, if you need Settings, import it from 
openlp.core.common.settings
- translation/internationalisation code has been (somewhat) centralised 
into openlp.core.common.i18n
- check_directory_exists(), which was basically a "mkdir -p" has been 
changed to "create_paths" and can take multiple Path objects. It has 
also been moved to openlp.core.common.path

I have a few more refactors up my sleeve.

Also, I ran into a LOT of tests that were mocking objects incorrectly or 
in the wrong places. Some tests were not being run due to naming 
conventions or duplicated names, and some tests just made no sense at 
all and weren't actually testing what they claimed to be testing. If you 
are in any way unsure of how to test something, or what to test, PLEASE 
talk to me. I'm more than happy to explain how to mock, how to write 
tests, what good tests look like and and help you figure out how to test 
what you want tested.


[0] 
https://www.hanselman.com/blog/YakShavingDefinedIllGetThatDoneAsSoonAsIShaveThisYak.aspx

-- 
Raoul Snyman
+1 (520) 490-9743
raoul at snyman.info


More information about the openlp-dev mailing list