International Journal of Engineering Trends and Technology (IJETT) – Volume 31 Number 5- January 2016 Adaption of Reusable Code in Software Project and Their Maintenance Issues Dr.G.Anil Kumar Sr. Assistant Professor, CSE MGIT Hyderabad T.S. India Abstract: Software maintenance is an important phase of any software project. Reusability of a software code is an advantage in the modular project development. But, in the stage of project maintenance, reusability of the code may create some problems. In this paper we address some of these problems but the overview of the paper is to introduce the negative effects of code reuse usually called as code cloning. INTRODUCTION A software application used by an organization must support all the needs of the organization for which the application is developed. A software application is said to be successful if it serves long time to an organization. Over the time changes in the user requirements are inevitable. Adaption of these changes by the system is a challenging task. Over time, application becomes more and more complex with these changes and also developer cannot remember design and development of the application. Software maintenance team finds it difficult to manage the applications integrity over these changes. So, there is a lot of scope for research in software engineering especially in software maintenance. Software re-use is a powerful approach in development phase of the SDLC, but the consequences of this approach results in code cloning. This paper explains what is software maintenance, types of maintenance, code cloning, importance of code cloning in maintenance, challenges in code cloning, motivations of the research work, our contributions to the research of code clones. costliest phase. Software maintenance explained in four categories [2]. They are is better Corrective maintenance Adaptive maintenance Perfective maintenance and Preventive maintenance Following sections gives brief description about these four types of maintenance. Corrective Maintenance: Corrective maintenance is a kind of system maintenance with a goal of restoring operability to a software system when a problem or fault emerges in a system. In certain cases, it is not possible to foresee or prevent a failure. In such cases corrective maintenance is the only option. For instance if a system requires repair because of insufficient preventive measures, people may prefer to focus on corrective maintenance over the other maintenance activities. This is one of the most accepted maintenance strategies. The procedure of corrective maintenance starts with a failure. A diagnosis is used in the process of determining the reasons for the failure. The whole diagnostic process includes steps as follows. They are physical inspection of a system, using diagnostic process to assess the system, and interviewing the users. There are some other additional steps required to determine the cause of the problem. This is essential to take necessary action and one must be aware that multiple failures of software components may occurred simultaneously. Software Maintenance Software maintenance is a process of modification of any software product after delivery either to correct faults or to improve performance. Sometimes it is also necessary to adapt the product in to a modified environment [1]. Software Development Life Cycle (SDLC) has several phases like requirements gathering, analysis, coding, testing and maintenance. Software maintenance is one of the important phases of the SDLC. Of all the phases, software maintenance is the ISSN: 2231-5381 Replacement of the damaged components is next step. In certain cases, the damage is repairable. This can be achieved by deleting the item and doing repairs. In other cases, complete replacement is required to restore proper functioning of the system. For instance, when an optical drive failed in a computer, a technician determines that, repairing or replacing the part may be sufficient. At times he may find that the whole drive needs to be replaced with new one. http://www.ijettjournal.org Page 263 International Journal of Engineering Trends and Technology (IJETT) – Volume 31 Number 5- January 2016 Adaptive maintenance: The changes made to a software product after delivery to keep the product updated in the changing environment for the continuous changes of the requirements. There are many reasons for the occurrence of these changes. Some of them are changes in the user requirements, alterations forced by associated systems, changes in the environment and other time dependent changes. To be precise, adaptive maintenance is used to adjust a program for effective functioning in a new environment. Some programs are typically designed and promoted to function in specific operating systems (OS). Some of these software function using new versions, however there are many other programs that cannot do so. To keep it current and useable, an adaptive patch to a program could be required to change the code so that it functions efficiently in a new system. Perfective maintenance: Certain changes are required by a software product to enhance performance or maintainability after the product is delivered to the customer. Perfective software maintenance can be used to add new features and to bring alterations, so that the user is directly affected. For instance, if a company releases word processing program which has a few spell checking features and they release a patch which can update the dictionary in the program and also provides additional error- correction options, that is considered as perfective maintenance. Preventive maintenance: The changes are required to any software product after delivery. These are to find out and correct the defects which are not traced during the development and testing phases. These changes are needed in the software product much before they become effective faults or bugs. Preventive maintenance refers to actions taken to forestall the need for major repairs. These will include inspection, cleaning and replacing parts. This software includes programs written for computers consisting operating systems and software applications with the help of which a variety of tasks can be performed. Preventive maintenance can otherwise be called as Computerized Maintenance Management Solution (CMMS). This is a way of managing maintenance for all the equipment in its facilities. With an increase in the size and complexity of software, the maintenance tasks became more tough and burdened. Either one–fourth or one–third of the software life cycle cost is utilized in the maintenance or operation phase of the life cycle. According to Arthur about 67% of the life cycle cost is used as maintenance phase expenditure [3, 4]. The work of improving an existing system is costlier than developing a new ISSN: 2231-5381 system if at all the base system is not well structured [5]. All the four maintenance activities discussed above are well in practice in the software industry. It is difficult to identify the product or the process which has created the product. Not only modifications are not sufficiently documented but also there is no stability in the change and there will be a ripple effect when making changes. These are some of the reasons why maintenance becomes very hard to deal with [6]. What is code duplication? Most of the studies prove that about 5% to 20% of software systems consist of duplicated code. This is because of the activity of copying existing code fragments and later making use of them by pasting either with or without minor modifications. Because of the innumerable efforts to develop clone detection tool, the sphere of clone detection has received tremendous interest [7]. A clone detector should be able to make out the pieces of code that of high similarity in a particular system‟s source text. The major problem is, it is not possible to trace out the code fragments that may be repeated. So, each possible code fragment should be compared with every possible fragment. Such comparison is really expensive. So, many measures are used to reduce the cost. The domain of comparison is reduced much before the actual comparisons are performed. Despite identifying potentially cloned fragments, there must be further analysis and tool support is required to make out the actual clones [8]. The act of copying is an indication of the programmer‟s intention of reusing the implementation of an abstraction. Encapsulation, one of the object oriented software engineering principle is broken with the act of pasting. A program fragment which is identical to another fragment is a clone. A program fragment which is nearly identical to another fragment is a near miss clone [9]. There can be redundancy in different forms in software. Software consists of both programs and data. Redundant code is misleadingly called cloned code. Which implies that one piece of code is extracted from the other one. Though cloning results in redundant code, every redundant code is not a clone. There can be code segments which are similar or just identical by chance, though they are not a copy of each other. Sometimes there can be redundant code with a totally different implementation, though there is semantic equivalence [10]. http://www.ijettjournal.org Page 264 International Journal of Engineering Trends and Technology (IJETT) – Volume 31 Number 5- January 2016 refactoring is done frequently that helps the code to retain its shape. Challenges in code clone maintenance There are many challenges found in the maintenance of clones, some of which are related to the removal of code duplication through refactoring. All these challenges can be further explained in the following subsections. Clone representation When there is code fragment repeated several times in a program or duplicated in another program, collection of these clones form clone groups. Because of all this, in the understanding of cloning in code, there are critical elements. The information collected about each clone in the group can make out characteristics of the group choosing clone location and syntactic differences between them. The different sections of code that are closely associated with the clones in the group should necessarily be assessed by the programmers if he/she has to specify the features of a clone group. This will be a major challenge for the programmer who should assess all the characteristics of the clone group depending on the multiple instances of the clones. Refactoring When a software product undergoes a change to improve its internal structure without altering the external behavior of the code, then it is referred as refactoring [11, 12]. This is a semantic way of cleaning up a code by reducing the chance of introducing bugs. After writing the code, if the developer wants to improve the design of the code then he can opt for refactoring. This is a tool which can be used for several purposes. They are i. ii. iii. iv. Improve the design of software Make software easier to understand Help to find bugs Helps to develop and maintain software efficiently Improve the design of software: If the developer does not opt for refactoring, there will be decay in the design of the software. When people change code, the original structure of the code is lost. Just by reading the code, it is difficult to understand the design. Refactoring helps in cleaning up the code. There is cumulative effect for the loss of the structure of code. It is firm and difficult to see the design and to preserve it because it decays more rapidly. If ISSN: 2231-5381 Make software easier to understand: If the programmer has written a code in the past, he may not be able to remember important aspects about the code for which he has to modify the code often. At times the programmer takes a week to make a change, which otherwise would have taken only an hour time had he understood the code. The problem is that when the programmer is getting it done, he is not anticipating the changes he needs to undertake in the future. Process of refactoring enables the programmer to make his code more readable which means it also enables him to think of the future changes. Help to find bugs: Refactoring helps in understanding the code and also enables the programmer to spot bugs. If the structure of the program is clarified by using refactoring the programmer also clarifies few assumptions he has made, meaning even a programmer cannot avoid spotting some bugs if structurally they are not clear. Refactoring is helpful to the programmers to write an effective robust code. Helps to develop and maintain software efficiently: All the aspects that are discussed pave way to develop and maintain an efficient program. For rapid software development, a good design is necessary. There can be progress even without a good design in the beginning. However, the poor design may show him/her from progress later. Lot of time will be spent by the programmer to find and fix the bugs instead of adding new function. More time is essential for the changes to be made as one goes ahead trying to understand the program. In order to maintain speed in software development a good design is necessary. The process of refactoring enables the programmer to build software more quickly, for refactoring prevents the design from decaying. Fowler [11] analyzed code patterns and addressed 22 bad symptoms of code patterns that need to be refactored. He proposed 72 refactoring techniques to remove these bad symptoms. Out of all these symptoms duplicated code tops the table according to its severity. Code clone analysis and refactoring The use of clone detection tools has resulted in the general knowledge of the presence of clones in code. Table 1.1 shows a clone coverage sampling in programs of different sizes. The table depicts consistency in the cloning of the code in both small and large programs. This consistency can be seen in different languages like C and Java. The table also depicts that vast data can be http://www.ijettjournal.org Page 265 International Journal of Engineering Trends and Technology (IJETT) – Volume 31 Number 5- January 2016 detected which is related to cloning in source code by a clone detection tool. For instance, CP –miner reported that Linux kernel has 120K of “copy –pasted segments”, it is a clear indication that many sections of code have been duplicated. The vast data becomes a challenge for programmers when it comes to understanding the clones. To take necessary action to cloning, the programmer must scan the 120K copy pasted segments along with CP –Miner data to understand the extent of cloning in the program. Removal of comments Substitution of literals with terminal symbol “ ; ”. iii. Addition of file name identifiers iv. Concatenation of all source files in to a large source file One can remove a complete line but it affects the analysis approach which is based on per KLOC. The tools will also report the cloned fragment with reference to line number will be influenced. Table 1.1Clone duplication percentages in popular programs Finally, the first line of the source file will be added with its own file name. Then, all the files are appended or concatenated into a single large file, all the cloned segments of the methods can be extracted in a single search. System (Program) LOC JDK 1.4.2 (Java Development Kit) JDK 1.3.0 Linux kernel JavaGenes 0.7.68 JHotDraw 7.0.7 2418K 570K 4365K 45K 71K Percentage of clones 8% [13] 9% [23] 15% [14] 10% [24] 19% [24] The possibility of errors in the future can be reduced by removing the duplication of the coder or code clones. Refactoring can be used in the best possible manner to erase duplication related to clones. For instance, by using Extract method in refactoring, a part of duplicate code can be modularized and the actual sections of code related to the duplication can be replaced. The replacement can be done by calls to the newly extracted method. The future maintenance is performed in a single location, for the program modularity is improved. Presently, the task of clone refactoring is done by the programmer. The programmer has two options. One is to manually refactor the clones and the other is to pass on the information of the clones to a refactoring engine. This requires individual steps for refactoring for every single clone in the group. All this gives a break to the whole process of clone maintenance. The clone maintenance process usually starts with detection of the clones, analysis of the clones, determining the refactoring opportunities and ends with the actual findings. Code Transformation The transformation of the actual source code fragment is essential to effectively parse the code. All this has to be done within the context of the analysis. This process of transformation include step by step procedure as follows ISSN: 2231-5381 i. ii. Method level code duplication Code cloning or code duplication can be identified in various levels using various methods. Method level code duplication refers to a function or method copied to exact copy which is the result of cut copy paste activity or modified its passing parameters and/or changed variables will make to differ with the original method. In addition to the change of variable names new statements may be added and some existing statements may be deleted without modifying the functional behavior of the method. Code fragments at method level, that are developed in two different ways for a single cause or purpose needs to be considered as clones. These clones are syntactically not similar but semantically similar. At method level two methods developed in two different approaches may results the same. This kind of methods can be known as clones. Metrics based approach The metrics from source code are calculated and are used to measure clones in software. This approach is known as metric based approach. Instead of directly working on source code, this particular approach uses metrics to identify clones. There are different tools that are available for assessing metrics of source code. Columbus is one such tool. This tool helps to provide metrics which will be used in detecting clones. The same tool cannot be applied for Java code. There are other tools which provide metrics. However they are not efficient in finding out the results of clone detection. In this work metric based clone detection is proposed. The metrics used in this method are very useful for predicting the Java software. They are also very easy to use. http://www.ijettjournal.org Page 266 International Journal of Engineering Trends and Technology (IJETT) – Volume 31 Number 5- January 2016 Motivations of the research The aim of clone detection technique is to find duplicated code, which is slightly different from the original [13]. To detect simple clones, token based approach is applied. This facilitates a suitable level of flexibility for the task. This is done by limiting the language dependence in the process of providing an appreciable mechanism for discovering parameterizing simple clones. After transforming a source program into a string of tokens, the maximal repeats in the string are computed with a suffix array based algorithm [14]. All these maximal repeats in the string form clone classes with some heuristic based pruning. Though the detection of simple clones is a kin to the previous approach, there is novelty in the introduction of a simple and flexible tokenization technique and also in the selection of necessary data structures and algorithms for token string manipulations [15]. Software projects consist of code clones. Many commonly adopted software development practices are introduced. These practices include reusing a generic framework following a specific programming pattern and lastly copying and pasting code fragments. All these can enhance the productivity of software development. This can be seen in the repetition of similar functionalities. With these practices the maintainability of the program may be reduced. For instance, when a duplicated code is enhanced or bugs are fixed, it becomes necessary to make modifications of the same kind for the other instances of the code [16]. like, software reengineering and maintenance, quality assessment, detection of plagiarism, investigations on copyright issues, identification of cross cutting concerns etc. Research work Contributions: Proposed method detects all the types (type I, type II, type III, and type IV) of clones as clone pairs for programming language,in this work,we have tested it with JAVA [20]. Detection of clones is the process of identifying the potential clones present in the original code of a software project. The detection process is started with comments and white space removal, followed by tokenizing them with the analysis of language constructs, continued with textual comparisons results similar to plagiarism of code fragments, preprocessing activities like normalization are applied on the code before comparison to nullify the effect of change of variable names etc., and applying metrics to identify the semantically equal code fragments. All the detected clone pairs are grouped together to form clone clusters and they are stored in files. These files are useful for analysis of the detected clones, and to proceed further for refactoring through „extract‟ method for making the common code as a method and can be called by any number of times in the code and „pull up‟ method where the code fragment is large in size and to use the essence of inheritance property effectively the code fragment made as methods of parent class which is substitutable the child classes. The entire process of analyzing will be useful to reduce the effect of maintenance problems. There are some common activities in software development. They are copying code fragments reuse them by pasting sometimes with modifications and sometimes without modifications. This type is called code cloning and it involves re-use approach. Depending on the extent of their similarity, the cloned fragments have been classified under four categories. Code cloning is not only influencing the maintenance cost of the software product but also considered to be as defect –prone, where inconsistent changes to code fragments which are duplicated can leads to unexpected behavior by the program. Refactoring is an effective technique in code clone detection process. The effect and usefulness of refactoring is explained in the earlier part of this paper. All the detected clones can be automatically refactored if required by the programmer. Refactoring automatically makes the maintenance job convenient and easy. This refactoring is made at method level and used two types of refactoring techniques in this work. Extract method and pull up method are more suitable for code clone detection at method level. These clones are considered to be harmful because, occurrence of multiple and possibly unnecessary clones‟ increases the cost of the maintenance and inconsistent changes made to code fragments may lead to unexpected behavior by the program. This paper introduced software maintenance and the challenges in maintenance due to code cloning. As we know maintenance is the costliest and important phase of the software development life cycle (SDLC). The best way of using the existing and proven good software code can be used in similar way in the developing system. That is the essence of software reuse. The advantages of this software reuse and Clone detection tools are used to perform several tasks in the area of research and practice. These areas are ISSN: 2231-5381 Conclusion http://www.ijettjournal.org Page 267 International Journal of Engineering Trends and Technology (IJETT) – Volume 31 Number 5- January 2016 difficulties of the software maintenance due to software reuse were discussed. References [1] IEEE. Standard for Software Maintenance.IEEE Standard 1219, 1998. [2] ISO/IEC. Software Engineering - Software Maintenance. ISO/IEC 14764,1999. [3] L. Arthur. Software Evolution: The Software Maintenance Challenge. Wiley,1988. [4] S. W. L. Yip and T. Lam.A software maintenance survey. In Proc. of the 1st Asia-Pacific Software Engineering Conference, pages 70– 79, Dec 1994. [5] S. Chidamber and C. Kemerer.A metric suite for object-oriented design. IEEE Transactions on Software Engineering, 25(5):476–493, Jun 1994. [6] ClearCase. http://www306.ibm.com/software/awdtools/clearcase/. [7] Robert Tairas, “Clone detection and refactoring”, Proceeding of OOPSLA '06 Companion to the 21st ACM SIGPLAN symposium on Object-oriented programming systems, languages, and applications, pp. 780-781, New York, USA, 2006 [8] Chanchal K. Roy, James R. Cordya and Rainer Koschkeb, “Comparison and Evaluation of Code Clone Detection Techniques and Tools: A Qualitative Approach”, Journal Science of Computer Programming, Vol. 74, No.7, pp. 470-495, May 2009. [9] Ira D. Baxter, Andrew Yahin, Leonardo Moura, Marcelo Sant Anna and Lorraine Bier, “Clone Detection Using Abstract Syntax Trees”, Proceedings of the International Conference on Software Maintenance, pp. 368, Washington DC, USA 1998 [10] G.Anil Kumar, Dr.CRK.Reddy, Dr.A.Govardhan “Code duplication in Software Systems: A survey”, International Journal of Software Engineering Research & Practices Vol.2, Issue 1, Jan 2012 [11] M. Fowlor. Refactoring: improving the design of existing code. Addison Wesley, 1999. [12] R. H. Page. http://www.refactoring.com/. ISSN: 2231-5381 http://www.ijettjournal.org Page 268