muammar / mkchromecast

Cast macOS and Linux Audio/Video to your Google Cast and Sonos Devices
http://mkchromecast.com
Other
2.22k stars 140 forks source link

Add encapsulation, reduce code duplication, and simplify cascading logic #434

Open xsdg opened 11 months ago

xsdg commented 11 months ago

This bug covers three classes of deficiencies in mkchromecast: 1) 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.

2) 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)

3) 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.