SlideShare ist ein Scribd-Unternehmen logo
1 von 61
Thomas Haug
MATHEMA Software GmbH
80% der
 Projektkosten
fallen nach der
Entwicklung an


                  http://users.jyu.fi/~koskinen/smcosts.htm
Thin Client                Thick Client

         Presentation layer

           Application layer

           Integration layer

Database      Filesystem       Legacy system
Thin Client                Thick Client

         Presentation layer
                                          KEEP IT
           Application layer              SIMPLE
           Integration layer              STUPID.
Database      Filesystem       Legacy system
© by AskDaveTaylor at flickr
© by D'Arcy Norman at flickr




                 9
> Process
   –   Test Driven Development
   –   Short development cycles
> Runtime Analysis
   –   Test Coverage
   –   Memory Analysis
   –   Deadlock Detection
   –   Monitoring / Logging
> Static Code Analysis
   –   Design and Code guidelines
   –   → Design- and Code Reviews
   –   Static analysis tools
   –   Metrics                      10
 Motivation
 Metriken Überblick
 Metriken kombinieren
 Zusammenfassung, Literatur
   und Werkzeuge




                               © Emi Yanez @ Flickr
70er Jahre
         Basis Metrics



SLOC     Complexity      ...


LOC    McCabe    Halstead
Quellcodezeilen (Source Lines of Code - SLOC)

 Physikalische Codezeilen (Lines of code - LOC)
   o Abzählen von Codezeilen, Kommentare und Klammern


 Logische Codezeilen (Logical lines of code - lLOC und
  Non Commented Source Statements -NCSS)
   o Abzählen von Anweisungen



           “Measuring programming progress by lines of code is
            like measuring aircraft building progress by weight”
                                                          Bill Gates
 LOC vs lLOC


 for (int i = 0; i < 10; i++)            LOC = 2
    System.out.println(i + ". value");   lLOC = 2



 for (int i = 0; i < 10; i++)
 {
    // print to console                  LOC = 5
    System.out.println(i + ". value");   lLOC = 2
 }
 Cyclomatic Komplexität (CC(N))
                                             function gcd (x, y)
 McCabe, 1976

                                                  while (y>0)

              p: Anzahl der Komponenten
              e: Anzahl der Kanten (edges)       rest = x % y
              n: Anzahl der Knoten (nodes)           x=y
                                                   y = rest

 Beispiel
                                                   return x
             CC = 4 – 4 + 2*1 = 2
Original McCabe values        PMD (per method)
 1-10 : low complexity         1-4   : low complexity
11-20 : medium complexity      5-7   : medium complexity
21-50 : high complexity       8-10   : high complexity
> 51 : very high complexity   > 11   : very high complexity




                                 http://www.enerjy.com/blog/?p=198
165 Methoden




  CC > 11 : very high complexity
? Kopplung ?
? Kopplung ?
               ? Vererbung ?
Software Metrics

  70er Jahre                                            90er Jahre
         Basis Metrics                            O-O Metrics



SLOC     Complexity      ...         CK            MOOD         LK     ...


LOC    McCabe    Halstead      WMC          ...   MHF     ...    ...   ...
 Basis Metriken decken wichtige Aspekte der Objekt-Orientierung nicht ab


 OO Metriken messen alle drei Dimensionen
   o Größe und Komplexität
   o Kopplung
   o Vererbung


 Unüberschaubare Anzahl an Metriken vorhanden (>= 375)


 Beispiel
   o Chidamber und Kemerer (CK) Metric suite (1994)
        WMC, CBO, DIT, NOC, RFC, LCOM
   o Robert C. Martin Metrics (1994)
       Coupling, Stability, Abstractness,...
 Weighted Method Count (WMC)




                                Sehr hohe Klassen-
                                komplexität, aber
                                durchschnittliche
                                Methodenkom-
            .                   plexität ist niedrig
            .
            .
                                Sehr hohe Klassen-
                                komplexität, durch-
                                schnittliche Methoden-
                                komplexität ist hoch /
                                sehr hoch
 Coupling Between Object Classes (CBO)



 Heuristik: “Werte über 14 vermeiden“ (Sahraoui, Godin, Miceli: „Can Metrics Help
  Bridging the Gap Between the Improvement of OO Design Quality and Its Automation?“)




                                                                                        24
25



© gjeewAaytee at flickr
Informelle Beschreibung
      der Metrik 1

Metrik 1 > Schwellwert

                                Potentieller
                          UND
                                  Defekt
Informelle Beschreibung
      der Metrik 2

Metrik 2 < Schwellwert
 Motivation
 Metriken Überblick
 Metriken kombinieren
 Zusammenfassung, Literatur
  und Werkzeuge




                               © Emi Yanez @ Flickr
NASA Heuristik (Rosenberg et al, 1999)

 Eine Klasse sollte analysiert werden, sollten zwei
  oder mehr Bedingungen erfüllt sein:
   o WMC        > 100
   o CBO        >    5
   o RFC        > 100    (Response for a class)

   o NOM        > 40
   o RFC        > 5 * NOM


 Spinellis empfiehlt aufgrund seiner Erfahrungen
  dass mindestens drei Bedingungen erfüllt sein sollten
WMC > 100
                                    CBO > 5
NASA Heuristik                      NOM > 40




     Spring 2.5.6 (26 Klassen, aber NASA Heuristik
            gibt keine Indizien, welche Defekte
                        gefunden wurden)
 Nutzen bestehende Metriken, z.B. CK-suite
 Definieren eigene Metriken, z.B. ATFD
 Haben Schwellwerte für Metriken auf Basis
   o von 45 Java
     und 37 C++ Projekten definiert


 Beschreiben Darstellungsmöglichkeiten
   o Pyramidal Overview
   o Polymetric views
   o Class Blue Print

 Definieren “code smell detection
  strategies” basierend auf Metriken
 Gleichzeitige Darstellung von mehreren Metriken

                                Metrik 1




                                                    Metrik 2
                               Artefakt 1



         Metrik 3
                                                               Metrik
                                                                 4

                               Artefakt 2
 System Complexity View
                                                  Beispiel
                  Number of
               attributes (NOA)




                                      Number of
                                       methods
                                        (NOM)
                   Class 1



  Weighted
Method Count
   (WMC)                          Inheritance

                   Class 2
AbstractEntityPersister   Hibernate 3.3.2
      NOA       90
      NOM      299




                                UnionSubclassEntityPersister
                                       NOA       14
JoinedSubclassEntityPersister          NOM      41
NOA      28
NOM      44




                                 SingleTableEntityPersister
                                        NOA       40
                                        NOM      55
Informelle Beschreibung
      der Metrik 1
  metric1 > threshold

                          UND
Informelle Beschreibung
      der Metrik 2                     Potentieller
                                Oder
                                         Defekt
  metric2 < threshold


Informelle Beschreibung
      der Metrik 3
  metric3 > threshold
Lanza und Marienscu
                                                                  identity
                                                                  disharmony

 Beschreiben drei unterschiedliche Kategorien von disharmonies
   o Identity disharmonies


   o Collaboration disharmonies                                   collaboration
                                                                  disharmony


   o Classification disharmonies


 Sind teilweise an die Codegerüche von Martin Fowler angelehnt
                                                                  classification
                                                                  disharmony
 Designschwächen kommen oft im Verbund vor
 Feature Envy (Fowler)                                      identity
   o Die Methoden sind übermäßig an Daten anderer Klassen    disharmony
     interessiert
 Data Class (Fowler)
   o Aggregieren Daten, beinhalten aber kein Verhalten
 God class (Riel / Fowler)                                  collaboration
                                                             disharmony
   o Interagieren mit vielen anderen Kassen, besitzen eine
     sehr hohe Komplexität
 Brain Method
   o Methode hat eine sehr hohe Komplexität und beinhaltet
     große Teile der Klassen funktionalität                  classification
 Brain Class                                                disharmony

   o Klasse besitzt viele Brain Methods
 Significant Duplication (Fowler)
   o               Hoher Grad an Code Duplizierung
Definition
                                                                        identity
                                                                        disharmony

 beinhaltet fundamentale Funktionalität des Systems
   o Sehr Hohe Komplexität (McCabe)


 Verwendet Daten( Wissen) anderer Klassen                              collaboration
                                                                        disharmony
   o Access to Foreign Data (ATFD)


 Besitzt zu viele Verantwortlichkeiten
   o Tight Class Cohersion (TCC)
                                                                        classification
                                                                        disharmony
             “Do not create god classes/objects in your system.
             Be very suspicious of an abstraction whose name
             contains Driver, Manager, System, or Subsystem.”
                                  Arthur Riel, Object-Oriented Design
                                  Heuristics, 1996
Detection strategy
                                                      identity
                                                      disharmony
  Klasse nutzt Attri-   ATFD Access To Foreign Data
bute anderer Klassen
                        TCC   Tight Class Cohesion
    ATFD > FEW
                                                      collaboration
                                                      disharmony
Komplexität sehr hoch
                                           God
   WMC >= VERY
                        UND                Class
      HIGH
                                                      classification
                                                      disharmony
 Niedrige Kohäsion        FEW = 2-5
                          VERY HIGH = 47 (for WMC)
 TCC < ONE THIRD
                          ONE THIRD = 0.33
identity
                                                    disharmony
AbstractEntityPersister



                                                    collaboration
                                                    disharmony




                                                    classification
                                                    disharmony


SingleTableEntityPersister

                    JoinedSubclassEntityPersister
identity
          disharmony




          collaboration
          disharmony

49
Klassen


          classification
          disharmony
identity
disharmony




collaboration
disharmony




classification
disharmony
identity
disharmony




collaboration
disharmony




classification
disharmony
identity
disharmony




collaboration
disharmony




classification
disharmony
identity
disharmony




collaboration
disharmony




classification
disharmony
identity
disharmony




collaboration
disharmony




classification
disharmony
identity
disharmony




collaboration
disharmony




classification
disharmony
identity
disharmony




collaboration
disharmony




classification
disharmony
 Motivation
 Metriken Überblick
 Metriken kombinieren
 Zusammenfassung, Literatur
  und Werkzeuge




                               © Emi Yanez @ Flickr
 Metriken zur Analyse von
    Größe und Komplexität
    Kopplung
    Vererbung                                          Foto: pixelio.de - Olaf Rendler



  von Klassen nutzen

 Metriken können zum Aufdecken potentieller
  Refaktorisierungen genutzt werden

 Durch geeignete Kombination können code smells entdeckt werden

         Komplementär zu Werkzeugen wie PMD, JDepend, FxCop,
                  StyleCop, …
 Metriken müssen immer im Kontext des Projekts
           interpretiert werden

         Total Lines Of Code (LOC)
350000
300000
250000
200000                                                                      Average complexity per line of
150000
100000                                                                                              code
 50000
                                                                     0,21
     0
         Hibernate   Hibernate   Hibernate   Hibernate   Hibernate    0,2
            3.0         3.1         3.2         3.3         3.5      0,19

                  Gesamtanzahl Lines Of Code (LOC)                   0,18

                                                                     0,17
                                                                            Hibernate   Hibernate    Hibernate   Hibernate   Hibernate
                                                                               3.0         3.1          3.2         3.3         3.5

                                                                                         Durchschnittliche Komplexitäten
•Code Duplizierung reduzieren
Prio 1


         •Größe und Komplexität reduzieren
Prio 2


         •Kopplung reduzieren
Prio 3


         •Vererbungstiefe reduzieren
Prio 4
 JavaNCSS    http://www.kclee.de/clemens/java/javancss/
 ckjm        http://www.spinellis.gr/sw/ckjm/
 PMD         http://pmd.sourceforge.net/
 IPlasma     http://loose.upt.ro/iplasma/index.html
 InFushion   http://www.intooitus.com
 InCode      http://loose.upt.ro/incode/pmwiki.php/Main/Incode?from=Main.InCode
 CodeCity    http://www.inf.unisi.ch/phd/wettel/codecity.html
 MOOSE       http://moose.unibe.ch/
 Metrics     http://metrics.sourceforge.net/
 SonarJ      http://www.hello2morrow.com/products/sonarj
„However, a metric is not a god; it is merely
a measurement against an arbitrary standard“
                                         Robert C. Martin
> Refused Parent Bequest (Fowler)
                                                                   identity
   –   Child class only partially uses or does not use inherited   disharmony
       methods at all.


> Tradition Breaker
   –   Subclass provides a large set of new Interface methods      collaboration
                                                                   disharmony
       which are unrelated to the services provided by the
       parent class



                                                                   classification
                                                                   disharmony
> Refused Parent Bequest (Fowler)   identity
> Tradition Breaker                 disharmony




                                    collaboration
                                    disharmony




                                    classification
                                    disharmony
> Shotgun Surgery (Fowler)
                                                                identity
   –   The suspicious method is used by many other methods      disharmony



> Intensive Coupling (Fowler)
   –   The suspicious method heavily interacts with
       few other method                                         collaboration
                                                                disharmony

> Dispersed Coupling
   –   The suspicious class interacts with many other classes

                                                                classification
                                                                disharmony
[CM = Changing Methods]                     identity
Method is called by too   CM: Anzahl der Methoden, die die            disharmony
    many methods              betrachtete Methode aufrufen
CM > Short Memory Cap      Short Memory Capacity = 7- 8

                                                                      collaboration
                                                                      disharmony
                                                            Shotgun
                                 AND                        Surgery

                                  [CC = Changing Classes]
Incoming calls are from
                                   CC : Anzahl der Klassen, deren     classification
  many other classes                      Methoden die betrachtete    disharmony
                                          Methode aufrufen.
      CC > Many
                                  Many > 7
identity
disharmony




collaboration
disharmony




classification
disharmony

Weitere ähnliche Inhalte

Mehr von Aberla

Mobile Banking 2011: Sparkasse
Mobile Banking 2011: SparkasseMobile Banking 2011: Sparkasse
Mobile Banking 2011: SparkasseAberla
 
Mobile Banking 2011: Credit Suisse
Mobile Banking 2011: Credit SuisseMobile Banking 2011: Credit Suisse
Mobile Banking 2011: Credit SuisseAberla
 
Mobile Banking 2011: Postfinance
Mobile Banking 2011: PostfinanceMobile Banking 2011: Postfinance
Mobile Banking 2011: PostfinanceAberla
 
ESEconf2011 - Cruywagen Leon: "Cool ways to work smarter in the cloud"
ESEconf2011 - Cruywagen Leon: "Cool ways to work smarter in the cloud"ESEconf2011 - Cruywagen Leon: "Cool ways to work smarter in the cloud"
ESEconf2011 - Cruywagen Leon: "Cool ways to work smarter in the cloud"Aberla
 
ESEconf2011 - Wichmann Klaus-Peter: "Kennen Sie die Leistungsfähigkeit Ihres ...
ESEconf2011 - Wichmann Klaus-Peter: "Kennen Sie die Leistungsfähigkeit Ihres ...ESEconf2011 - Wichmann Klaus-Peter: "Kennen Sie die Leistungsfähigkeit Ihres ...
ESEconf2011 - Wichmann Klaus-Peter: "Kennen Sie die Leistungsfähigkeit Ihres ...Aberla
 
ESEconf2011 - Hanin Makram: "Embedding Performance into Continuous Integratio...
ESEconf2011 - Hanin Makram: "Embedding Performance into Continuous Integratio...ESEconf2011 - Hanin Makram: "Embedding Performance into Continuous Integratio...
ESEconf2011 - Hanin Makram: "Embedding Performance into Continuous Integratio...Aberla
 
ESEconf2011 - Lorenz Oliver: "'Agil heisst nicht beliebit' - Scrum als wirksa...
ESEconf2011 - Lorenz Oliver: "'Agil heisst nicht beliebit' - Scrum als wirksa...ESEconf2011 - Lorenz Oliver: "'Agil heisst nicht beliebit' - Scrum als wirksa...
ESEconf2011 - Lorenz Oliver: "'Agil heisst nicht beliebit' - Scrum als wirksa...Aberla
 
ESEconf2011 - Schilling Rüdiger: "Generative Konzepte für den Plattform-Zoo -...
ESEconf2011 - Schilling Rüdiger: "Generative Konzepte für den Plattform-Zoo -...ESEconf2011 - Schilling Rüdiger: "Generative Konzepte für den Plattform-Zoo -...
ESEconf2011 - Schilling Rüdiger: "Generative Konzepte für den Plattform-Zoo -...Aberla
 
ESEconf2011 - Freixa Vidal Roger: "Oracle's Java Strategy"
ESEconf2011 - Freixa Vidal Roger: "Oracle's Java Strategy"ESEconf2011 - Freixa Vidal Roger: "Oracle's Java Strategy"
ESEconf2011 - Freixa Vidal Roger: "Oracle's Java Strategy"Aberla
 
ESEconf2011 - Westphal Ralf: "Slice me nice - Produktiv, schnell, zufrieden"
ESEconf2011 - Westphal Ralf: "Slice me nice - Produktiv, schnell, zufrieden"ESEconf2011 - Westphal Ralf: "Slice me nice - Produktiv, schnell, zufrieden"
ESEconf2011 - Westphal Ralf: "Slice me nice - Produktiv, schnell, zufrieden"Aberla
 
ESEconf2011 - Caine Matthew: "Creating an Environment of Teamwork, Quality, I...
ESEconf2011 - Caine Matthew: "Creating an Environment of Teamwork, Quality, I...ESEconf2011 - Caine Matthew: "Creating an Environment of Teamwork, Quality, I...
ESEconf2011 - Caine Matthew: "Creating an Environment of Teamwork, Quality, I...Aberla
 
ESEconf2011 - Schwaber Ken: "Scrum: Necessary but not sufficient for agility"
ESEconf2011 - Schwaber Ken: "Scrum: Necessary but not sufficient for agility"ESEconf2011 - Schwaber Ken: "Scrum: Necessary but not sufficient for agility"
ESEconf2011 - Schwaber Ken: "Scrum: Necessary but not sufficient for agility"Aberla
 
ESEconf2011 - Kaiser Traian: "How to measure productivity in software develop...
ESEconf2011 - Kaiser Traian: "How to measure productivity in software develop...ESEconf2011 - Kaiser Traian: "How to measure productivity in software develop...
ESEconf2011 - Kaiser Traian: "How to measure productivity in software develop...Aberla
 
ESEconf2011 - Haas Thomas & Jenni Joscha: "Ein Softwareprojekt zum Festpreis ...
ESEconf2011 - Haas Thomas & Jenni Joscha: "Ein Softwareprojekt zum Festpreis ...ESEconf2011 - Haas Thomas & Jenni Joscha: "Ein Softwareprojekt zum Festpreis ...
ESEconf2011 - Haas Thomas & Jenni Joscha: "Ein Softwareprojekt zum Festpreis ...Aberla
 
ESEconf2011 - Buschmann Frank: "What architects need to know"
ESEconf2011 - Buschmann Frank: "What architects need to know"ESEconf2011 - Buschmann Frank: "What architects need to know"
ESEconf2011 - Buschmann Frank: "What architects need to know"Aberla
 
ESEconf2011 - Arrenbrecht Peter: "Literate Testing: Stimmige API's machen meh...
ESEconf2011 - Arrenbrecht Peter: "Literate Testing: Stimmige API's machen meh...ESEconf2011 - Arrenbrecht Peter: "Literate Testing: Stimmige API's machen meh...
ESEconf2011 - Arrenbrecht Peter: "Literate Testing: Stimmige API's machen meh...Aberla
 
ESEconf2011 - Bosch Andy: "JavaServer Faces im Portal - Statusbestimmung"
ESEconf2011 - Bosch Andy: "JavaServer Faces im Portal - Statusbestimmung"ESEconf2011 - Bosch Andy: "JavaServer Faces im Portal - Statusbestimmung"
ESEconf2011 - Bosch Andy: "JavaServer Faces im Portal - Statusbestimmung"Aberla
 
ESEconf2011 - Trost Joachim: "Tool supported technical Code and Design Qualit...
ESEconf2011 - Trost Joachim: "Tool supported technical Code and Design Qualit...ESEconf2011 - Trost Joachim: "Tool supported technical Code and Design Qualit...
ESEconf2011 - Trost Joachim: "Tool supported technical Code and Design Qualit...Aberla
 
ESEconf2011 - Hochdoerfer Stephan: "Assembly line production of software appl...
ESEconf2011 - Hochdoerfer Stephan: "Assembly line production of software appl...ESEconf2011 - Hochdoerfer Stephan: "Assembly line production of software appl...
ESEconf2011 - Hochdoerfer Stephan: "Assembly line production of software appl...Aberla
 
ESEconf2011 - Guckenheimer Sam: "Agile in the Very Large"
ESEconf2011 - Guckenheimer Sam: "Agile in the Very Large"ESEconf2011 - Guckenheimer Sam: "Agile in the Very Large"
ESEconf2011 - Guckenheimer Sam: "Agile in the Very Large"Aberla
 

Mehr von Aberla (20)

Mobile Banking 2011: Sparkasse
Mobile Banking 2011: SparkasseMobile Banking 2011: Sparkasse
Mobile Banking 2011: Sparkasse
 
Mobile Banking 2011: Credit Suisse
Mobile Banking 2011: Credit SuisseMobile Banking 2011: Credit Suisse
Mobile Banking 2011: Credit Suisse
 
Mobile Banking 2011: Postfinance
Mobile Banking 2011: PostfinanceMobile Banking 2011: Postfinance
Mobile Banking 2011: Postfinance
 
ESEconf2011 - Cruywagen Leon: "Cool ways to work smarter in the cloud"
ESEconf2011 - Cruywagen Leon: "Cool ways to work smarter in the cloud"ESEconf2011 - Cruywagen Leon: "Cool ways to work smarter in the cloud"
ESEconf2011 - Cruywagen Leon: "Cool ways to work smarter in the cloud"
 
ESEconf2011 - Wichmann Klaus-Peter: "Kennen Sie die Leistungsfähigkeit Ihres ...
ESEconf2011 - Wichmann Klaus-Peter: "Kennen Sie die Leistungsfähigkeit Ihres ...ESEconf2011 - Wichmann Klaus-Peter: "Kennen Sie die Leistungsfähigkeit Ihres ...
ESEconf2011 - Wichmann Klaus-Peter: "Kennen Sie die Leistungsfähigkeit Ihres ...
 
ESEconf2011 - Hanin Makram: "Embedding Performance into Continuous Integratio...
ESEconf2011 - Hanin Makram: "Embedding Performance into Continuous Integratio...ESEconf2011 - Hanin Makram: "Embedding Performance into Continuous Integratio...
ESEconf2011 - Hanin Makram: "Embedding Performance into Continuous Integratio...
 
ESEconf2011 - Lorenz Oliver: "'Agil heisst nicht beliebit' - Scrum als wirksa...
ESEconf2011 - Lorenz Oliver: "'Agil heisst nicht beliebit' - Scrum als wirksa...ESEconf2011 - Lorenz Oliver: "'Agil heisst nicht beliebit' - Scrum als wirksa...
ESEconf2011 - Lorenz Oliver: "'Agil heisst nicht beliebit' - Scrum als wirksa...
 
ESEconf2011 - Schilling Rüdiger: "Generative Konzepte für den Plattform-Zoo -...
ESEconf2011 - Schilling Rüdiger: "Generative Konzepte für den Plattform-Zoo -...ESEconf2011 - Schilling Rüdiger: "Generative Konzepte für den Plattform-Zoo -...
ESEconf2011 - Schilling Rüdiger: "Generative Konzepte für den Plattform-Zoo -...
 
ESEconf2011 - Freixa Vidal Roger: "Oracle's Java Strategy"
ESEconf2011 - Freixa Vidal Roger: "Oracle's Java Strategy"ESEconf2011 - Freixa Vidal Roger: "Oracle's Java Strategy"
ESEconf2011 - Freixa Vidal Roger: "Oracle's Java Strategy"
 
ESEconf2011 - Westphal Ralf: "Slice me nice - Produktiv, schnell, zufrieden"
ESEconf2011 - Westphal Ralf: "Slice me nice - Produktiv, schnell, zufrieden"ESEconf2011 - Westphal Ralf: "Slice me nice - Produktiv, schnell, zufrieden"
ESEconf2011 - Westphal Ralf: "Slice me nice - Produktiv, schnell, zufrieden"
 
ESEconf2011 - Caine Matthew: "Creating an Environment of Teamwork, Quality, I...
ESEconf2011 - Caine Matthew: "Creating an Environment of Teamwork, Quality, I...ESEconf2011 - Caine Matthew: "Creating an Environment of Teamwork, Quality, I...
ESEconf2011 - Caine Matthew: "Creating an Environment of Teamwork, Quality, I...
 
ESEconf2011 - Schwaber Ken: "Scrum: Necessary but not sufficient for agility"
ESEconf2011 - Schwaber Ken: "Scrum: Necessary but not sufficient for agility"ESEconf2011 - Schwaber Ken: "Scrum: Necessary but not sufficient for agility"
ESEconf2011 - Schwaber Ken: "Scrum: Necessary but not sufficient for agility"
 
ESEconf2011 - Kaiser Traian: "How to measure productivity in software develop...
ESEconf2011 - Kaiser Traian: "How to measure productivity in software develop...ESEconf2011 - Kaiser Traian: "How to measure productivity in software develop...
ESEconf2011 - Kaiser Traian: "How to measure productivity in software develop...
 
ESEconf2011 - Haas Thomas & Jenni Joscha: "Ein Softwareprojekt zum Festpreis ...
ESEconf2011 - Haas Thomas & Jenni Joscha: "Ein Softwareprojekt zum Festpreis ...ESEconf2011 - Haas Thomas & Jenni Joscha: "Ein Softwareprojekt zum Festpreis ...
ESEconf2011 - Haas Thomas & Jenni Joscha: "Ein Softwareprojekt zum Festpreis ...
 
ESEconf2011 - Buschmann Frank: "What architects need to know"
ESEconf2011 - Buschmann Frank: "What architects need to know"ESEconf2011 - Buschmann Frank: "What architects need to know"
ESEconf2011 - Buschmann Frank: "What architects need to know"
 
ESEconf2011 - Arrenbrecht Peter: "Literate Testing: Stimmige API's machen meh...
ESEconf2011 - Arrenbrecht Peter: "Literate Testing: Stimmige API's machen meh...ESEconf2011 - Arrenbrecht Peter: "Literate Testing: Stimmige API's machen meh...
ESEconf2011 - Arrenbrecht Peter: "Literate Testing: Stimmige API's machen meh...
 
ESEconf2011 - Bosch Andy: "JavaServer Faces im Portal - Statusbestimmung"
ESEconf2011 - Bosch Andy: "JavaServer Faces im Portal - Statusbestimmung"ESEconf2011 - Bosch Andy: "JavaServer Faces im Portal - Statusbestimmung"
ESEconf2011 - Bosch Andy: "JavaServer Faces im Portal - Statusbestimmung"
 
ESEconf2011 - Trost Joachim: "Tool supported technical Code and Design Qualit...
ESEconf2011 - Trost Joachim: "Tool supported technical Code and Design Qualit...ESEconf2011 - Trost Joachim: "Tool supported technical Code and Design Qualit...
ESEconf2011 - Trost Joachim: "Tool supported technical Code and Design Qualit...
 
ESEconf2011 - Hochdoerfer Stephan: "Assembly line production of software appl...
ESEconf2011 - Hochdoerfer Stephan: "Assembly line production of software appl...ESEconf2011 - Hochdoerfer Stephan: "Assembly line production of software appl...
ESEconf2011 - Hochdoerfer Stephan: "Assembly line production of software appl...
 
ESEconf2011 - Guckenheimer Sam: "Agile in the Very Large"
ESEconf2011 - Guckenheimer Sam: "Agile in the Very Large"ESEconf2011 - Guckenheimer Sam: "Agile in the Very Large"
ESEconf2011 - Guckenheimer Sam: "Agile in the Very Large"
 

ESeconf2011 - Haug Thomas: "Sauberer Code mit Metriken"

  • 2. 80% der Projektkosten fallen nach der Entwicklung an http://users.jyu.fi/~koskinen/smcosts.htm
  • 3.
  • 4. Thin Client Thick Client Presentation layer Application layer Integration layer Database Filesystem Legacy system
  • 5. Thin Client Thick Client Presentation layer KEEP IT Application layer SIMPLE Integration layer STUPID. Database Filesystem Legacy system
  • 6.
  • 7.
  • 9. © by D'Arcy Norman at flickr 9
  • 10. > Process – Test Driven Development – Short development cycles > Runtime Analysis – Test Coverage – Memory Analysis – Deadlock Detection – Monitoring / Logging > Static Code Analysis – Design and Code guidelines – → Design- and Code Reviews – Static analysis tools – Metrics 10
  • 11.  Motivation  Metriken Überblick  Metriken kombinieren  Zusammenfassung, Literatur und Werkzeuge © Emi Yanez @ Flickr
  • 12. 70er Jahre Basis Metrics SLOC Complexity ... LOC McCabe Halstead
  • 13. Quellcodezeilen (Source Lines of Code - SLOC)  Physikalische Codezeilen (Lines of code - LOC) o Abzählen von Codezeilen, Kommentare und Klammern  Logische Codezeilen (Logical lines of code - lLOC und Non Commented Source Statements -NCSS) o Abzählen von Anweisungen “Measuring programming progress by lines of code is like measuring aircraft building progress by weight” Bill Gates
  • 14.  LOC vs lLOC for (int i = 0; i < 10; i++) LOC = 2 System.out.println(i + ". value"); lLOC = 2 for (int i = 0; i < 10; i++) { // print to console LOC = 5 System.out.println(i + ". value"); lLOC = 2 }
  • 15.
  • 16.  Cyclomatic Komplexität (CC(N)) function gcd (x, y)  McCabe, 1976 while (y>0) p: Anzahl der Komponenten e: Anzahl der Kanten (edges) rest = x % y n: Anzahl der Knoten (nodes) x=y y = rest  Beispiel return x CC = 4 – 4 + 2*1 = 2
  • 17. Original McCabe values PMD (per method) 1-10 : low complexity 1-4 : low complexity 11-20 : medium complexity 5-7 : medium complexity 21-50 : high complexity 8-10 : high complexity > 51 : very high complexity > 11 : very high complexity http://www.enerjy.com/blog/?p=198
  • 18. 165 Methoden CC > 11 : very high complexity
  • 20. ? Kopplung ? ? Vererbung ?
  • 21. Software Metrics 70er Jahre 90er Jahre Basis Metrics O-O Metrics SLOC Complexity ... CK MOOD LK ... LOC McCabe Halstead WMC ... MHF ... ... ...
  • 22.  Basis Metriken decken wichtige Aspekte der Objekt-Orientierung nicht ab  OO Metriken messen alle drei Dimensionen o Größe und Komplexität o Kopplung o Vererbung  Unüberschaubare Anzahl an Metriken vorhanden (>= 375)  Beispiel o Chidamber und Kemerer (CK) Metric suite (1994) WMC, CBO, DIT, NOC, RFC, LCOM o Robert C. Martin Metrics (1994) Coupling, Stability, Abstractness,...
  • 23.  Weighted Method Count (WMC) Sehr hohe Klassen- komplexität, aber durchschnittliche Methodenkom- . plexität ist niedrig . . Sehr hohe Klassen- komplexität, durch- schnittliche Methoden- komplexität ist hoch / sehr hoch
  • 24.  Coupling Between Object Classes (CBO)  Heuristik: “Werte über 14 vermeiden“ (Sahraoui, Godin, Miceli: „Can Metrics Help Bridging the Gap Between the Improvement of OO Design Quality and Its Automation?“) 24
  • 26. Informelle Beschreibung der Metrik 1 Metrik 1 > Schwellwert Potentieller UND Defekt Informelle Beschreibung der Metrik 2 Metrik 2 < Schwellwert
  • 27.  Motivation  Metriken Überblick  Metriken kombinieren  Zusammenfassung, Literatur und Werkzeuge © Emi Yanez @ Flickr
  • 28. NASA Heuristik (Rosenberg et al, 1999)  Eine Klasse sollte analysiert werden, sollten zwei oder mehr Bedingungen erfüllt sein: o WMC > 100 o CBO > 5 o RFC > 100 (Response for a class) o NOM > 40 o RFC > 5 * NOM  Spinellis empfiehlt aufgrund seiner Erfahrungen dass mindestens drei Bedingungen erfüllt sein sollten
  • 29. WMC > 100 CBO > 5 NASA Heuristik NOM > 40 Spring 2.5.6 (26 Klassen, aber NASA Heuristik gibt keine Indizien, welche Defekte gefunden wurden)
  • 30.  Nutzen bestehende Metriken, z.B. CK-suite  Definieren eigene Metriken, z.B. ATFD  Haben Schwellwerte für Metriken auf Basis o von 45 Java und 37 C++ Projekten definiert  Beschreiben Darstellungsmöglichkeiten o Pyramidal Overview o Polymetric views o Class Blue Print  Definieren “code smell detection strategies” basierend auf Metriken
  • 31.  Gleichzeitige Darstellung von mehreren Metriken Metrik 1 Metrik 2 Artefakt 1 Metrik 3 Metrik 4 Artefakt 2
  • 32.  System Complexity View Beispiel Number of attributes (NOA) Number of methods (NOM) Class 1 Weighted Method Count (WMC) Inheritance Class 2
  • 33. AbstractEntityPersister Hibernate 3.3.2 NOA 90 NOM 299 UnionSubclassEntityPersister NOA 14 JoinedSubclassEntityPersister NOM 41 NOA 28 NOM 44 SingleTableEntityPersister NOA 40 NOM 55
  • 34. Informelle Beschreibung der Metrik 1 metric1 > threshold UND Informelle Beschreibung der Metrik 2 Potentieller Oder Defekt metric2 < threshold Informelle Beschreibung der Metrik 3 metric3 > threshold
  • 35. Lanza und Marienscu identity disharmony  Beschreiben drei unterschiedliche Kategorien von disharmonies o Identity disharmonies o Collaboration disharmonies collaboration disharmony o Classification disharmonies  Sind teilweise an die Codegerüche von Martin Fowler angelehnt classification disharmony  Designschwächen kommen oft im Verbund vor
  • 36.  Feature Envy (Fowler) identity o Die Methoden sind übermäßig an Daten anderer Klassen disharmony interessiert  Data Class (Fowler) o Aggregieren Daten, beinhalten aber kein Verhalten  God class (Riel / Fowler) collaboration disharmony o Interagieren mit vielen anderen Kassen, besitzen eine sehr hohe Komplexität  Brain Method o Methode hat eine sehr hohe Komplexität und beinhaltet große Teile der Klassen funktionalität classification  Brain Class disharmony o Klasse besitzt viele Brain Methods  Significant Duplication (Fowler) o Hoher Grad an Code Duplizierung
  • 37. Definition identity disharmony  beinhaltet fundamentale Funktionalität des Systems o Sehr Hohe Komplexität (McCabe)  Verwendet Daten( Wissen) anderer Klassen collaboration disharmony o Access to Foreign Data (ATFD)  Besitzt zu viele Verantwortlichkeiten o Tight Class Cohersion (TCC) classification disharmony “Do not create god classes/objects in your system. Be very suspicious of an abstraction whose name contains Driver, Manager, System, or Subsystem.” Arthur Riel, Object-Oriented Design Heuristics, 1996
  • 38. Detection strategy identity disharmony Klasse nutzt Attri- ATFD Access To Foreign Data bute anderer Klassen TCC Tight Class Cohesion ATFD > FEW collaboration disharmony Komplexität sehr hoch God WMC >= VERY UND Class HIGH classification disharmony Niedrige Kohäsion FEW = 2-5 VERY HIGH = 47 (for WMC) TCC < ONE THIRD ONE THIRD = 0.33
  • 39. identity disharmony AbstractEntityPersister collaboration disharmony classification disharmony SingleTableEntityPersister JoinedSubclassEntityPersister
  • 40. identity disharmony collaboration disharmony 49 Klassen classification disharmony
  • 46.
  • 49.  Motivation  Metriken Überblick  Metriken kombinieren  Zusammenfassung, Literatur und Werkzeuge © Emi Yanez @ Flickr
  • 50.  Metriken zur Analyse von  Größe und Komplexität  Kopplung  Vererbung Foto: pixelio.de - Olaf Rendler von Klassen nutzen  Metriken können zum Aufdecken potentieller Refaktorisierungen genutzt werden  Durch geeignete Kombination können code smells entdeckt werden  Komplementär zu Werkzeugen wie PMD, JDepend, FxCop, StyleCop, …
  • 51.  Metriken müssen immer im Kontext des Projekts interpretiert werden Total Lines Of Code (LOC) 350000 300000 250000 200000 Average complexity per line of 150000 100000 code 50000 0,21 0 Hibernate Hibernate Hibernate Hibernate Hibernate 0,2 3.0 3.1 3.2 3.3 3.5 0,19 Gesamtanzahl Lines Of Code (LOC) 0,18 0,17 Hibernate Hibernate Hibernate Hibernate Hibernate 3.0 3.1 3.2 3.3 3.5 Durchschnittliche Komplexitäten
  • 52. •Code Duplizierung reduzieren Prio 1 •Größe und Komplexität reduzieren Prio 2 •Kopplung reduzieren Prio 3 •Vererbungstiefe reduzieren Prio 4
  • 53.
  • 54.  JavaNCSS http://www.kclee.de/clemens/java/javancss/  ckjm http://www.spinellis.gr/sw/ckjm/  PMD http://pmd.sourceforge.net/  IPlasma http://loose.upt.ro/iplasma/index.html  InFushion http://www.intooitus.com  InCode http://loose.upt.ro/incode/pmwiki.php/Main/Incode?from=Main.InCode  CodeCity http://www.inf.unisi.ch/phd/wettel/codecity.html  MOOSE http://moose.unibe.ch/  Metrics http://metrics.sourceforge.net/  SonarJ http://www.hello2morrow.com/products/sonarj
  • 55. „However, a metric is not a god; it is merely a measurement against an arbitrary standard“ Robert C. Martin
  • 56.
  • 57. > Refused Parent Bequest (Fowler) identity – Child class only partially uses or does not use inherited disharmony methods at all. > Tradition Breaker – Subclass provides a large set of new Interface methods collaboration disharmony which are unrelated to the services provided by the parent class classification disharmony
  • 58. > Refused Parent Bequest (Fowler) identity > Tradition Breaker disharmony collaboration disharmony classification disharmony
  • 59. > Shotgun Surgery (Fowler) identity – The suspicious method is used by many other methods disharmony > Intensive Coupling (Fowler) – The suspicious method heavily interacts with few other method collaboration disharmony > Dispersed Coupling – The suspicious class interacts with many other classes classification disharmony
  • 60. [CM = Changing Methods] identity Method is called by too CM: Anzahl der Methoden, die die disharmony many methods betrachtete Methode aufrufen CM > Short Memory Cap Short Memory Capacity = 7- 8 collaboration disharmony Shotgun AND Surgery [CC = Changing Classes] Incoming calls are from CC : Anzahl der Klassen, deren classification many other classes Methoden die betrachtete disharmony Methode aufrufen. CC > Many Many > 7