Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Construct the grads only once #78
Before this change, grads were constructed: * twice during `__init__` * each time the user called `ga.mv()` with no arguments * each time the user called `ga.grads()` After this change, grads are constructed: * once during `__init__`
@@ Coverage Diff @@ ## master #78 +/- ## ========================================== - Coverage 67.24% 67.21% -0.03% ========================================== Files 8 8 Lines 4817 4816 -1 ========================================== - Hits 3239 3237 -2 - Misses 1578 1579 +1
utensil left a comment •
This kind of init code is everywhere, I can always see the potential repetition here and there. We need to have a policy on these kind of code and apply them consistently. Some of them are tangled and less easy to extract. This one looks not so much tangled though.
The old code likes to use some lazy-init-like style. Upon calling a method to get an attribute, it will check if a certain condition is met, then do init. But the condition isn't always the same as whether it's inited. And the old code like to use these lazy-ish getter method to do the init without a init-like name.
I imagine that the policy to apply could be:
This is consistent with what you are doing.