112
ThoughtWorks ThoughtWorks NEAL FORD software architect / meme wrangler ThoughtWorks [email protected] 3003 Summit Boulevard, Atlanta, GA 30319 www.nealford.com www.thoughtworks.com blog: memeagora.blogspot.com twitter: neal4d visualizations for code metrics

Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

ThoughtWorksThoughtWorks

NEAL FORD software architect / meme wrangler

ThoughtWorks

[email protected] 3003 Summit Boulevard, Atlanta, GA 30319

www.nealford.com

www.thoughtworks.com

blog: memeagora.blogspot.com

twitter: neal4d

visualizations for code metrics

Page 2: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

housekeepingask questions anytime

download slides from nealford.com

download samples from github.com/nealford

Page 3: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

point it to a subversion repository

code_swarm

http://code.google.com/p/codeswarm/

useful? cool!

visualization of check-ins over time

what was that?

Page 4: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

http://www.wired.com/wired/issue/16-07

Page 5: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 6: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

wtf’s/min

Page 7: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

external perspective

is the software valuable to its users?

Page 8: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

how easy is it to understand & extend?

how appropriate is the design?

how amenable is emergent design?

is it salvageable?

how maintainable is it?

internal perspective

Page 9: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

30,000 feet ground level

http://opensimulator.org/wiki/Grid_Architecture_Diagram

Page 10: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

where are the defects?

Page 11: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

which way do the messages flow?

Page 12: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

systems evolve locally, often uncontrolled

models created up front convey a vision but usually don’t reflect reality

generating a complete model for large systems is nearly impossible

need tools to create ad-hoc models more easily

the best picture very much depends on the question you are trying to answer

where do the pictures come from?

Page 13: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

a class is a box with name, methods, fields,...

a model that describes a model

example: meta-model for a class diagram

rules: no circles in inheritance, etc.

available connectors: association, inheritance, aggregation…

1. select a meta-model

Page 14: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

common meta-models

Clas

s

M1 M2 M3

Foo 3.4 3.8 6.5

Bar 5.0 0.0 10.0

… … … …

M1

M2

Foo

Bar

xyz

M1

Metrics (Quantitative) Directed Graph

Tree Process Model (e.g. Petri Net)

Page 15: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

byte code

static analysis

source code

profiling, listen to messages, log files, network sniffer, etc.

dynamic analysis

2. inspection / instrumentation

Page 16: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

3. mapping to the model

Mapper

Comp. Channel

A X

B Y

Comp. Channel

C X

C Y

Senders Receivers

Nodes: A, B, CEdges: X(A!C) Y(B!C)

Graph Model

example: messaging system

capture send/receive actions

map onto directed graph

Page 17: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

4. visualization &...

Graphviz

Page 18: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

enforce rules or best practices

don’t simply observe

verify & alert

islands on a dependency graph

detect cycles

...validation

Page 19: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

the hawthorne effect

Page 20: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

measure and let it be known that you are measuring

the hawthorne effect

Page 21: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

metrics

Page 22: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

cyclomatic complexitymeasures complexity of a function

V(G)= e - n + 2V(G) = cyclomatic complexity of Ge= # edgesn= # of nodes

Page 23: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

start

if (c1)

f1() f2()

if (c2)

f3() f4()

end

start

if (c1)

f1() f2()

if (c2)

f3() f4()

end

7

65

4

32

1

8

7

65

4

3

2

1

nodes

edges

Page 24: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

chidamber & kemererobject-oriented metrics

shyam r chidamberchris f kemerer

easy but not terribly useful very useful

Page 25: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

easy (but trivial)

dit depth of inheritance tree # levels of inheritance

noc number of children # immediate descendants

npm number of public methods

# public methods in class

Page 26: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

very usefulwmc weighted methods/

class ∑ of cyclomatic complexity

rfc response for class # of methods executed due to method call

lcom lack of cohesion ∑ of sets of methods not shared via sharing fields

cbo/ce

efferent couplings ∑ of other classes this class uses (outgoing calls)

ca afferent couplings ∑ of how many other classes use this class (incoming calls)

Page 27: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

visualizations

Page 28: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

lines, statements, % branches, calls, % comments, classes, methods/class, avg stmts/method, max complexity, max depth, average depth, average complexity

freeware tool for gathering metrics

metrics:

graphical user interface, windows only!

source monitor

Page 29: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

source monitor:kiviat graphs

Page 30: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

source monitor:class summary

Page 31: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

source monitor w/ c#

Page 32: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

classes that violate several kiviat graph ranges

really odd shapes

looking for...

Page 33: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

“A project dedicated to making code metrics so widely understood, valuable, and simple that their use becomes ubiquitous, thus raising the quality of software across

the industry.”

Page 34: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

jdepend

code coverage with emma1-line change to switch to cobertura

checkstyle1-line switch for custom rule sets

volatility

javancss

panopticode parts

code duplication using simian

aggregator & reports

treemaps

Page 35: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

complexity treemap

Page 36: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 37: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

code coverage

Page 38: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

20,000 foot view along a single dimension

simple view of one dimension

information radiators

looking for...

Page 39: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

allows comparison to “industry standards”

developed at Universities of Berne and Lugano

shows key metrics and their relationships

created by iPlasma tool from source code

size & complexity pyramid

Page 40: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

pyramid5.75 NOP 224

6.13 NOC 12895.69 NOM 7905 7905 NOM 2.79

0.26 LOC 44988 22039 CALLS 0.40CYCLO 11602 8798 FANOUT

Page 41: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

iPlasma + Struts

Page 42: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 43: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

vuze

Page 44: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

low cyclomatic complexity / line

adherence to industry standards

low number of lines / method (see composed method pattern)

looking for...

Page 45: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

GraphViz

Page 46: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

e v e n t l i s t

d o t

f i l e

Page 47: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

output

Page 48: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

generating dot files

Page 49: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

untangling jars

Kirk Knoernschildwww.kirkk.com

jar analyzer

Page 50: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

xml output

Page 51: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

t r a n s f o r m e d

Page 52: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

graphical

struts 1.0

Page 53: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 54: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 55: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

no “rats’ nests”

not that!

small number of one-way dependencies

no cycles

looking for...

Page 56: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

Vizantant task to create a GraphViz DOT file from an ant build file

http://vizant.sourceforge.net/

Page 57: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

ant 1.5

Page 58: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

log4j

Page 59: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

tomcat 3.3.1

Page 60: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

from=“dist”

Page 61: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

to=“prepare”

Page 62: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

networks around common dependent elements

hot spots

more even distribution

think about extracting via macrodef

look for...

Page 63: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

SpringVizXSLT => DOT for spring

dependencies

http://www.samoht.com/wiki/wiki.pl?SpringViz

Page 64: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 65: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 66: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

SpringViz

Page 67: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

overloaded dependencies

regularity

symmetry

isolated pockets

look for...

Page 68: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

toxicity chart

provides easy to compare overview of quality

created with checkstyle + excel

Page 69: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

toxicity chart

0.0

5.0

10.0

15.0

20.0

25.0

30.0

35.0

40.0

Ses

sio

nF

acto

ryU

tils

.jav

a

Abs

tra

ctB

ea

nF

ac

tory

.java

Bea

nW

rapp

erI

mp

l.ja

va

Dis

pa

tch

erS

erv

let.

java

Sch

ed

ule

rFa

cto

ryB

ea

n.ja

va

AntP

ath

Ma

tch

er.

jav

a

SQ

LE

rro

rCo

de

SQ

LE

xc

eptio

nT

rans

lato

r.ja

va

Hib

ern

ate

Te

mp

late

.ja

va

Re

load

able

Re

so

urc

eB

und

leM

ess

age

So

urc

e.ja

va

Pro

pe

rtie

sB

ea

nD

efi

nitio

nR

ead

er.

jav

a

Sta

tem

entC

reato

rUtils

.jav

a

Lazy

Co

nn

ec

tio

nD

ata

So

urc

eP

rox

y.ja

va

De

fau

ltM

ess

ag

eL

iste

ne

rCo

nta

ine

r.ja

va

Jd

oTra

ns

actio

nM

an

ag

er.

jav

a

To

pLin

kT

rans

actio

nM

an

ag

er.

jav

a

Scrip

tFa

cto

ryP

os

tPro

ce

sso

r.ja

va

Tra

ns

ac

tio

nA

wa

reC

on

ne

ctio

nF

acto

ryP

roxy

.jav

a

Nu

mb

erU

tils

.ja

va

Hib

ern

ate

Acc

ess

or.

jav

a

Sprin

gS

ess

ionS

yn

ch

ron

iza

tio

n.ja

va

Bea

nD

efi

nitio

nV

alu

eR

eso

lve

r.ja

va

Exte

nde

dE

ntity

Ma

nag

erC

reato

r.ja

va

Para

me

terM

eth

od

Na

me

Re

so

lve

r.ja

va

Ca

llab

leS

tate

me

ntC

reato

rFa

cto

ry.jav

a

Bea

nF

acto

ryA

sp

ec

tJA

dvis

ors

Build

er.

java

Cu

sto

miz

able

Tra

ce

Inte

rce

pto

r.ja

va

Abs

tra

ctX

slt

Vie

w.ja

va

Gen

eric

Co

llectio

nT

yp

eR

eso

lve

r.ja

va

Arg

um

entC

onv

ert

ingM

eth

od

Inv

oke

r.ja

va

Sha

red

Entity

Ma

nag

erC

reato

r.ja

va

Fre

eM

ark

erC

onfi

gura

tio

nF

acto

ry.ja

va

Sele

cte

dV

alu

eC

om

pa

rato

r.ja

va

Mo

ck

Htt

pS

erv

letR

eq

ue

st.ja

va

Fra

me

wo

rkP

ort

let.

jav

a

Re

so

urc

eA

rra

yP

rope

rty

Edit

or.

java

Asp

ec

tJW

ea

ve

rMe

ss

ag

eH

and

ler.

java

Me

tho

dM

apT

rans

ac

tio

nA

ttrib

ute

Sou

rce

.ja

va

Sin

gle

Co

nne

ctio

nF

ac

tory

.ja

va

Me

ss

age

Lis

ten

erA

dap

ter.

jav

a

Jd

oTe

mp

late

.ja

va

Da

taS

ou

rce

Utils

.ja

va

Velo

cit

yV

iew

.ja

va

Abs

tra

ctM

es

sa

ge

Lis

ten

erC

onta

iner.

java

SqlL

ob

Valu

e.ja

va

Port

letR

eq

ue

stH

an

dle

dE

ve

nt.

jav

a

Jd

bcO

pe

ratio

ns

.ja

va

Tx

Adv

ice

Bea

nD

efi

nitio

nP

ars

er.

java

Arg

Ty

pe

Pre

pare

dS

tate

me

ntS

ett

er.

jav

a

Re

fre

sh

ab

leP

ag

edL

istH

old

er.

java

Abs

tra

ctJ

asp

erR

ep

ort

sS

ing

leF

orm

atV

iew

.ja

va

Cla

ss

Utils

.ja

va

Sim

ple

Ma

ilMe

ss

age

.ja

va

Jm

sT

rans

ac

tio

nM

ana

ge

r.ja

va

Tra

ns

ac

tio

nA

ttrib

ute

Edit

or.

jav

a

De

fau

ltB

ea

nD

efi

niti

onD

oc

um

entR

ea

de

r.ja

va

Abs

tra

ctI

nte

rce

pto

rDriv

en

Be

an

De

fin

itio

nD

eco

rato

r.ja

va

Re

su

ltS

etW

rapp

ing

Sq

lRo

wS

et.

jav

a

Hs

qlM

ax

Valu

eIn

cre

me

nte

r.ja

va

Co

deb

as

eA

wa

reO

bje

ctI

np

utS

tre

am

.ja

va

Abs

tra

ctS

ing

leto

nP

roxy

Fa

cto

ryB

ea

n.jav

a

Loc

alS

lsb

Inv

oke

rIn

terc

ep

tor.

java

Bea

ns

Dtd

Re

so

lve

r.ja

va

Abs

tra

ctM

es

sa

ge

So

urc

e.ja

va

Abs

tra

ctD

ep

en

de

nc

yIn

ject

ionS

prin

gC

onte

xtT

es

ts.ja

va

To

mc

atI

ns

tru

me

nta

ble

Cla

ss

Loa

de

r.ja

va

Loc

alC

onta

inerE

ntity

Ma

na

gerF

acto

ryB

ea

n.ja

va

Re

so

urc

eE

ntity

Re

solv

er.

java

Re

dire

ctV

iew

.ja

va

Htm

lCh

ara

cte

rEn

tity

Ref

ere

nce

s.ja

va

Abs

tra

ctP

ath

Ma

pH

an

dle

rMa

pp

ing

.ja

va

Asp

ec

tJP

rec

ed

en

ce

Co

mp

ara

tor.

java

Re

so

urc

eS

erv

let.

java

Adv

ise

dS

upp

ort

.ja

va

EhC

ach

eF

ac

tory

Bea

n.ja

va

Cu

sto

mC

olle

ctio

nE

dit

or.

java

Co

mm

ons

Mu

ltip

art

File

.ja

va

Ope

nE

ntity

Ma

na

ge

rIn

Vie

wF

ilte

r.ja

va

To

pLin

kIn

terc

epto

r.ja

va

Me

tho

dIn

vo

kin

gJ

ob

De

tailF

acto

ryB

ea

n.ja

va

De

fau

ltN

am

es

pa

ce

Ha

ndle

rRe

solv

er.

jav

a

Xm

lValid

atio

nM

od

eD

ete

cto

r.ja

va

Gen

eric

Filt

erB

ea

n.ja

va

He

ss

ianS

erv

ice

Exp

ort

er.

java

Pro

pe

rty

Acc

es

so

rUtils

.jav

a

Insta

ntia

tio

nM

ode

lAw

are

Poin

tcu

tAdv

iso

rIm

pl.

java

BooleanExpressionComplexity ClassDataAbstractionCoupling ClassFanOutComplexity CyclomaticComplexity FileLength MethodLength NestedIfDepth AnonInnerLength ParameterNumber MissingSwitchDefault TreeWalker

Page 70: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

test to code ratioLines of unit test code per line of production code

1 2 3 3.053.1 4 5 6 7 8 9 10 11 12 13 14 15 16 17

0.80

1.00

1.20

1.40

1.60

1/4/06

15/4/06

29/4/06

13/5/06

27/5/06

10/6/06

24/6/06

8/7/06

22/7/06

5/8/06

19/8/06

2/9/06

16/9/06

30/9/06

14/10/06

28/10/06

11/11/06

25/11/06

9/12/06

23/12/06

6/1/07

20/1/07

3/2/07

17/2/07

3/3/07

17/3/07

31/3/07

14/4/07

28/4/07

12/5/07

26/5/07

9/6/07

23/6/07

7/7/07

21/7/07

4/8/07

18/8/07

Releases Unit test LOC/LOC

created using unix tools + excel

Page 71: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

cc / loc / releases

Page 72: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

test-to-code ratio: higher is better

notifications along your key dimension

toxicity: high-spikes

deltas more interesting than raw numbers

complexity / loc: trends

look for...

Page 73: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

founded in Stockholm by Ola Rosling, Anna Rosling Rönnlund and Hans Rosling

“Unveiling the beauty of statistics for a fact based world view.”

time-based statistical view of chart data

now realized in the google spreadsheet motion gadget

Page 74: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 75: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

the data

Page 76: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

motion chart gadget

Page 77: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

symmetry

time-based trends

odd outliers along dimensions

fluidity

look for...

Page 78: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

CodeCrawlerwww.inf.unisi.ch/faculty/lanza/codecrawler.html

Page 79: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

CodeCrawler

Page 80: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

written in VisualAge Smalltalk

academic graphical metrics tool

language independent

quirky but powerful

based on the Moose platform

CodeCrawler

Page 81: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

provides system complexity view, class & package dependency view

graduate student project written by Jacopo Malnati (http://atelier.inf.unisi.ch/~malnatij/xray.php)

open-source software visualization plug-in for eclipse

model of the underlying Java project can be triggered and used by other plug-ins

x-ray

Page 82: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

x-ray visualizing itself through via system complexity view

Page 83: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

x-ray creates textual information and actions

install the plug-in

choose the Analyze Current Project action from the package explorer

visualizations characterized by entities positioned according to layouts and criterions

using x-ray

Page 84: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

actions

project name

# classes

# methods# packages

lines of code

show dependencies

color tag

show/hide nodes

show/hide package content

open selected classes

snapshot image

Page 85: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

class dependency view

system complexity view

package dependency view

polymetric views

Page 86: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

system complexity view

Page 87: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

anomalies of shape (provided by the inheritance tree)

tries to illustrate disharmonies in the design and implementation of a system.

identify big nodes (compared to the others)

view provides several different dimensions of metrics

system complexity view

Page 88: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

positional metrics

Page 89: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

system complexity view

Page 90: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

color metrics

Page 91: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

system complexity view

Page 92: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

Azureus 3.0 (more than

500,000 lines of code)

x-ray itself

Page 93: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

dependencies

incoming

outgoing

Page 94: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

class & package dependency views

Page 95: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

class dependency view

Page 96: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

package dependency

Page 97: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

Azureus packages

Page 98: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

filtering (< 30 weight)

Page 99: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

proximity alert

Page 100: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

exuberant responsibility

towers (=> lots of code, lots of methods)

tangled dependencies

balance

natural partitions

look for...

Page 101: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

10,000 ft view (literally)

CodeCity by Richard Wettel

http://www.inf.unisi.ch/phd/wettel/codecity.html

Page 102: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

written in VisualWorks Smalltalk, atop the Moose platform

integrated environment for software analysis

software systems are visualized as interactive, navigable 3D cities

packages => districts

classes => buildings

CodeCity

Page 103: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

citylyzer

Page 104: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

building height => number of methods

written atop x-ray

inspired by CodeCity

packages => districts

width/length => number of attributes

Citylyzer

Page 105: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 106: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 107: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 108: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319
Page 109: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

overly crowded neighborhoods

“real” cityscape

buildings that wouldn’t exist in the real world

would you live there?

abandoned parts of town

look for...

Page 110: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

discuss on iteration boundaries

wire metrics & analysis into continuous integration

manually check often

fail the build with: xpath expressions & plugins jdepend-like unit tests

metrics + agility

Page 111: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

single dimensions

intermediate altitude

information radiators

cool!

compelling evidence

summary

Page 112: Vizualizations for Code Metrics - Jfokus...ThoughtWorks NEAL FORD software architect / meme wr angle r Thought Works nford@thoughtw orks.com 3003 Summit Boule vard, Atlanta, GA 30319

ThoughtWorks

This work is licensed under the Creative Commons Attribution-Share Alike 3.0 License.

http://creativecommons.org/licenses/by-sa/3.0/us/

?’splease fill out the session evaluationssamples at github.com/nealford

NEAL FORD software architect / meme wrangler

ThoughtWorks

[email protected] 3003 Summit Boulevard, Atlanta, GA 30319

www.nealford.com

www.thoughtworks.com

blog: memeagora.blogspot.com

twitter: neal4d