Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Measurable code quality

Measurable code quality

Held at the enterJS in Cologne, Germany at Tuesday, 1. July 2014.
The talk was in german.

Andy Grunwald

July 01, 2014
Tweet

More Decks by Andy Grunwald

Other Decks in Technology

Transcript

  1. Andy Grunwald • Software Engineer bei @trivago
 • Open Source


    • @andygrunwald
 • @PHPUGDus
 • andygrunwald
  2. –Helmut Balzert „Unter Softwarequalität versteht man die Gesamtheit der Merkmale

    … eines Softwareprodukts, …, festgelegte oder vorausgesetzte Erfordernisse zu erfüllen.“
  3. Frontend HTTP Requests Navigation Timing DOM Elemente Browser Repaints …

    Backend Request-Zeit Cache-Miss / -Hits Ressource-Zeit Business-Logik …
  4. Frontend HTTP Requests Navigation Timing DOM Elemente Browser Repaints …

    Backend Request-Zeit Cache-Miss / -Hits Ressource-Zeit Business-Logik … Source Code
  5. Source Code Functions count Nested depth Halstead Maintainability index LOC

    Parameter count Cyclomatic Complexity nPath Lint errors CLOC LLOC Your metric here
  6. Source Code Functions count Nested depth Halstead Maintainability index LOC

    Parameter count Cyclomatic Complexity nPath Lint errors CLOC LLOC Your metric here
  7. // Is a given array, string, … // An "empty"

    object has … _.isEmpty = function(obj) { if (obj == null) { return true; } ! if (_.isArray(obj)) { return obj.length === 0; } ! for (var key in obj) { if (_.has(obj, key)) { return false; } } ! return true; }; _.isEmpty(e);
  8. // Is a given array, string, … // An "empty"

    object has … _.isEmpty = function(obj) { if (obj == null) { return true; } ! if (_.isArray(obj)) { return obj.length === 0; } ! for (var key in obj) { if (_.has(obj, key)) { return false; } } ! return true; }; _.isEmpty(e); • LOC: 19
  9. // Is a given array, string, … // An "empty"

    object has … _.isEmpty = function(obj) { if (obj == null) { return true; } ! if (_.isArray(obj)) { return obj.length === 0; } ! for (var key in obj) { if (_.has(obj, key)) { return false; } } ! return true; }; _.isEmpty(e); • LOC: 19
 • CLOC: 2
  10. // Is a given array, string, … // An "empty"

    object has … _.isEmpty = function(obj) { if (obj == null) { return true; } ! if (_.isArray(obj)) { return obj.length === 0; } ! for (var key in obj) { if (_.has(obj, key)) { return false; } } ! return true; }; _.isEmpty(e); • LOC: 19
 • CLOC: 2
 • NCLOC: 17
  11. _.isEmpty(e); • LOC: 19
 • CLOC: 2
 • NCLOC: 17


    • LLOC: 9 // Is a given array, string, … // An "empty" object has … _.isEmpty = function(obj) { if (obj == null) { return true; } ! if (_.isArray(obj)) { return obj.length === 0; } ! for (var key in obj) { if (_.has(obj, key)) { return false; } } ! return true; };
  12. Source Code Functions count Nested depth Halstead Maintainability index LOC

    Parameter count Cyclomatic Complexity nPath Lint errors CLOC LLOC Your metric here
  13. Source Code Functions count Nested depth Halstead Maintainability index LOC

    Parameter count Cyclomatic Complexity nPath Lint errors CLOC LLOC Your metric here
  14. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  15. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  16. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  17. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  18. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  19. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } } Cyclomatic Complexity: 4
  20. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  21. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  22. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  23. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  24. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } }
  25. function nestedFunction(x, y, z) { if (x > 0) {

    if (y > 0) { if (z > 0) { console.log(z); } } } } nPath Complexity: 4
  26. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  27. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  28. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  29. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  30. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  31. Cyclomatic Complexity: 4 function nPath(x, y, z) { if (x

    > 0) { console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  32. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  33. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  34. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  35. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  36. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  37. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  38. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  39. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  40. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } }
  41. function nPath(x, y, z) { if (x > 0) {

    console.log(x); } ! if (y > 0) { console.log(y); } ! if (z > 0) { console.log(z); } } nPath Complexity: 8
  42. +

  43. function foo() { var a = [0, 1, 2, 3,

    4]; for (index = 0; index < a.length; ++index) { console.log(a[index]); } }
  44. function foo() { for (key in [0, 1, 2, 3,

    4]) { console.log(key); } } function foo() { var a = [0, 1, 2, 3, 4]; for (index = 0; index < a.length; ++index) { console.log(a[index]); } }
  45. function foo() { for (key in [0, 1, 2, 3,

    4]) { console.log(key); } } function foo() { [0, 1, 2, 3, 4].forEach(function (i) { console.log(i); }); } function foo() { var a = [0, 1, 2, 3, 4]; for (index = 0; index < a.length; ++index) { console.log(a[index]); } }
  46. var a = '(function() {' + 'if(arguments[0] > 0) '

    + 'console.log(arguments);' + '})(6)'; eval(a); var a = 'if(arguments[0] > 0) ' + 'console.log(arguments);'; new Function(a)(5);
  47. Java (45 Projekte) Metrik Niedrig Normal Hoch Sehr hoch CYCLO/LOC

    0.16 0.20 0.24 0.36 LOC/Methode 7 10 13 19.5 NOM/Class 4 7 10 15
  48. Java (45 Projekte) Metrik Niedrig Normal Hoch Sehr hoch CYCLO/LOC

    0.16 0.20 0.24 0.36 LOC/Methode 7 10 13 19.5 NOM/Class 4 7 10 15 C++ (37 Projekte) Metrik Niedrig Normal Hoch Sehr hoch CYCLO/LOC 0.20 0.25 0.30 0.45 LOC/Methode 5 10 16 24 NOM/Class 4 9 15 22.5
  49. Source Code Functions count Nested depth Halstead Maintainability index LOC

    Parameter count Cyclomatic Complexity nPath Lint errors CLOC LLOC Your metric here
  50. Verwendete Bilder • „Ruler“ by Scott Akerman: https://www.flickr.com/ photos/sterlic/4299631538/ •

    „the JavaScript Code“ by Dmitry Baranovskiy: https:// www.flickr.com/photos/dmitry-baranovskiy/2378867408 • „Ignition“ by Zach Dischner: https://www.flickr.com/ photos/zachd1_618/3489625168 • „Tools IMG_0171“ by OZinOH: https://www.flickr.com/ photos/75905404@N00/7126146307
  51. Verwendete Bilder • „Danger & Skull, Legoland“ by bixentro: https://

    www.flickr.com/photos/bixentro/338433029 • „Baby“ by The Noun Project: http://thenounproject.com/ term/baby/47/ • „Man“ by The Noun Project: http://thenounproject.com/ term/man/2/ • „Sasquatch“ by Mike Wirth: http://thenounproject.com/ term/sasquatch/2680/
  52. Verwendete Bilder • „Waking Up In Abbeyford Woods“ by Miles

    Wolstenholme: https://www.flickr.com/photos/ oaktorphotography/14444806464 • „Danke 102/365“ by Dennis Skley: https:// www.flickr.com/photos/dskley/13796815083/ • „Questions“ by Oberazzi: https://www.flickr.com/photos/ oberazzi/318947873/in/photostream/
  53. Zitate und Tabellen • Helmut Balzert: Lehrbuch der Softwaretechnik. Band

    2: Softwaremanagement, Software-Qualitätssicherung, Unternehmensmodellierung, Spektrum Akademischer Verlag, Heidelberg 1998, ISBN 3-8274-0065-1, S. 257 • Michele Lanza, Radu Marinescu: Object-Oriented Metrics in Practice: Using Software Metrics to Characterize, Evaluate, and Improve the Design of Object-Oriented Systems, Springer 2006, ISBN 3540244298