Maintainability SFJS Sept 4 2014
-
Upload
jarrod-overson -
Category
Technology
-
view
269 -
download
0
description
Transcript of Maintainability SFJS Sept 4 2014
![Page 1: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/1.jpg)
Jarrod Overson - @jsoverson
AchievingMaintainability
![Page 2: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/2.jpg)
a . k . a .
![Page 3: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/3.jpg)
Idiot proofing your code
![Page 4: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/4.jpg)
![Page 5: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/5.jpg)
![Page 6: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/6.jpg)
( psst, we’re all idiots )
![Page 7: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/7.jpg)
We do stuff like…
❯ pi 3.141592653589793
❯ pi(2) 6.283185307179586
![Page 8: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/8.jpg)
Or…
❯ 4..days 345600000
❯ 60..seconds 60000
![Page 9: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/9.jpg)
And even…
<script src="#"></script>
![Page 10: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/10.jpg)
What was clever six months agoclever
![Page 11: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/11.jpg)
Is idiotic todayidiotic
![Page 12: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/12.jpg)
We’re not awful people
![Page 13: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/13.jpg)
We’re just smart
![Page 14: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/14.jpg)
We’re just lazysmart
![Page 15: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/15.jpg)
We’re justlazysmart
bored
![Page 16: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/16.jpg)
We’re just
lazysmart
boredevil
![Page 17: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/17.jpg)
We’re just doing our job
![Page 18: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/18.jpg)
And our job is hard
![Page 19: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/19.jpg)
How do we get better at it?
![Page 20: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/20.jpg)
EXAMINE1
2
3
![Page 21: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/21.jpg)
![Page 22: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/22.jpg)
How much analysis do you run on your code?
![Page 23: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/23.jpg)
It’s not enough.
![Page 24: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/24.jpg)
KNOW YOUR LINTERS
JSHINT
ESLINT
JSCS
Community-driven JSLint fork. High configurability.
JSHint alternative. High configurability.
Code style checker. Separate and complementary.
WHAT ABOUT JSLINT AND CLOSURE LINTER?
![Page 25: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/25.jpg)
KNOW YOUR LINTER’S OPTIONS
![Page 26: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/26.jpg)
"maxparams" : 4 "maxdepth" : 4 "maxstatements" : 20 "maxlen" : 100 "maxcomplexity" : 7
SET LIMITS
![Page 27: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/27.jpg)
WHAT IS CYCLOMATIC COMPLEXITY?
![Page 28: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/28.jpg)
CYCLOMATIC COMPLEXITY IS THE NUMBER OF PATHS
THROUGH YOUR CODE
TECHNICALLY
![Page 29: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/29.jpg)
CYCLOMATIC COMPLEXITY IS HOW HARD
YOUR CODE IS TO TEST
PRACTICALLY
![Page 30: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/30.jpg)
!function main(a) { !}
COMPLEXITY : 1
![Page 31: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/31.jpg)
function main(a) { if (a > 5) { } }
COMPLEXITY : 2
![Page 32: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/32.jpg)
function main(a) { if (a > 5) { ! } else { ! } }
COMPLEXITY : ?
![Page 33: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/33.jpg)
function main(a) { if (a > 10) { ! } else if(a > 5) { ! } }
COMPLEXITY : 3
![Page 34: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/34.jpg)
function main(a) { if (a > 5) { if (a > 10) { ! } } }
COMPLEXITY : 3
![Page 35: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/35.jpg)
function main(a) { if (a) { } else if (a) { } ! if (other) { } ! for (var i = 0; i < a; i++) { if (i % 2) { } else if (i % 3) { } } }
COMPLEXITY : 7
![Page 36: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/36.jpg)
GENERATE VISUAL REPORTS
![Page 37: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/37.jpg)
![Page 38: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/38.jpg)
![Page 39: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/39.jpg)
code coverageistanbul
jscoverblanket
![Page 40: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/40.jpg)
![Page 41: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/41.jpg)
platocomplexity
maintainabilitylint errors
![Page 42: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/42.jpg)
MAINTAINABILITY?fn(averageEffort, averageComplexity, averageLines);
fn(difficulty, volume)fn(length, vocabulary)
fn(uniqueOperators, totalOperands, uniqueOperands)
fn(uniqueOperators, uniqueOperands)
fn(totalOperators, totalOperands)
![Page 43: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/43.jpg)
doc coveragethis
existdoesn’t
![Page 44: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/44.jpg)
AUTOMATE2
3
1
![Page 45: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/45.jpg)
![Page 46: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/46.jpg)
IF IT’S NOT EASYIt won’t get done.
![Page 47: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/47.jpg)
IF IT’S NOT AUTOMATICIt won’t get done every time.
![Page 48: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/48.jpg)
IF IT’S NOT VISIBLEIt may as well not be done at all.
![Page 49: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/49.jpg)
Build firstBefore you write code, set up your build
![Page 50: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/50.jpg)
But I don’t wanna!
![Page 51: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/51.jpg)
Look into yeomanManages file copies, conflicts, prompts, defaults
![Page 52: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/52.jpg)
But I don’t want to learn Yeoman!
![Page 53: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/53.jpg)
$ npm install yo generator-generator !$ mkdir generator-myWorkflow !$ cd generator-myWorkflow !$ yo generator
![Page 54: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/54.jpg)
![Page 55: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/55.jpg)
But I don’t need all that!
![Page 56: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/56.jpg)
![Page 57: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/57.jpg)
Delete, add, and modify It’s surprisingly easy.
![Page 58: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/58.jpg)
Grunt vs Gulpit doesn’t matter, just choose one.
![Page 59: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/59.jpg)
What about…• MAKE • RAKE • JAKE • ANT • BROCCOLI • blahhhh…
![Page 60: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/60.jpg)
It doesn’t matter.Just choose one.
( but be ready to support it )
![Page 61: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/61.jpg)
Want code coverage?grunt-contrib-jasminegrunt-mocha-istanbulgrunt-jscoverageand 30 more
![Page 62: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/62.jpg)
Want linting?grunt-contrib-jshintgrunt-eslintgrunt-jscs-checkerand 50 more
![Page 63: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/63.jpg)
Want docs?grunt-contrib-yuidocgrunt-jsdocgrunt-doccoand 90+ more
![Page 64: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/64.jpg)
There’s no excusefor manual process
![Page 65: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/65.jpg)
PROTECT3
1
2
![Page 66: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/66.jpg)
![Page 67: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/67.jpg)
‣ Code style ‣ Metrics ‣ Build tools ‣ Data formats ‣ Naming conventions ‣ Curly Braces ‣ Directory structure ‣ Everything
ENFORCE‣ Automate Everything
‣ VCS hooks ‣ CI ‣ Code reviews ‣ Reports ‣ Everything
‣ Warnings === errors ‣ Make it hard to be
wrong
DOCUMENT‣ Treat docs as code ‣ Make it
‣ easy to find ‣ easy to read ‣ easy to update ‣ easy to discuss
‣ Use github!
AGREE
GET EVERYONE TOGETHER
![Page 68: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/68.jpg)
Your automation choice needs to accommodate enforcement
![Page 69: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/69.jpg)
![Page 70: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/70.jpg)
![Page 71: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/71.jpg)
Recap
your analysis
your enforcement
your everything
Automate
Automate
Automate
![Page 72: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/72.jpg)
Interested in why a security hardware startup attracted so many JavaScript developers? Come talk to us!
esprima
venus
plato
grunt-contrib
![Page 73: Maintainability SFJS Sept 4 2014](https://reader034.fdocuments.us/reader034/viewer/2022051514/54b753e74a79592b5b8b46e3/html5/thumbnails/73.jpg)
Jarrod Overson - @jsoverson
AchievingMaintainability