The time and method of reconstruction of "Software Engineering" development Project

Source: Internet
Author: User
Tags comments

Software development projects are often time-intensive, task-heavy, understaffed, inexperienced .... Work overtime. Where there is time to refactor.

In fact, refactoring is an effective way to improve the quality of software, and through refactoring activities can effectively avoid the software too fast "rot".

OK, your project does not have to do refactoring activities, but if you do, here are some principles for refactoring activities for reference.

"Refactoring" describes too much content, if all according to the book ... Project never Knot: (


Time

1, after the implementation of the code function, according to the code to view the comments modified.

2, before adding new features, if the function needs to modify the original code a lot of places, consider refactoring first.

3, the module reaches a certain volume, it is recommended to refactor every 200~300 line (Java), up to no more than 500 lines.


Premise

1, perfect test cases, at least covering all aspects of the design, compare the code performance before and after the refactoring.

2, perfect comments, step back, if the comments are insufficient, at least the refactoring to understand the code very well.


Focus

Practical engineering application, the focus is how much manpower, the goal effect how, to see the various projects different arrangements for different time.

Not a round of reconstruction, you can modify all kinds of problems, but the focus is different, the key part must be all modified, other parts according to time, manpower, etc. adjust the strategy at any moment.

the first round: repetitive code or Logic

Can be obtained by using the Check tool, the selection of the specific inspection tool requires the project team to choose according to their own circumstances. Other tools are less intelligent, and for some logically similar code, manual inspection is required.

Repeating code is generally extracted first, forming a standalone function, if the object-oriented can use private, subsequent adjustments as needed until public, even if necessary can be published as an interface.

There are generally options for extracting functions in the IDE, which is one of the most common features.

This round typically takes the longest time and can be combined with other refactorings, with the goal of keeping all logically duplicated code in one copy.

Later, when new features are added, it is not necessary to spend too much time on the same logic code that is distributed to the system.

Second round: Long function (independent function block)

A function that is too long is the culprit of code decay. No one can read or change.

The project itself set standards, what is too long, if strictly a little, maybe more than 30 or even 20 lines even if it is too long. Generally, a function is required to be responsible for only one thing, such as in Java development, if the function name using 3 actual words can not describe their own functions, proposed splitting. Getnamebyindex, GETNAMEBYADDR, these are long. (You can actually use the overload according to the input to decide which one, the example is not good, later update it)

Getnamebyindexandstatus, look at this name, you can split into Getnamebyindexstatus1/getnamebyindexstatus2 ..., and then split into getnamestatus1/by overloading GetNameStatus2 ... For Byindex, byaddr are overloaded.

round three: processing of methods

Methods to be placed in the most suitable class, the common means are pull up, push down, move to other classes and so on. Cautious. Especially in many places to be quoted, if not very necessary, or do not change it ...

fourth round: temporary variables, naming

Actually should be regarded as "other" part, if have time, think more about what need to change.

Fifth round: modifying annotations

Good code is self-explanatory, but you still have to make it easy for others to read in the project. Refactoring good code doesn't need to add too many comments to the feature itself, but add some of the following:

In which version the introduction, author, date, and other package, class relationships, if there are performance requirements to increase performance requirements and measurement instructions.

General Staff is not very sufficient, to here is enough.

Refactoring is also a process of cultivating habits, generally after 3-6 months, Refactoring said that the time spent is greatly reduced, even when the development of the way to complete.


Finally, I wish you all the program ape and program Yuan overtime not too late Oh ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.