You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the structure of Stargazer’s internal methods for generating the table in different formats (generate_header_html, generate_r2_latex, etc.) makes it easy to navigate the code, but also leads to a lot of repetitive code. This makes changes and additions difficult. I give two examples of this below and suggest a solution.
These are just two functions that are used to render the HTML table. Note that the only difference are: the show_* boolean to check, the title of the column and the content. The formatting and the code to produce the table row is exactly the same.
As a result, adding a new statistic requires copying all of the above code. Similarly, adding a tag to the tr or td elements would already require over 10 changes in the code.
There is also a lot of repetitive code between formats. Specifically, all generate_* methods are implemented twice (once for HTML and once for Latex).
Again, this means that any change to the table needs to be repeated twice, even when the change has nothing to do with the formatting (e.g. #11). This problem will only get worse as more formats are added.
This restructuring of the code removes the above-described code repetitions. Thus, bug fixes and the implementation of new formats would require a lot fewer changes to the code.
At the same time, it preserves much of the seperation into smaller pieces of code, meaning it remains easily navigatable. Moreove, one can still implement a custom render function (not use generic _gen functions), if need be (e.g. if the formatting of one line is affected by the next).
Since the change only affects internal methods (not the render options or render_* methods), it is fully backwards compatible.
Note that the above sketch uses newer language features (f-strings) for brevity. To keep stargazer compatible with Python 3.0, these would need to be replace by .format().
The text was updated successfully, but these errors were encountered:
Agreed, your proposed solution sounds great. A utility to concatenate fields through the for md in self.model_data: structure could also reduce code duplication.
Quite different from your proposal @csemken , but should make it easier to apply it (at least we avoid the format parameter, and it should be easier to isolate format-agnostic code parts): #46 , comments welcome.
Currently, the structure of Stargazer’s internal methods for generating the table in different formats (
generate_header_html
,generate_r2_latex
, etc.) makes it easy to navigate the code, but also leads to a lot of repetitive code. This makes changes and additions difficult. I give two examples of this below and suggest a solution.Problem 1: repetition within a format
These are just two functions that are used to render the HTML table. Note that the only difference are: the
show_*
boolean to check, the title of the column and the content. The formatting and the code to produce the table row is exactly the same.As a result, adding a new statistic requires copying all of the above code. Similarly, adding a tag to the tr or td elements would already require over 10 changes in the code.
Problem 2: Repetition between formats
There is also a lot of repetitive code between formats. Specifically, all
generate_*
methods are implemented twice (once for HTML and once for Latex).Again, this means that any change to the table needs to be repeated twice, even when the change has nothing to do with the formatting (e.g. #11). This problem will only get worse as more formats are added.
Solution: a new structure
Here is a sketch of the new structure I propose:
This restructuring of the code removes the above-described code repetitions. Thus, bug fixes and the implementation of new formats would require a lot fewer changes to the code.
At the same time, it preserves much of the seperation into smaller pieces of code, meaning it remains easily navigatable. Moreove, one can still implement a custom render function (not use generic _gen functions), if need be (e.g. if the formatting of one line is affected by the next).
Since the change only affects internal methods (not the render options or
render_*
methods), it is fully backwards compatible.Note that the above sketch uses newer language features (f-strings) for brevity. To keep stargazer compatible with Python 3.0, these would need to be replace by
.format()
.The text was updated successfully, but these errors were encountered: