CSC/ECE 517 Fall 2009/wiki1a 9 pp: Difference between revisions
No edit summary |
|||
Line 44: | Line 44: | ||
<font face=""Times New Roman","serif""><font size="12.0pt"> </font></font> | <font face=""Times New Roman","serif""><font size="12.0pt"> </font></font> | ||
[1] Emerson Murphy-Hill, | [1] [http://portal.acm.org/citation.cfm?id=1176617.1176705&coll=ACM&dl=ACM&CFID=113271&CFTOKEN=65759170 Improving usability of refactoring tools] Emerson Murphy-Hill, October 2006, ACM | ||
[2] [http://en.wikipedia.org/wiki/Program_slicing Program Slicing] | [2] [http://en.wikipedia.org/wiki/Program_slicing Program Slicing] |
Revision as of 22:07, 7 September 2009
Research in refactoring tools
Refactoring is a very practical subject. A lot of the work in refactoring environments has been done on an ad hoc basis, by practicing programmers. This article briefly summarizes various initiatives that have been taken to improve the current generation of refactoring tools. Refactoring analysis requires serious research. All though the refactoring tools have been used presently for an automated refactoring, the refactoring itself is being performed informally from many years. The automatic refactoring is a result of academic researches being performed in this area since many years. This article will later summarizes the academic underpinning for some popular refactoring methods.
Introduction
Refactoring is a process of restructuring code without changing the way it behaves. Refactoring can be semi-automated with the help of tools, such as those that are integrated into the Eclipse environment. If these tools help programmers refactor with fewer errors, in less time, and with greater overall satisfaction than refactoring by hand, then programmers are likely to adopt such tools.
While the integration of refactoring tools into many development environments has increased, the usability of these tools has remained stagnant. Specifically, when refactoring fail, tools communicate the failure to the programmer poorly, causing the programmer to restructure slowly, conservatively, and without preserving behavior. There are various techniques developed for refactoring correctness, speed, and user satisfaction and improving the usability of refactoring tools. In the long run, better usability will aid in the adoption and utilization of refactoring tools.
Improvements in the Refactoring Tools
There are two main difficulties encountered by programmers while trying to refactor. First, on many occasions programmers are unable to select a list of statements, due to very long statements and inconsistent formatting. Second, is that the programmers have trouble understanding and interpreting error messages produced by the tools, such as “Ambiguous return value: selected block contains more than one assignment to local variable.” These error messages are generally caused by violated refactoring preconditions.
In order to make the tools user friendly there are several researches being performed. Murphy-Hill [5] proposed add-ons to Eclipse such as SelectionAssist where when the cursor is placed in the whitespace in front of a statement, a green highlight appears over the text range of that statement. Another suggestion was using Refactoring Annotations which tell the programmer that one parameter must be passed in to the extracted method, and that two values must be returned, violating an Extract Method precondition. Refactoring Annotations can also inform the programmer about precondition violations involving control flow. With experimental validations Murphy-Hill [1] found that the usability of refactoring tools increases significantly with these changes thus increasing programmers’ speed and correctness.
Academic underpinnings
Lexical Analysis [4], various Parsing [5] techniques, Regular Expressions [6] and Graph Theory [7] are the four most basic components used in the refactoring tools. Over last several years these components have matured due to ongoing research and provide extremely strong foundation for refactoring tools building. Below are some of the refactoring methods discussed which makes uses of these components.
Extract Method
Extract Method has been recognized as one of the most important refactorings, since it decomposes large methods and can be used in combination with other refactorings for fixing a variety of design problems. Extract method is simply observed as Cut and Paste operation but it is not indeed. Extract Method actually requires some serious work. The method needs to be analyzed, all the temporary variables need to be found and then the refactoring strategy needs to be applied. The analysis is not something which is simply done by regular expression manipulation but it requires some careful work.
The main problem with existing tools and methodologies is that they support extraction of methods based on a set of statements selected by the user in the original method. There are researches being performed in order to provide suggestions about Extract Method opportunities. Chatzigeorgiou [12] have proposed methodology to automatically identify Extract Method refactoring opportunities and present them as suggestions to the designer of an object oriented system. Such techniques require making uses of Program Slicing [2] techniques. Program Slicing was defined by Weiser [3] as a slice consists of all the statements in a program that may affect the value of a variable x at a specific point of interest p. The pair (p, x) is referred to as slicing criterion. In general, slices are computed by finding sets of directly or indirectly relevant statements based on control and data dependencies. There are vast majority of the papers found in the literature of method extraction are based on the concept of Program Slicing. After the original definition by Weiser [3] several other notions of slicing such as static and dynamic slicing, forward and backward slicing, syntax-preserving slicing and intra-procedural slicing have been proposed by various researchers.
Code cloning and detection
When a section of code is duplicated in more than one location among a collection of source files, that section of code and all of its duplicates are considered code clones. Clones are typically generated because a programmer copies a section of code and pastes it into other parts of the same program. Such clones can produce maintenance nightmares. In particular, if a section of code representing a clone is updated, then other sections of code representing clones from the same group may also need to be updated. This scenario creates a challenge for the maintainer to realize the existence of the clones and uniformly update all relevant sections of code. One approach to improve the maintainability of clones is the use of refactoring to eliminate the duplicate code through abstraction and improved modularity. In this case, the maintainability is improved because an update to the section of code is only required in one location. In order to determine clones that have potential for being refactored, analysis of the clones is required. Clone detection analysis makes use of:
String Matching – Represents and evaluates code using string comparisons. There are various types of string matching such as Exact String Matching, Parameterized Matching and Substring Matching.
Token Parsing – Transforms code into tokens by using language specific constructs into a single token string. Then finds the similarities within this token string and transforms token clones back into code clones for presentation.
Graph Matching – Machine representation of the code is formed using graphs and clones are identified as identical subgraphs.
Refactoring Annotations
Refactoring Annotations as discussed earlier could be applied to other software engineering tools, such as compilers. For example, type error messages are notoriously hard for beginners to understand and for experts to track down.
References
[1] Improving usability of refactoring tools Emerson Murphy-Hill, October 2006, ACM
[2] Program Slicing
[3] M. Weiser, "Program Slicing," IEEE Transactions on Software Engineering, vol. 10, no. 4, pp. 352-357, 1984.
[4] Lexical Analysis
[5] Parsing
[7] Graph Theory