mkchromecast
mkchromecast copied to clipboard
Add encapsulation, reduce code duplication, and simplify cascading logic
This bug covers three classes of deficiencies in mkchromecast:
-
It uses a lot of module-level code (that is, code that takes action immediately upon
import
, and that cannot ever be triggered again after that import). Among other things, this style of code is impossible to unit-test, and also makes it difficult to make conditional use of functionality that is defined in those modules. -
A lot of code is duplicated both within single modules and across modules (for instance, code to reset the state of casting is duplicated in slightly different forms across 6 different modules)
-
A lot of multi-dimensional policies (that is, where two or more factors decide which outcome to execute) are implemented as huge cascades of
if/then/else
conditionals, where many of the outcomes have small differences that could be expressed in ways that are more compact and easier to understand. The current implementation of audio.py is a prime example of this.
The goal of making progress on this issue is to make the codebase easier to unit test, easier to understand, easier for non-experts to update, less prone to bugs, and less prone to copy-paste errors.