-
Notifications
You must be signed in to change notification settings - Fork 573
Refactor BMConfigParser
as a module variable
#1927
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
Refactor BMConfigParser
as a module variable
#1927
Conversation
8863e48
to
de05577
Compare
6b1e897
to
04f4271
Compare
c649d1d
to
db39e6e
Compare
@@ -270,3 +169,6 @@ def validate_bitmessagesettings_maxoutboundconnections(value): | |||
if value < 0 or value > 8: | |||
return False | |||
return True | |||
|
|||
|
|||
config = BMConfigParser() |
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.
Another place with side effects is bad
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.
What alternative design do you propose? I think a module variable is an improvement singleton and I don't know other approaches.
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.
For me this approach seems worse than the singleton antipattern. Create the instance of BMConfigParser()
upon program start and use it everywhere passing as argument to functions or accessing it through a slot of another object.
These changes also create potential conflicts all across the codebase. And current test coverage is definitely not enough for such big changes.
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.
but where to put it then? state.py
?
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.
So you basically recommend dependency injection. Which is ok, I'm just not sure that can be done easily now because of legacy structures. Using a module variable is halfway there, we can do unit tests on isolated objects, and can be refactored into dependency injection later.
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.
If it was all about the tests, you could just separate BMConfigParser
from singleton object.
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.
It's not just tests though, there are some additions that prevent misbehaviour, like a clean reset, consolidation of default values and threads waiting for initialization. I'm not super happy that the commit is kind of big, just the old code is difficult to modify in small chunks. The commit makes the code easier to change in the future.
3a45e34
to
d80c1ad
Compare
5ca7411
to
7a5d606
Compare
d92ee8c
to
b0477f3
Compare
d6fed4c
to
fc5cce6
Compare
BMConfigParser
as a module variable
3139af4
to
3d14120
Compare
@g1itch I'm ready to merge this, any objections other than dependency injection? That can be done later and easier now with this refactoring. |
3d14120
to
a577399
Compare
It looks like |
Refactor
BMConfigParser