An empirical investigation into code smells rectifications through ADA_BOOSTER

An empirical investigation into code smells rectifications through ADA_BOOSTER

Ain Shams Engineering Journal 10 (2019) 549–553 Contents lists available at ScienceDirect Ain Shams Engineering Journal journal homepage: www.scienc...

726KB Sizes 1 Downloads 105 Views

Ain Shams Engineering Journal 10 (2019) 549–553

Contents lists available at ScienceDirect

Ain Shams Engineering Journal journal homepage: www.sciencedirect.com

Engineering Physics and Mathematics

An empirical investigation into code smells rectifications through ADA_BOOSTER M. Sangeetha ⇑, C. Chandrasekar Professor, Department of Computer Science, Periyar University Tamil Nadu, India

a r t i c l e

i n f o

Article history: Received 15 March 2018 Revised 28 September 2018 Accepted 8 October 2018 Available online 18 February 2019 Keywords: Software refactoring Code smell Smell identifications Smell rectifications ADA-Booster

a b s t r a c t Object Oriented Programming has become one of the most established paradigms. It offers us features like encapsulation, polymorphism, inheritance etc. By using these features we are able to develop good software’s that are easy to understand. But when the size of the software goes on increasing it poses problems with respect to maintaining the source code. Also we come across the problems like code scattering and code tangling. So object oriented programming has some limitations and this is where Aspect Oriented Programming comes into play. Refactoring is one of the most important activities in software development. It is done to improve the design of the software, to make the software easier and better to understand and to help us in writing programs faster. After the software is refactored, it is important to note the behaviour of that software. Here, we propose new refactorings technique. The refactorings are identified. They are applied on the Systems. The ADA_BOOSTER technique to measure the metrics. By using refactoring we can change the existing software without affecting the behaviour of the software. Ó 2019 The Authors. Published by Elsevier B.V. on behalf of Faculty of Engineering, Ain Shams University. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-ncnd/4.0/).

1. Introduction Software Engineering is the engineering process of making to design, development, testing, implementation, and maintenance of software code in an efficient manner. In software programs, a code smell creates a deeper problem in the source code to degrade the software quality. In general, such kind of problem in the code is called as code smell and the detection of code smells has become a well-known method to identify the software. Design issues that may cause problems for further maintenance. Therefore, these smells are rectified to avoid the problems. But the costs and risks are major parameters for rectifying the code smell. Many techniques have developed to support the detection of code smells. Refactoring is one of the methods to detect the code smell thereby

⇑ Corresponding author at: 328/2 Udhayapuri Colony, Narasothipatti, Salem 636304, Tamil Nadu, India. E-mail addresses: [email protected] (M. Sangeetha), ccsekar@gmail. com (C. Chandrasekar). Peer review under responsibility of Ain Shams University.

Production and hosting by Elsevier

improving the software quality. Software Refactoring is a technique of altering a software system but it not varies the external performance of the code. The application of refactoring increases the code readability, maintainability, extensibility, Decrease density and software quality. The process of the refactoring is suggested as shown in Fig. 1. Software refactoring process modifying the existing software code with no changes occurred in external activities. Refactoring changes the inappropriate code of the software source code. The benefit of refactoring technique comprises better code readability and less complexity. This also increases the source-code maintainability and generates a more significant internal construction to improve extensibility. The software code refactoring is also determined the computer bugs in the system by eliminating redundant levels of complexity.

2. Software refactoring Software Refactoring is generally activated by detecting a code smell (i.e. bad smell). In computer programming code, refers to a few indications in the source code of a program that probably shows a deeper problem or technically incorrect basis. The benefit of the software refactoring is the Maintainability of the software code quality. It is easier to secure bugs since the source code is easy

https://doi.org/10.1016/j.asej.2018.10.005 2090-4479/Ó 2019 The Authors. Published by Elsevier B.V. on behalf of Faculty of Engineering, Ain Shams University. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/).

550

M. Sangeetha, C. Chandrasekar / Ain Shams Engineering Journal 10 (2019) 549–553

Decision tree classifier

Source code

Detect location of code duplication (i.e. code smell)

Classifies code smell type

repository

based on rule

Ada boost classifier Code smell type identification

Identification of refactoring solution Code smell type rectification

Fig. 1. Process of software refactoring.

Improve quality of software to read and its author is easily to seize. This is achieved by reducing large routines into a set of individually abbreviation, well-named, single-purpose techniques. In [1], a monitor-based instant refactoring framework was developed to determine and avoid more code smells rapidly. However, it has high maintenance cost and failed to improve software quality. A dynamic and Automatic Feedback-Based Threshold Adaptation technique was introduced in [2] to detect the code smell in source code. However, the false positive was not reduced to improve the software equality. An automated approach was developed in [3] for detecting the costeffective refactoring with the help of dynamic information in object-oriented software. However, it failed to consider the different types of code smell in software program. Harmfulness code smell model was developed in [4] for identifying and classifying the harmful effect of code smells. But the other types of code smell were not identified. The analysis of four code smells were presented in [5] throughout consecutive versions of two open source system. However the experimental analysis on many software systems and other code smells were not validated. A semi-automated approach was developed in [6] for prioritizing code smells before selecting on suitable refactoring. But, the refactoring cost of such method was high. In [7], multiple linear regressions analysis in which the entire code smells were investigated in the similar model. However, it reduced the software maintenance. Six types of bad smells were detected in [8] which were rectified by using window based graphical user interface. But, it failed to use different metrics to detect more code smells. The different code smell detection tools were compared in [9] by analyzing their accuracy from the reference list. However it failed to achieve software maintenance performances. Parallel Evolutionary algorithm (P-EA) was designed in [10] with a similar cooperative manner for detecting the code-smells. However, the automatic rectification of codesmells was not performed. As shown in Fig. 2, processing diagram of the software refactoring location identification and rectification is described. The local search and applied the refactoring technique to perform rectification process. Initially, each software code is placed inside a gene to perform refactoring process. The refactoring process determines which refactoring is needed in an identified location. Then, it ensures the applied refactoring preserve behaviors. The result of refactoring on software quality characteristics is verified. Finally, preserves the consistency between refactors program code and other software artifacts.

Fig. 2. Processing diagram of the software refactoring location identification and rectification.

Table 1 Comparison of original code and refactored code using refactoring I. S. no

Parameter

Original code

Refactored code

1. 2. 3. 4.

Vocabulary size Number of attributes Number of operation Weighted operations per component Number of statements Lines of code Depth of inheritance tree Number of children Time taken to execute

1 1 2 4

1 1 3 5

8 23 1 0 166.6 ms

9 25 1 0 146 ms

5. 6. 7. 8. 9.

3. Identify the location of software code smell Initially, all the software codes are placed inside a gene to generate the initial population. Each member of this population initiates a better solution based on fitness calculation. At first, the source code is generated randomly [11]. Then the Local search is determine exact location of code bad smell among a number of codes of lines in the source code. After that, every iteration the best individuals (i.e. gens) are selected and the worst ones are altered with new ones generated from the fitness value. Then the local search finds the exact location of code smell where the software code to be refactored. The information about the neighborhood is identified through the fitness calculation. The fitness is measured to select the high quality (i.e. best) and weaker (i.e. low quality) in order to perform software refactoring. Therefore, the weaker code is called as code smell. The fitness function is measured as,

weightðW t Þ ¼ Minfgood code qualityg  Maxfbad code qualityg

ð1Þ

From (1), weightðW t Þis the optimal weights of gene are determined hence the range is large as possible. From the range, the middle point as a threshold to decides whether a gene is a weaker or strong quality.

551

M. Sangeetha, C. Chandrasekar / Ain Shams Engineering Journal 10 (2019) 549–553 Table 2 Comparision of original versus refactored code. Comparision of original versus refactored code Parameter

Bank acc

Tracing agent

Figure stage

Point_introduction

Subject_observer

School mates

Game of tactis

Vocabulary size Number of attributes Number of operations Weighted operations per Number of statements Line of code Depth of inheritance tree Number of children Time taken to execute

3 1 5 12 73 35 8 0 166.5

6 8 34 57 61 134 8 2 230.5

14 11 30 67 53 199 15 3 40.33

5 6 19 29 32 102 10 1 429.33

7 6 16 26 90 137 5 0 171.67

16 79 22 45 37 78 76 33 123.2

16 79 69 127 659 1034 18 0 32.68

 FitnessðFÞ ¼

Wt < Th;

weaker Code

W t > T h ; stronger Code

ð2Þ

From (2), If the quality of a code is calculated with the optimal weights ðW t Þis less than the threshold value, then the code is judged to a weaker code, and refactoring is suggested so that the code is transformed using an appropriate refactoring technique. Based on fitness calculation, the code smell is identified where the refactoring is needed. The design for the refactorings mentioned above has been discussed. The nine refactorings that have been identified are applied on the two systems listed in the previous chapter. Code samples of before the system is refactored and after the system is refactored have been presented (see Tables 1 and 2). 4. Problem In refactoring, the code undergoes changes so that it is able to gather the requirements. ADA BOOSTER is used for dealing with concerns like exception handling, logging, security etc. ADA BOOSTER is now on the threshold of becoming the next established standard in the software industry. a. Separation of Concerns b. A mechanism to describe the concerns that crosscut other components in the system. It is implemented by using a wide set of tools that are specific to that programming language. When refactoring is applied to the existing code, generally the behavior of these programs may change and also the structure of the program may change. So when the programs are refactored, it is necessary to make sure that the behaviour of the program remains same and is preserved. There are a set of refactoring tools available, but all of them do not provide all the functionality and are not general in nature. So, there is a need to find out what are the other refactoring required for ADA BOOSTER and how they will help in maintaining the software.

1. Make the Aspect Unprivileged 2. Replace The Point cut Name With Its Designator 3. Introduce the Get And Set Pointcut, Introduce Before And After Advice 4. Remove the Word Abstract For The Aspect 5. Remove Aspect Inheritance (One Aspect Extends Another Aspect) 5.1. Refactoring I: Make the aspect unprivileged Original Code Here the original code is presented that contains the aspect that is privileged. As discussed in previous chapter, the privileged aspect can access the private data member. In the code there is a variable ‘‘i1” which is declared as private. Since the aspect is declared as privileged, it is able to directly access that variable. privileged aspect MyAspect { static final int M1 = 1000; before(int x1, MyClass ob): call(void MyClass.incI(int)) && target(ob) && args(x1) { if (ob.i1 + x1 > M1) throw new RuntimeException(); } } class MyClass { private int i1 = 0; void incI(int x1) {i1 = i1 + x1;} public static void main(String[] args) { MyClass ob = new MyClass(); ob.incI(10); System .out .println(‘‘Working Prototype”); } }

5. Overview of the solution

5.2. Refactored code

In this, a solution to the problem is proposed by finding out new refactorings in the area of Object Oriented Programming. The refactorings will help the systems to evolve. New refactorings that have been identified will make the task of the programmer easy. The lists of the refactorings identified are as below.

Now let us remove the keyword ‘‘privileged” and refactor the code. The refactored code is presented below. As seen in the refactored code, the place where the variable i1 was accessed is replaced with the method call. This method is declared inside the class and is used in the aspect.

552

M. Sangeetha, C. Chandrasekar / Ain Shams Engineering Journal 10 (2019) 549–553

aspect MyAspect { static final int M1 = 1000; before(int x1, MyClassob): call(void MyClass.incI(int)) && target(ob) && args(x1) { if (ob.getI() + x1 > M1) throw new RuntimeException(); } } class MyClass { private int i1 = 0; void incI(int x1) {i1 = i1 + x1;} int getI() { return i1; } public static void main(String[] args) { MyClass ob = new MyClass(); ob.incI(10); System .out .println(‘‘Working Prototype”); } }

1200 vocbulary size 1000 800 600 400 200 0

Number of aributes number of operaons Weighted operons per Number of statements

Line of code Depth of inheritance tree Number of children

Fig. 4. Time execution after refactoring.

MCA Graduated students. The comparison of original code versus refactored code is presented below given tables. As seen in the graphs mentioned above, when the systems were refactored using the first refactoring the values for vocabulary size, number of attributes, number of children, depth of inheritance tree have remained the same whereas we can see the values for number of operation, weighted operation per component, number of statements, lines of code show changes increase in the values. However the time taken for execution shows decline in the value. Therefore the system executes in less time, thereby giving good performance in of its execution (see Fig. 4). 6. Conclusion

5.3. Results of the original code and the refactored code The original code has been passed to ADA BOOSTER – The tool has given the following results when applied to the original code. When increasing more new requirements software become more complex and software capacity to adopted new requirements need best quality. The refactoring is respect to maintaining the source code (see Fig. 3). 5.4. Screens Above are the screenshots of some systems that have been used for conducting the experiments. The following systems were refactored using the eighth different projects. This work conducted by

Ada-Boost Classifier technique is developed for software code smell type identification and rectification with cost minimization. Adaboost with decision tree classifier is used to improve the software quality. If the source code has a rule which related to code smell, then the classifier classifies the types of code smell is presented. After that, the identified code smells are rectified by applying the refactoring technique with minimum cost and space complexity. Experimental evaluation is conducted using many real time dataset to evaluate the proposed Ada Booster technique in terms of code smell type Identification accuracy, false positive rate, code smell type rectification cost and space complexity. The results analysis of ADA-BOOSTER technique improves software code smell type identification accuracy with minimum false positive rate, code smell type rectification cost and space complexity than the state-of-art methods.

Fig. 3. Code refactoring.

M. Sangeetha, C. Chandrasekar / Ain Shams Engineering Journal 10 (2019) 549–553

Acknowledgements I would like to thanks Periyar University for providing me the Opportunity to study as a research scholar. We are also grateful to the colleague and family members for their continuous support. References [1] Liu Hui, Guo Xue, Shao Weizhong. Monitor-based instant software refactoring. IEEE Trans Software Eng 2013;39(8):1112–26. [2] Liu Hui, Liu Qiurong, Niu Zhendong, Liu Yang. Dynamic and automatic feedback-based threshold adaptation for code smell detection. IEEE Trans Software Eng 2016;42(6):544–58. [3] Han Ah-Rim, Bae Doo-Hwan. Dynamic profiling-based approach to identifying cost-effective refactorings. Inform Softw Technol, Elsevier 2013;55:966–85. [4] Husien Harris Kristanto, Harun Muhammad Firdaus, Lichter Horst. Towards a severity and activity based assessment of code smells. Proc Comput Sci, Elsevier 2017;116:460–7. [5] Chatzigeorgiou Alexander, Manakos Anastasios. Investigating the evolution of code smells in object-oriented systems. Innov Syst Softw Eng, Springer 2014;10(1):3–18. [6] Vidal Santiago A, Marcos Claudia, Andrés Díaz-Pace J. An approach to prioritize code smells for refactoring. Automated Softw Eng, Springer 2016;23 (3):501–32. [7] Sjøberg Dag IK, Yamashita Aiko, Anda Bente CD, Mockus Audris, Dybå Tore. Quantifying the effect of code smells on maintenance effort. IEEE Trans Software Eng 2013;39(8):1144–56. [8] Kaur Sandeep, Kaur Harpreet. Identification and refactoring of bad smells to improve code quality. Int J Sci Eng Res (IJSER) 2015;3(8):99–102. [9] Paiva Thanis, Damasceno Amanda, Figueiredo Eduardo, Sant’Anna Cláudio. On the evaluation of code smells and detection tools. J Softw Eng Res Dev, Springer 2017;5(7):1–28. [10] Kessentini Wael, Kessentini Marouane, Sahraoui Houari, Bechikh Slim, Ouni Ali. A cooperative parallel search-based software engineering approach for code-smells detection. IEEE Trans Software Eng 2014;40(9):841–61.

553

[11] Sangeetha M, Sengottuvelan P. Gene based software refactoring location identification and rectification for software code quality maintenance. Int. J. Comput. Sci. Inform. Secur. (IJCSIS) 2017;15(8).

M. Sangeetha received her B.Sc & M.Sc. degree in Computer Science from Bharathidasan University, Trichy in 1994 and 1999 respectively, also received her M. Phil degree in Periyar University in 2007. Currently she is pursuing her full time research in Computer Science at Periyar University PG Extension centre, Dharmapuri. From 1999 to 2014, she was the Faculty in the Department of computer science, Salem Sowdeswari College, Salem. From 2014 to 2015, she acted as a Vice Principal in Sakthikailash Women’s College, Dharmapuri. Her Professional activities include guided Seven M.Phil Scholars in the field of CS. Also she has Published and presented more than 15 Papers in International and National Journals and also in Conferences. Her current research interests on Software Engineering. She is a Life Member of the IAENG, Hong Kong.

Dr. C. Chandrasekar is the Professor of the Department of Computer Science at Periyar University. He pursued his M.C.A., and awarded Ph.D. His Research Areas are Mobile and Wireless Computing/ 10/521.He have 25 years of teaching experience and 15 years of research interest And he published book on Chandrasekar. C and Venkatesan. K., ‘‘ Introduction to Information Technology”, Serve the People Publications, 2010.