|
| 1 | +--- |
| 2 | +date: "2023-02-14T00:00:00+00:00" |
| 3 | +title: "Guidelines for Refactoring" |
| 4 | +slug: "guidelines-refactoring" |
| 5 | +weight: 20 |
| 6 | +toc: false |
| 7 | +draft: false |
| 8 | +menu: |
| 9 | +sidebar: |
| 10 | +parent: "developers" |
| 11 | +name: "Guidelines for Refactoring" |
| 12 | +weight: 20 |
| 13 | +identifier: "guidelines-refactoring" |
| 14 | +--- |
| 15 | + |
| 16 | +# Guidelines for Refactoring |
| 17 | + |
| 18 | +**Table of Contents** |
| 19 | + |
| 20 | +{{< toc >}} |
| 21 | + |
| 22 | +## Background |
| 23 | + |
| 24 | +Since the first line of code was written at Feb 12, 2014, Gitea has grown to be a large project. |
| 25 | +As a result, the codebase has become larger and larger. The larger the codebase is, the more difficult it is to maintain. |
| 26 | +A lot of outdated mechanisms exist, a lot of frameworks are mixed together, some legacy code might cause bugs and block new features. |
| 27 | +To make the codebase more maintainable and make Gitea better, developers should keep in mind to use modern mechanisms to refactor the old code. |
| 28 | + |
| 29 | +This document is a collection of guidelines for refactoring the codebase. |
| 30 | + |
| 31 | +## Refactoring Suggestions |
| 32 | + |
| 33 | +* Design more about the future, but not only resolve the current problem. |
| 34 | +* Reduce ambiguity, reduce conflicts, improve maintainability. |
| 35 | +* Describe the refactoring, for example: |
| 36 | + * Why the refactoring is needed. |
| 37 | + * How the legacy problems would be solved. |
| 38 | + * What's the Pros/Cons of the refactoring. |
| 39 | +* Only do necessary changes, keep the old logic as much as possible. |
| 40 | +* Introduce some intermediate steps to make the refactoring easier to review, a complete refactoring plan could be done in several PRs. |
| 41 | +* If there is any divergence, the TOC(Technical Oversight Committee) should be involved to help to make decisions. |
| 42 | +* Add necessary tests to make sure the refactoring is correct. |
| 43 | +* Non-bug refactoring is preferred to be done at the beginning of a milestone, it would be easier to find problems before the release. |
| 44 | + |
| 45 | +## Reviewing & Merging Suggestions |
| 46 | + |
| 47 | +* A refactoring PR shouldn't be kept open for a long time (usually 7 days), it should be reviewed as soon as possible. |
| 48 | +* A refactoring PR should be merged as soon as possible, it should not be blocked by other PRs. |
| 49 | +* If there is no objection from TOC, a refactoring PR could be merged after 7 days with one core member's approval (not the author). |
| 50 | +* Tolerate some dirty/hacky intermediate steps if the final result is good. |
| 51 | +* Tolerate some regression bugs if the refactoring is necessary, fix bugs as soon as possible. |
0 commit comments