machine learning techniques for code smell …...on the diffuseness and the impact on...

67
Machine Learning Techniques for Code Smell Detection: A Systematic Literature Review and Meta-Analysis (2019) Веселов Иван 20 февраля 2019

Upload: others

Post on 06-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Machine Learning Techniques for Code Smell Detection: A Systematic Literature

Review and Meta-Analysis (2019)Веселов Иван

20 февраля 2019

Page 2: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Code smell

Термин, обозначающий код с признаками проблем в системе.

2/67

Page 3: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Feature envy

3/67

Page 4: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Поиск потенциальных ошибок

4/67

Page 5: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Identification of Move Method Refactoring Opportunities (2009)

5/67

Page 6: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Identification of Move Method Refactoring Opportunities (2009)

6/67

Page 7: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Существующие проблемы

1. Code smell не всегда означает наличие проблемы

2. Существующие детекторы находят разные code smell

3. Часто детекторы требуют настройки параметров

7/67

Page 8: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Существующие проблемы

1. Code smell не всегда означает наличие проблемы

2. Существующие детекторы находят разные code smell

3. Часто детекторы требуют настройки параметров

F. A. Fontana, J. Dietrich, B. Walter, A. Yamashita, M. Zanoni, Antipattern and code smell false positives: Preliminary conceptualization and classification, in: Software Analysis, Evolution, and Reengineering (SANER), 2016 IEEE 23rd International Conference on, Vol. 1, IEEE, 2016, pp. 609–613.

8/67

Page 9: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

404

Page 10: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Subtype knowledge anti-pattern

10/67

Page 11: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Subtype knowledge anti-pattern

11/67

Page 12: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Существующие проблемы

1. Code smell не всегда означает наличие проблемы

2. Существующие детекторы находят разные code smell

3. Часто детекторы требуют настройки параметров

F. A. Fontana, P. Braione, M. Zanoni, Automatic detection of bad smells in code: An experimental assessment., Journal of Object Technology 11 (2) (2012) 5–1.

12/67

Page 13: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Наивная оценка согласияПоиск feature envy

Метод проекта A.foo() A.getValue(int) ... Z.destroy()

Детектор 1 smelly smelly ... OK

Детектор 2 OK smelly ... smelly

Детектор 3 smelly smelly ... OK

13/67

Page 14: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Наивная оценка согласияПоиск feature envy

Метод проекта A.foo() A.getValue(int) ... Z.destroy()

Детектор 1 smelly smelly ... OK

Детектор 2 OK smelly ... smelly

Детектор 3 smelly smelly ... OK

14/67

Page 15: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Наивная оценка согласия

15/67

Page 16: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Cohen's kappa

16/67

Page 17: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Fleiss' kappa

17/67

Page 18: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Существующие проблемы

1. Code smell не всегда означает наличие проблемы

2. Существующие детекторы находят разные code smell

3. Часто детекторы требуют настройки параметров

E. Fernandes, J. Oliveira, G. Vale, T. Paiva, E. Figueiredo, A review-based comparative study of bad smell detection tools, in: Proceedings of the 20th International Conference on Evaluation and Assessment in Software Engineering, EASE ’16, ACM, New York, NY, USA, 2016, pp. 18:1–18:12. doi:10.1145/2915970.2915984 18/67

Page 19: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Существующие проблемы

1. Code smell не всегда означает наличие проблемы

2. Существующие детекторы находят разные code smell

3. Часто детекторы требуют настройки параметров

19/67

Page 20: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

ML может помочь

1. Code smell не всегда означает наличие проблемы

2. Существующие детекторы находят разные code smell

3. Часто детекторы требуют настройки параметров

20/67

Page 21: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Machine Learning Techniques for Code Smell Detection: A

Systematic Literature Review and Meta-Analysis

Page 22: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Поиск статей

22/67

Page 23: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Research questions

● RQ1: Code smells considered

● RQ2: Machine Learning Setup

● RQ3: Evaluation Setup

● RQ4: Performance Meta-Analysis

23/67

Page 24: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Research questions

● RQ1: Code smells considered

● RQ2: Machine Learning Setup

● RQ3: Evaluation Setup

● RQ4: Performance Meta-Analysis

24/67

Page 25: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Code smells considered

25/67

Page 26: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Опасные code smells

26/67

Page 27: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

ML нужен не везде

27/67

Page 28: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Research questions

● RQ1: Code smells considered

● RQ2: Machine Learning Setup

● RQ3: Evaluation Setup

● RQ4: Performance Meta-Analysis

28/67

Page 29: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Machine Learning Setup

● RQ2.1: What independent variables have been considered?

● RQ2.2: What classification types have been considered?

● RQ2.3: What machine learning algorithms have been used?

● RQ2.4: What training strategies have been proposed?

29/67

Page 30: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Machine Learning Setup

● RQ2.1: What independent variables have been considered?

● RQ2.2: What classification types have been considered?

● RQ2.3: What machine learning algorithms have been used?

● RQ2.4: What training strategies have been proposed?

30/67

Page 31: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Метрики Чидамбера и Кемерера (CK)

● WMC

● DIT

● NOC

● CBO

● RFC

● LCOM1

31/67

Page 32: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Depth of Inheritance Tree

● DIT (C0) = 0

● DIT (C0’) = 0

● DIT (C1) = 1

● DIT (C2) = 2

● DIT (C3) = 3

● DIT (C4) = 432/67

Page 33: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Response For a Class

33/67

Page 34: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Метрики процесса

● Количество изменений

● Время существования файла

● Похожесть имен файлов

34/67

Page 35: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Текстовая информация

35/67

Page 36: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Альтернативы● Метрики ориентированные на разработчика

● A. Perez , R. Abreu , Framing program comprehension as fault localization, J. Softw. 28 (10) (2016) 840–862.

● J. Padilha , J. Pereira , E. Figueiredo , J. Almeida , A. Garcia , C. Santanna , On the effectiveness of concern metrics to detect code smells: an empirical study, in: International Conference on Advanced Information Systems Engineering, Springer, 2014, pp. 656–671.

36/67

Page 37: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Альтернативы● Метрики ориентированные на разработчика

● A. Perez , R. Abreu , Framing program comprehension as fault localization, J. Softw. 28 (10) (2016) 840–862.

● J. Padilha , J. Pereira , E. Figueiredo , J. Almeida , A. Garcia , C. Santanna , On the effectiveness of concern metrics to detect code smells: an empirical study, in: International Conference on Advanced Information Systems Engineering, Springer, 2014, pp. 656–671.

37/67

Page 38: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Scattering and Tangling

38/67

Page 39: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Machine Learning Setup

● RQ2.1: What independent variables have been considered?

● RQ2.2: What classification types have been considered?

● RQ2.3: What machine learning algorithms have been used?

● RQ2.4: What training strategies have been proposed?

39/67

Page 40: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Виды классификации

● Нет smell

● Есть не критичный smell

● Есть обычный smell

● Есть критичный smell

40/67

Page 41: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Machine Learning Setup

● RQ2.1: What independent variables have been considered?

● RQ2.2: What classification types have been considered?

● RQ2.3: What machine learning algorithms have been used?

● RQ2.4: What training strategies have been proposed?

41/67

Page 42: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Использованные алгоритмы

42/67

Page 43: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Использованные алгоритмы

● Нужно внимательнее относиться к настройке гиперпараметров

● Ансамбли мало исследованы

43/67

Page 44: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Machine Learning Setup

● RQ2.1: What independent variables have been considered?

● RQ2.2: What classification types have been considered?

● RQ2.3: What machine learning algorithms have been used?

● RQ2.4: What training strategies have been proposed?

44/67

Page 45: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Подходы к разбиению датасета

45/67

Page 46: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Research questions

● RQ1: Code smells considered

● RQ2: Machine Learning Setup

● RQ3: Evaluation Setup

● RQ4: Performance Meta-Analysis

46/67

Page 47: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Evaluation Setup

● RQ3.1: What types of validation techniques have been exploited?

● RQ3.2: Which have been the evaluation metrics?

● RQ3.3: Which have been the datasets considered?

47/67

Page 48: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Evaluation Setup

● RQ3.1: What types of validation techniques have been exploited?

● RQ3.2: Which have been the evaluation metrics?

● RQ3.3: Which have been the datasets considered?

48/67

Page 49: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Способы тестирования

49/67

Page 50: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Рекомендации

Hall, T., Beecham, S., Bowes, D., Gray, D., & Counsell, S. (2012). A Systematic Literature Review on Fault Prediction Performance in Software Engineering. IEEE Transactions on Software Engineering, 38(6), 1276–1304. doi:10.1109/tse.2011.103

50/67

Page 51: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Evaluation Setup

● RQ3.1: What types of validation techniques have been exploited?

● RQ3.2: Which have been the evaluation metrics?

● RQ3.3: Which have been the datasets considered?

51/67

Page 52: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Метрики оценки

52/67

Page 53: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Метрики оценки

Нужно меньше использовать метрики, которые зависят от threshold значения

53/67

Page 54: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Evaluation Setup

● RQ3.1: What types of validation techniques have been exploited?

● RQ3.2: Which have been the evaluation metrics?

● RQ3.3: Which have been the datasets considered?

54/67

Page 55: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Датасеты

55/67

Page 56: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Датасеты

● Большинство исследований используют маленькие датасеты (до 8 проектов)

● Только в одном исследовании датасет разметили вручную

56/67

Page 57: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Датасеты● F. Palomba , D. Di Nucci , M. Tufano , G. Bavota , R. Oliveto , D.

Poshyvanyk, A. DeLucia , Landfill: an open dataset of code smells with public evaluation, in: Mining Software Repositories (MSR), 2015 IEEE/ACM 12th Working Conference on, IEEE, 2015, pp. 482–485 .

● F. Palomba , G. Bavota , M. Di Penta , F. Fasano , R. Oliveto , A. De Lucia, On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017) 1–34.

57/67

Page 58: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Датасеты● F. Palomba , D. Di Nucci , M. Tufano , G. Bavota , R. Oliveto , D.

Poshyvanyk, A. DeLucia , Landfill: an open dataset of code smells with public evaluation, in: Mining Software Repositories (MSR), 2015 IEEE/ACM 12th Working Conference on, IEEE, 2015, pp. 482–485 .

● F. Palomba , G. Bavota , M. Di Penta , F. Fasano , R. Oliveto , A. De Lucia, On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017) 1–34.

58/67

Page 59: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

404

Page 60: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Датасеты● F. Palomba , D. Di Nucci , M. Tufano , G. Bavota , R. Oliveto , D.

Poshyvanyk, A. DeLucia , Landfill: an open dataset of code smells with public evaluation, in: Mining Software Repositories (MSR), 2015 IEEE/ACM 12th Working Conference on, IEEE, 2015, pp. 482–485 .

● F. Palomba , G. Bavota , M. Di Penta , F. Fasano , R. Oliveto , A. De Lucia, On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017) 1–34.

60/67

Page 61: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Датасеты

● 395 релизов 30 open-source проектов

● 13 видов code smell

● 17,350 провалидированых случаев

● Реальных code smell не так много

61/67

Page 62: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Research questions

● RQ1: Code smells considered

● RQ2: Machine Learning Setup

● RQ3: Evaluation Setup

● RQ4: Performance Meta-Analysis

62/67

Page 63: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Метаанализ

● Effect Size

● Hedges’ g

● Inverse-variance method

63/67

Page 64: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Влияние фичей

● Нужно выбирать не произвольные фичи

● Фичи должны подбираться под решаемую задачу

64/67

Page 65: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Влияние алгоритмов

Если выбрать неподходящий алгоритм, то результаты могут оказаться плохими

65/67

Page 66: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Влияние разбиения датасета

● Within-project работает лучше

● Возможно, переобучение

66/67

Page 67: Machine Learning Techniques for Code Smell …...On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng. (2017)

Q&A