Repository navigation
[TST/MAINT] de-duplicate get_correction_factor code - #4988
Conversation
|
most likely not. I will think about it when I'm in that code neighborhood code duplication provides information locally where we need it, i.e. I want to see what correction factor is used in individual cases |
|
Take a look at the affected code. No information is lost. I should clarify that information is in fact gained, will do so,when at a real keyboard. |
Codecov Report
@@ Coverage Diff @@
## master #4988 +/- ##
==========================================
- Coverage 81.33% 81.32% -0.02%
==========================================
Files 582 582
Lines 90026 90001 -25
Branches 10093 10094 +1
==========================================
- Hits 73224 73190 -34
- Misses 14507 14513 +6
- Partials 2295 2298 +3
Continue to review full report at Codecov.
|
Consider the perspective of a new reader. Unless you know ex-ante that there are only two versions of this code, the natural assumption is that the similar-looking code is duplicated for a reason, i.e. that there are small differences between the many versions. This eliminates that confusion and the accompanying cognitive overhead. The big thing that needs to be documented in the affected code is "Why does class A use implementation X while class B uses implementation Y?" This PR doesn't answer that question, but puts a big TODO note in place, and minimizes the number of places where the question needs answering. Another non-obvious thing that makes the two versions look more different than they are is the inversion: which this PR much more clearly writes as making it clear that the only difference between the two versions is the subtraction of Last, reducing code duplication is about forward-looking bug-prevention. As we see all over the code-base, one version of duplicated code get missed, and by the time someone realizes other versions were missed, its an archaeological adventure to sort out "are these slightly different on purpose? It must be on purpose right?" @bashtage care to weigh in? |
|
@josef-pkt besides being good code hygiene, this is a move toward parameterization/fixturization, which will allow us to systematically cover “method” etc args. |
Codecov Report
@@ Coverage Diff @@
## master #4988 +/- ##
==========================================
- Coverage 82% 81.99% -0.01%
==========================================
Files 588 588
Lines 93061 93036 -25
Branches 10313 10314 +1
==========================================
- Hits 76311 76286 -25
Misses 14378 14378
Partials 2372 2372
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #4988 +/- ##
==========================================
- Coverage 82% 81.99% -0.01%
==========================================
Files 588 588
Lines 93061 93036 -25
Branches 10313 10314 +1
==========================================
- Hits 76311 76286 -25
Misses 14378 14378
Partials 2372 2372
Continue to review full report at Codecov.
|
ATM the
get_robust_cluclassmethod calculates a correction factor and then a bunch of classes have that code copy/pasted into theirsetup_class. A bunch of other classes have a slightly-changed variant of that calculation, with no documentation as to why the slight change was made (IIRC the answer is "to make it match Stata/R").This de-duplicates all that code by implementing
get_correction_factor.