36
Selected Topics of Software Technology 3 Code Smells 1 S C I E N C E P A S S I O N T E C H N O L O G Y u www.tugraz.at Selected Topics of Software Technology 3 Code Smells Birgit Hofer Institute for Software Technology

Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Embed Size (px)

Citation preview

Page 1: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells1

S C I E N C E P A S S I O N T E C H N O L O G Y

u www.tugraz.at

Selected Topics of Software Technology 3

Code Smells

Birgit Hofer

Institute for Software Technology

Page 2: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells2

Spreadsheet

Quality Assurance

Techniques

Visualization

StaticAnalysis

Debugging

Testing

Modeling

Design & Maintenance

Support

Source: Jannach et al. “Avoiding, Finding and Fixing Spreadsheet Errors – A Survey of

Automated Approaches for Spreadsheet QA”, in Journal of Systems and Software, 2014.

Visualization: Patrick Koch,Diploma Seminar, TU Graz, 2015.

Static Analysis

• Code Smells

• Static Checker

Page 3: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells3

Outline

Motivation

Video about Spreadsheet disasters

Code Smells in Software

What smells?

Tools

Code Smells in Spreadsheets

What smells?

Tools

Practical

Page 4: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells4

Outline

Motivation

Video about Spreadsheet disasters

Code Smells in Software

What smells?

Tools

Code Smells in Spreadsheets

What smells?

Tools

Practical

Page 5: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells5

SpreadsheetsThe Ununderstood Dark Matter of IT

Felienne Hermans, Delfth University of Technology

Page 6: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells6

Outline

Motivation

Video about Spreadsheet disasters

Code Smells in Software

What smells?

Tools

Code Smells in Spreadsheets

What smells?

Tools

Practical

Page 7: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells7

What are Code Smells?

Any symptom in the source code of a program that

possibly indicates a deeper problem.

Not bugs, but they increase the risk

of introducing bugs.

Indicate the need of refactoring.

Refactoring

Process of changing a system in such a way that it does not alter the external behavior of the system but improves the internal structure. (Martin Fowler)

Page 8: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells8

Code Smells in Software

Code Smells within Classes

Code Smells between Classes

Coding Standard

Long Methods

Long Parameter List

Duplicated Code

Large Classes

Dead code

Inappropriate Intimacy

Data clumps

Indecent Exposure

Feature Envy

Message Chains

Shotgun Surgery

Lazy Class

Middle Class

Page 9: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells9

Page 10: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells10

Coding standard: final for local variables

Different Persons – different OpinionsA very simple question on StackOverflow:

Why would one mark local variables and method parameters as “final” in Java?

Source: http://stackoverflow.com/questions/316352/why-would-one-mark-local-variables-and-method-parameters-as-final-in-java, visited 2015-10-09

Page 11: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells11

Tools for Detecting Code Smells

Java

Checkstyle

FindBugs

PMD

C/C++

Lint

.Net

CodeIt.Right

Page 12: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells12

Outline

Motivation

Video about Spreadsheet disasters

Code Smells in Software

What smells?

Tools

Code Smells in Spreadsheets

What smells?

Tools

Practical

Page 13: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells13

Relevant Literature

Hermans, Pinzger and van Deursen:

“Detecting Code Smells in Spreadsheet Formulas”,

Int. Conference on Software Maintenance (ICSM) 2012.

Hermans, Pinzger and van Deursen:

“Detecting and visualizing inter-worksheet smells in spreadsheets”,

Int. Conference on Software Engineering (ICSE) 2012.

Kulesz and Ostberg:

“Practical Challenges with Spreadsheet Auditing Tools”,

European Spreadsheet Risks Interest Group Conf. (EuSpRIG), 2013.

Cunha, Fernandes, Ribeiro and Saraiva:

“Towards a Catalog of Spreadsheet Smells”,

Int. Conf. on Computational Science and Its Applications (ICCSA), 2012.

Cunha, Fernandes, Martins, Mendes and Saraiva:

“SmellSheet detective: A tool for detecting bad smells in spreadsheets”,

Symp. on Visual Languages and Human-Centric Computing (VL/HCC) 2012

Page 14: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells14

Formula Smells

Multiple Operations

Multiple References

Conditional Complexity

Long Calculation Chains

Duplicated Formulas

Source: Hermans, Pinzger and van Deursen:

“Detecting Code Smells in Spreadsheet Formulas”,

Int. Conference on Software Maintenance (ICSM) 2012.

Page 15: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells15

Some examples

Source: Jansen and Hermans “Code Smells in Spreadsheet Formulas Revisited on an Industrial Dataset”, ICSME 2015.

Page 16: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells16

Formula Smells

Multiple Operations

Multiple References

Conditional Complexity

Long Calculation Chains

Duplicated Formulas

Source: Hermans, Pinzger and van Deursen:

“Detecting Code Smells in Spreadsheet Formulas”,

Int. Conference on Software Maintenance (ICSM) 2012.

Page 17: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells17

Smell Interactions

Multiple Operations, Multiple References

Long Calculation Chain

Source: Hermans et al.: “Detecting code smells in spreadsheet formulas", ICSM 2012.

Visualization: Patrick Koch,Diploma Seminar, TU Graz, 2015.

Page 18: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells18

Inter-worksheet Smells

Inappropriate Intimacy

Feature Envy

Middle Man

Shotgun Surgery

Source: Hermans, Pinzger and van Deursen “Detecting and visualizing inter-worksheet

smells in spreadsheets”, Int. Conference on Software Engineering (ICSE) 2012.

Page 19: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells19

Exercise

Compute Intimacy, Feature Envy, Middle Man and Shotgun Surgery for the following spreadsheet!

Intimacy (Sheet1) =Intimacy (Sheet2) =Intimacy (Sheet3) = FeatureEnvy(Sheet2!A1) =FeatureEnvy(Sheet2!B1) =FeatureEnvy(Sheet3!A2) =

MiddleMan(Sheet2) = MiddleMan(Sheet3) =ChangingFormulas(Sheet2)=ChangingFormulas(Sheet3) =ChangingWorksheets(Sheet2) =ChangingWorksheets(Sheet3) =

Page 20: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells20

Thresholds

Frequency of

operators

conditionals

are numbers.

Thresholds identify when these numbers are code

smells.

You have to analyze many spreadsheets to derive

good threshold values.

Page 21: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells21

Thresholds

Smell Medium risk High risk Very high risk

Multiple Operators 4 5 9

Multiple References 3 4 6

Conditional Complexity 2 3 4

Message Chain 4 5 7

Duplication 6 9 13

Inappropriate Intimacy 8 16 42

Feature Envy 3 5 7

Middle Man 7 11 19

Shotgun Surgery – Formulas 9 16 30

Shotgun Surgery – Worksheets 2 3 4

Source: Hermans, Pinzger and van Deursen:

“Detecting Code Smells in Spreadsheet Formulas”, Int. Conference on Software Maintenance (ICSM) 2012.

“Detecting and visualizing inter-worksheet smells in spreadsheets”, Int. Conference on Software Engineering (ICSE) 2012.

Page 22: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells22

Other Code Smell for Spreadsheets

Statistical smells

Standard deviation

Type smells

Empty cell

Pattern finder

Content smell

String distance

Reference to empty cells

Functional dependencies based smells

Quasi-Functional Dependencies (QFD)

Source: Cunha, Fernandes, Ribeiro and Saraiva:

“Towards a Catalog of Spreadsheet Smells”,

Int. Conf. on Computational Science and Its Applications (ICCSA), 2012.

Page 23: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells23

Code Smells Examples

Standard deviation

Pattern finder

Empty cellQFD

String distance

Page 24: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells24

Standard Deviation – How to identify data outliers?

Conditional formatting

Page 25: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells25

Empty Cell Smell – How to identify?

Page 26: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells26

Empty Cell Smell – How to identify?

Page 27: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells27

Empty Cell Smell – How to identify?

Page 28: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells28

Empty Cell Smell – How to identify?

Empty cell

Page 29: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells29

Name Target Oo-pendant Introduction Consequence Alleviation

Em

pty

Nu

me

ric

Str

ing

Fo

rmu

la

Work

sheets

Cre

atio

n

Da

ta e

ntr

y

Exp

an

sio

n

Err

oneous

Re

su

lt

Impeded

Qu

alit

y

Ma

nu

al

Assis

ted

Au

tom

ate

d

Std. Deviation ● - ● ● ●

Empty Cell ● - ● ● ● ●

Pattern Finder ● ● ● ● - ● ● ● ●

String Distance ● - ● ● ●

Ref. to empty Cells ● - ● ● ● ●

QFD ● ● - ● ● ●

Mult. Operations ● Long Method ● ● ●

Multi. References ● Many Params. ● ● ●

Cond. Complexity ● - ● ● ● ●

Long Calc.-Chain ● - ● ● ● ●

Dupl. Formulas ● Duplication ● ● ●

Inappr. Intimacy ● Inappr. Intimacy ● ● ● ●

Feature Envy ● Feature Envy ● ● ● ●

Middle Man ● Middle Man ● ● ● ●

Shotgun Surgery ● Shotgun Surgery ● ● ● ●

Source and Visualization: Patrick Koch,Diploma Seminar, TU Graz, 2015.

Page 30: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells30

Tools for Detecting Code Smells

SIF (Spreadsheet Inspection Framework) https://github.com/kuleszdl/Spreadsheet-Inspection-Framework

SmellSheet Detective and FaultySheet Detective http://ssaapp.di.uminho.pt/twiki/bin/view/Main/Software

Breviz Tool developed at TU Delfth, download?

Page 31: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells31

Some remarks

Determining thresholds could be difficult

Handling of false positives

Time-consuming and boring

Configuration

Adjustable

Challenge:

How to convince users of “higher quality” related issues like maintenance?

Page 32: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells32

Some remarks – Output representation

Flat list of findings

Links missing (navigation)

Lists ordered after severity or grouped by type

Separate file

Links missing

Cell coloring and comments added Take care with spreadsheets that rely on conditional formatting

Not too many colors, use intuitive colors

Critical smellNon-critical smell

Page 33: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells33

Outline

Motivation

Video about Spreadsheet disasters

Code Smells in Software

What smells?

Tools

Code Smells in Spreadsheets

What smells?

Tools

Practical

Page 34: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells34

Practical – PART 1 (Testing)

No Paper Title Student

1 Improving Spreadsheet Test Practices Thomas

2 What You See Is What You Test Christian

3 Automated Test Case Generation for Spreadsheets David

4 AutoTest: A Tool for Automatic Test Case Generation in

SpreadsheetsAndreas

5 End-User Software Engineering with Assertions in the

Spreadsheet ParadigmAnja

6 Test-Driven Development: Can it Work for Spreadsheets?

+ Using Calculation Fragments for Spreadsheets-

Page 35: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells35

Outline

Motivation

Video about Spreadsheet disasters

Code Smells in Software

What smells?

Tools

Code Smells in Spreadsheets

What smells?

Tools

Practical

Page 36: Selected Topics of Software Technology 3 Code … Topics of Software Technology 3 10 Code Smells Coding standard: final for local variables Different Persons –different Opinions

Selected Topics of Software Technology 3

Code Smells36

Next Week

Talking about apples and orangesStatic analysis techniques – Part II

UCheck CheckCell

If we are on time, we will also start with

Spectrum-based Fault Localization

Please bring a computer or ad least a calculator