-
Notifications
You must be signed in to change notification settings - Fork 16
Invoke PipedCompressionProgram directly rather than through subclassing #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…through subclassing
The igzip CLI program from ISA-L is no longer used
@marcelm, since you like deleting lines here is another one. This is the last major refactor that I had in mind. |
93bb424
to
403ade3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the direction this is going. Subclassing to customize behavior could be considered an anti-pattern, from which I’ve tried to get away myself recently. I liked this talk by Brandon Rhodes. Relevant here would be the part about composition vs specialization.
However, I’m not a huge fan of using **kwargs
. You have this comment:
Rather than using a dict, use a NamedTuple with _asdict to enforce presence
of certain members and type checking.
The namedtuple itself is typechecked, but that is mostly lost when the _program_settings()
function is invoked, which has just Dict[str, Any]
as return type.
Another solution would be to pass ProgramSettings
directly to PipedCompressionProgram
and then avoid calling _asdict
, but assign the attributes individually instead. This adds a couple of lines, but makes it clearer what is going on.
One could argue that this increases coupling between ...Program
and ...Settings
, but the coupling is already there because the constructor to PipedCompressionProgram
expects exactly those fields that ProgramSettings
contains.
I found this made writing the tests less messy (I initially implemented it this way), but I agree with your arguement. So I have changed it back and used a dataclass instead. EDIT: @marcelm, all changes are done and reviewable now. |
@marcelm, it is finished now. I saw a comment that you were waiting on this in the other PR. I have rewatched a bit more of Brandon Rhodes. What is done here is composing two classes together, which is totally legit, even if this creates some coupling. |
Nice, I like it! Thanks for addressing my comments. |
Thanks for merging! According to github, we went from 1144 LOC on |
This is basically this Jack Diederich video in practice: https://www.youtube.com/watch?v=o9pEzgHorH0
Subclassing to derive settings is not the best way in this case.
By moving all the program specific arguments to a dedicated _ProgramSettings class, we can use a _ProgramSettings class for each different program. These settings classes are now in one central place in the code, rather than spread out over multiple class definitions.
I also made _PipedCompressionProgram a private class.
EDIT: Changed to reflected changes after review.