A few observations:
At hand: 1. You never had time for this.
If you regard re-factorization as something separate from coding (rather than decently inside the coding), and if you cannot manage the time, then yes, you will never have time for that.
- Context switching is mentally expensive (it's hard to leave what you are doing in the middle).
See the previous paragraph above. Refactoring is an active component of good coding practice. If you separate them as if they were two different tasks, then 1) your coding methods need improvement / maturation, and 2) you will encounter a serious context switch if your code is in urgent need of refactoring (again, quality code.)
- This is usually not an easy task.
Only if the code you produce is not refactored. That is, code that is difficult to refactor shows one or more of the following (the list is not generally accepted):
- High cyclic complexity
- No separate responsibility for the class (or procedure),
- High adhesion and / or poor low cohesion (also known as LCOM indicators)
- poor structure
- Does not follow SOLID principles.
- Do not obey the Law of Demeter when necessary.
- Excessive observance of the Law of Demeter when it is unacceptable.
- Programming versus implementations instead of interfaces.
- There is always fear that you will break what is working now.
Testing? Check? Analysis? Any of them before being checked in the initial control (and, of course, before being delivered to users)?
On the other hand: 1. The use of this code is error prone.
Only if it has never been tested / verified and / or if there is no clear understanding of the conditions and patterns of use under which a valid error code works acceptable.
- Over time, you will realize that if you reorganized the code the first time you saw it, it would save you time in the long run.
This awareness should not occur over time. Good engineering and work ethics require such an implementation when an artifact (whether hardware or software) is under development.
So my question is - Practically - When do you decide the time to reorganize your code?
Practically when I code; I find an area that needs improvement (or something that needs to be fixed after changing requirements or expectations); and I get the opportunity to improve it without sacrificing a deadline. If I cannot repeat the factor at this point, I simply document the perceived defect and create a workable, realistic plan to review the artifact for refactoring.
In real life, there will be times when we will encode some ugly clod just so that everything is in order, or because we are exhausted, tired, or something else. This is reality. Our task is to make sure that these incidents do not accumulate and remain unattended. And the key to this is refactoring, because you code, keep the code simple and with a nice, simple and elegant structure. And âelegantâ I don't mean smart ass or esotericism, but it displays what are usually considered readable, simple, compound attributes (and mathematical attributes when they are applied in practice).
Good code can be refactored; It displays good performance; its structure is similar to the composition of computer science and the mathematical structure of functions ; he has a clear responsibility; he makes his invariants, before and afterwords obvious; etc. etc.
Hope this helps.