Currently, we use _initWidget() method to initialize the layout of the custom widgets.
This approach has controversial properties:
PROS
Modular and reusable initializer
Clearly show the layout-initializing part
CONS
Reusing the initializer is quite rare
Just commenting might give the similar effect (readability)
It violates the rule that all the attributes should be appear in __init__().
In some sense, it forces the developer that this method can be reused. It seems too much requirement, and quite awkward considering the meaning of 'initialize'. Therefore, when we want to 'reset' the layout, a special method should be designed for such cases.
Suggestion
Do not use _initWidget(). Instead, write them directly in __init__() and use comments for readability.
For example, if the original code below
Problem
Currently, we use
_initWidget()
method to initialize the layout of the custom widgets. This approach has controversial properties:PROS
CONS
__init__()
.Suggestion
Do not use
_initWidget()
. Instead, write them directly in__init__()
and use comments for readability. For example, if the original code belowwould become
If you have any opinion, please leave comments!