The current project is to do almost a year and a half, and look back, before the year is doing reconstruction and then in a year is to create a new product. Do a little remodeling here summarize some of the things learned when it.
Reconstruction can in fact be a different goal, some refactoring to make code more reasonable, beautiful; while others may be in order to achieve a particular function; also have different levels of reconstruction, and some may just be the function, class level to make some changes, while others are to the entire structure, modules do change; reconstruction of the input is also very different, and some only in the event of bad code or design when it is corrected, while others will set up a special team to spend a long period of time to do the reconstruction.
Precise definitions of basic concepts is the basis for all discussions, I am here to discuss reconstruction "in order to achieve a functional and devoted to large-scale code change."
Architecture design, you can see how far
It simply, we need to do is put a software function of the UI code and the complete separation of the core, then core made of a single product. Of course, this so-called presentation layer and business layer to separate the truth is no one understands, and had indeed joined in the structure of these concepts, but the absence of strict requirements, but also never to separate out the core part of the run, After nearly a decade of development, the core layer of the UI code dependence has been very serious, there is static, dependent on the source code is compiled, there are also dynamic, runtime dependencies. This time to extract the core functions are undoubtedly very difficult and time-consuming (the amount to millions of lines of code in mind). There are now some open source CAD software online, a lot of that is beginning there is a clear division of Core-UI, and can run in kernel mode or UI mode. If FreeCAD . Think if it was then the architect can think of this step, from the outset a clear division can be sure: first, post-human and material resources without spending so much; Second, the quality, design will be much better.
Of course, this fact is not necessarily a vision is not enough, when considered together, and commercial interests, a lot of good design had to be abandoned. For example, your product is only for Windows users, the project group are Windows programmers - for better and faster product launches, cross-platform, you should not consider it - but years later, the boss decided to the Mac into a ~ ~ ~ So, this one is the best, destiny it.
Must be open to a separate branch. Behind closed doors, so you can "do whatever they want", and will not affect the other team. Here do whatever they mean:
- Build Errors are allowed
Because it is a great code base, you may change somewhere in another one cause compilation errors, or do you use the script to modify surface is particularly broad, and in the machine to do a full build may be a half-day (right, that is used IncrediBuild ), then check-in after the server to help to build, you can continue to work, there are several build error, it does not matter!
- Regression is normal
Each time before check-in, do not run those kind of automated testing.
Of course, this freedom in many cases is not recommended, but in here, but a very large increase efficiency.
In addition, because changes in the amount of reconstruction is very large, so often with the main or trunk branck to sync, the one-time change control in an acceptable range.
How to ensure quality
Mentioned above, we can not run automated test and check-in, then how to ensure the quality of it.
First, you must have a test automation - based on the code unit testing Ye Hao, script-based functional test but whatever is automated, and it is ok enough coverage - and doing reconstruction, especially in large-scale reconstruction when there is no automated testing, it is simply seeking death.
Because we are working on their own branch, as long as back main / trunk when no regression on it, the middle is what the state we are not very high. The general practice is:
- Smoketest will run about a week and some related acceptance test, to prevent some major problems.
- Time and main / trunk sync, we will spend about 4 days or so to do "automation triage" - the case of all automated tests are run again, get the report after the analysis one by one - or batch analysis, because many failure are the same.
This approach greatly improves the efficiency of - you know, we should finish all of the case, along with dozens of servers required to run three days ~ ~ ~
How to manage code
Reconstruction involves a lot of movement and split the file, you need to pay attention to two areas:
- File history information can not be broken
How a file is changed step by step over is a very important message - you can easily be found who at what time to turn over the documents, how to change the. Move, or split files is very easy to inadvertently lose the history of the operation. Must be correct to use SCM tools to keep this information, such as perforce where we should use intergrate, rather than simply add.
- Correspondence between the file can not be arbitrary
Involved here from the main branch to the intergration, you put a file in the branch moved on and made changes, and in the main on the same change was made to do intergration, you can easily lose people on the main changes because the correspondence has not been established, there is no way to merge the. I want a different SCM tools should provide a solution, such as perforce in its branch spec can illustrate in their correspondence.
I read over during the "reconstruction ---- improvement Design of Existing Code" , mentioned above a lot of good methods and steps to improve the design, but basically useless on. Because of the design, we either case, how to modify the prior research and have been doing the program, and those steps feeling slightly wordy, is not very applicable. Visual Assist provides a reconfigurable module, in general, with the size of the code can also be used, but there are a number of solution for the code can not do anything. Moreover, these are only related to the source code refactoring, we have a project / DLL 's reconstruction.
Our approach is: for different situations, to write perl script to automate some tasks. A simple point example: I changed the name of a method, the script will search all of the code, automatic check-out the file to edit, and replace the new name. Remember to write a perl script to automate many of the calls for perforce, VS call, code, project file changes and so on.
Some of the details
- interface using the interface for our refactoring work can be said to do anything, and it is a lot of use of the interface before allowing this has been very tight coupling of code UI-core separation is possible. Such as a core layer of the operation is complete is called to refresh the UI code, and move out of this refresh operation is very difficult, this time with the interface is good practice:
Of course there are other ways to use interface, but ultimately is to achieve separation.
- Use vsprops
We are using Visual Studio, hundreds of projects has its own settings, but in fact, many settings are similar, can those same settings into a vsprops file, so that each vcproj file to reference it. To the extent it can improve the degree of consistency and simplicity. MSDN has a detailed description .
- Virtual function and rebuild. Add, delete virtual functions, especially in the base class virtual function will destroy the original virtual table, so unless all possible references to rebuild the code, or will produce very strange function call, specifically to see this: on the virtual point out the things that function .
Reconstruction of large-scale software to do this, I learned more and more is:
- The face of some large-scale software systems will not commit Chu, would be more confident.
- Develop automatic habits, some of the large number of manual operations, will be very tedious, very time-consuming, error-prone to do and there is no sense of accomplishment, but to change if the goal: write a program to automate the above that the problem is not gone :)