| Start |
|---|
| Goto Cleanup In C++ code bases which used to be C, one can find the pattern In C++ one could use RAII (opens new window) to fix this issue: From this point on, one could continue refactoring the actual code. For example by replacing the |
| Refactoring walk through Here's a program which might benefit from refactoring. It's a simple program using C++11 which is intended to calculate and print all prime numbers from 1 to 100 and is based on a program that was posted on CodeReview (opens new window) for review. The output from this program looks like this: 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 The first thing we notice is that the program fails to print Trying this version, we see that it does indeed work correctly now: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 The next step is to notice that the second We can go further, changing variable names to be a bit more descriptive. For example We can also refactor This is just one way refactoring might be done. Others might make different choices. However, the purpose for refactoring remains the same, which is to improve the readability and possibly the performance of the code without necessarily adding features. |
Read Article
https://develop.horje.com/learn/1434/reference