Download - Leaning on the two Ts

Transcript
Page 1: Leaning on the two Ts

@theNeomatrix369

Are you pairing with tools to improve code quality ?

Leaning on tools & techniques to improve code quality

Page 2: Leaning on the two Ts

@theNeomatrix369

About meMani (@theNeomatrix369)

● LJC Associate● Adopt OpenJDK and JSR (JCP Member)● blog: http://neomatrix369.wordpress.com● github: http://github.com/neomatrix369● bitbucket: https://bitbucket.org/neomatrix369

Avatar: courtesy of Recworks: Dan Smallman @dsrecworks

Page 3: Leaning on the two Ts

@theNeomatrix369

- I’m only sharing my learning experience - YMMV !- Experimental yet practical methods- Learning via validating and verifying- A silver bullet to solve all problems- One shirt fits all solution- Not about any specific product

Disclaimer

Page 4: Leaning on the two Ts

@theNeomatrix369

Agenda- How it all started for me...- First steps to learning to use these tools...- Inventions- Observations- Introspection- Discoveries- Conclusion

Page 5: Leaning on the two Ts

@theNeomatrix369

How it all started for me...

Page 6: Leaning on the two Ts

@theNeomatrix369

My first computer - 8088 processor (8-bit processor)

My first game - Digger (not PacMan)

Mid-1990s

Page 7: Leaning on the two Ts

@theNeomatrix369

Between 2000-2010

Career started as a hobby - years later become a profession

Page 8: Leaning on the two Ts

@theNeomatrix369

Early 2010

Desire…more knowledge,

experience & skills

Page 10: Leaning on the two Ts

@theNeomatrix369

Sowing of seeds...

Page 11: Leaning on the two Ts

@theNeomatrix369Source: SonarQube (aka Sonar)

What does code quality mean to you ?

Is it the seven axes of quality ?

Page 12: Leaning on the two Ts

@theNeomatrix369

How do we improve quality ?

Page 13: Leaning on the two Ts

@theNeomatrix369

Pair programming is good...

Page 14: Leaning on the two Ts

@theNeomatrix369

...but not always available...

Page 15: Leaning on the two Ts

@theNeomatrix369

Then I had an idea...

Page 16: Leaning on the two Ts

@theNeomatrix369

Why not use tools...

Page 17: Leaning on the two Ts

@theNeomatrix369

First steps to learning to use these tools...

Page 18: Leaning on the two Ts

@theNeomatrix369

Treemaps are awesome...

10,000 feet view !

Page 19: Leaning on the two Ts

@theNeomatrix369

Dashboard - my own Quality metrics

Page 20: Leaning on the two Ts

@theNeomatrix369

Issue violations & Duplications

Checkstyle, Findbugs, PMD rules

Page 21: Leaning on the two Ts

@theNeomatrix369

What is Cyclomatic Complexity

or Complexity ?

Page 22: Leaning on the two Ts

@theNeomatrix369

In simple words, it is thenumber of pathways

due to decision logic in a software program.

See Wikipedia definition

Page 23: Leaning on the two Ts

@theNeomatrix369

ComplexitySee Definitions glossary

Page 24: Leaning on the two Ts

@theNeomatrix369

Refactoring saves the day...Higher complexity (CCI: 4) void doSomethingBasedOnCurrentState( int state ) {

switch ( state ) {

case INACTIVE: //doSomethingForInActiveState(); break;

case ACTIVE: //doSomethingForActiveState(); break;

case UNKNOWN: //doSomethingForUnknownState(); break;

}

}Lower complexity (CCI: 1)

public enum CurrentState { INACTIVE { void doSomething() {} }, ACTIVE { void doSomething() {} }, UNKNOWN { void doSomething() {} };

abstract void doSomething();}

CCI Source: SonarQube (Complexity scores)

Page 25: Leaning on the two Ts

@theNeomatrix369

Refactoring resources...

Page 26: Leaning on the two Ts

@theNeomatrix369

Test coverage - unit & integration tests

Hint: EclEmma, JaCoCo and IntelliJ Code Coverage

Page 27: Leaning on the two Ts

@theNeomatrix369

Performance tuning tools (short and long feedback loops)

- Application behaviour- GC behaviour (on the JVM)- Early or late feedback (during development, or post- development)- Profiling

Some known tools: Java Mission Control, Java Flight Recorder, jconsole, GC Viewer, VisualVM, HeapAnalyzer, PerfAnal, JAMon, HPJMeter, HonestProfiler, mjProf, Eclipse Memory Analyzer (MAT)

Page 28: Leaning on the two Ts

@theNeomatrix369

Performance tuning tools(short feedback loop)

Profiling tools

- Honest profiler- mjProf- Eclipse Memory Analyzer (MAT)- others

Page 29: Leaning on the two Ts

@theNeomatrix369

Performance tuning tools(short feedback loop)

JITWatch* - @chriswhocodes

Understand...Java HotSpot Just-In-Time (JIT) compiler...program execution.

Hot Method too big - among other JIT optimisation errors

Java 7 and Java 8 core methods above the default hot method inlining threshold

*an Adopt OpenJDK F/OSS project

Page 30: Leaning on the two Ts

@theNeomatrix369

Performance tuning tools(long feedback loop)

Censum - jclarity.com

- GC Analysis, similar to GC Viewer- Additional metrics and graphs- Built-in analytics, recommendations & heuristics

Page 31: Leaning on the two Ts

@theNeomatrix369

The others... Google CodePro

Coverity ThreadSafe

IntelliJ IDEA Squale

Veracode

Page 32: Leaning on the two Ts

@theNeomatrix369

Collaborate...share, crowd-source, machine learning...

(Hippie completion)

Page 33: Leaning on the two Ts

@theNeomatrix369

Inventions...

Page 34: Leaning on the two Ts

@theNeomatrix369

Strategies (checklists)

[ ] Strategy (method in the madness)[ ] Strategy (interesting, ear-marked)

Find the checklists in the Resources section at the bottom

Page 35: Leaning on the two Ts

@theNeomatrix369

Continuous Inspection

Individual inspections

(local first)

Page 36: Leaning on the two Ts

@theNeomatrix369

Continuous Inspection (local first)

Some more individual inspections

Page 37: Leaning on the two Ts

@theNeomatrix369

Rule of thumbMetrics Rule Mitigating action

Method complexity >= 6 pathways Refactor: split method

Class complexity >= 60 pathways Refactor: split class

LCOM4 >=2 responsibilities Refactor: new class / subclass

RFC per class > 40 connections (both ways - afferent & efferent)

Refactor: reduce dependencies and dependents, split class

Source: SonarSource resource, Book: SonarQube in Action

Page 38: Leaning on the two Ts

@theNeomatrix369

Observations...

Page 39: Leaning on the two Ts

@theNeomatrix369

Repetition...helps build muscle memory

Page 40: Leaning on the two Ts

@theNeomatrix369

Kata (型) ?

きょうしつ (kyoushitsu)

Page 41: Leaning on the two Ts

@theNeomatrix369

Katas - individual partsissues violations

duplicationscode (test) coverage

mutation testingquickcheck

immutability checkcomplexity check

performance check

Page 42: Leaning on the two Ts

@theNeomatrix369

Introspection...

Page 43: Leaning on the two Ts

@theNeomatrix369

Trust but verify

Trust your tool(s)……believe in your method(s)

Adopt advice from peers & experts… ...but also evaluate it yourself

Page 44: Leaning on the two Ts

@theNeomatrix369

Do these factors make up quality ?

developer: knowledge and skillsx

tool: tunability, features & capabilitiesx

(environment & team)

Page 45: Leaning on the two Ts

@theNeomatrix369

(when you take a plunge)

...its not just about tools, there is more….

Discovery…

Page 46: Leaning on the two Ts

@theNeomatrix369

Discovery…

...firstly a tool is onlya temporary scaffolding…

Page 47: Leaning on the two Ts

@theNeomatrix369

Discovery…

...its about methods and techniques...

(because tools are only a dumb conduit)

Page 48: Leaning on the two Ts

@theNeomatrix369

Discovery…

(...if you dive deeper…)its about the practise and developing good habits

"I'm not a great programmer; I'm just a good programmer with great habits.” Kent Beck, http://en.wikiquote.org/wiki/Kent_Beck

Page 49: Leaning on the two Ts

@theNeomatrix369

Realisations...

Writing good quality code takes practice, effort and time

Page 50: Leaning on the two Ts

@theNeomatrix369

Quality is a concerted effort of not just a single developer but a team of developers !

Realisations...

Page 51: Leaning on the two Ts

@theNeomatrix369

- Repetition- Measuring progress- Early detection- Short feedback loop- Reliable pairing - Filling the (missing) gap- Powerful & effective ally

Conclusion

Page 52: Leaning on the two Ts

@theNeomatrix369

Summary

● Personal story● Various methods & techniques: processes● Strategies (checklists)● Inventions & observations: continuous inspection (local first) & katas ● Discoveries and Realisations ● (My) conclusion

Page 54: Leaning on the two Ts

@theNeomatrix369

Q & A

Keep them coming !

Page 55: Leaning on the two Ts

@theNeomatrix369

Its time to share your methods and help improve our craft !

Please tweet your feedback at @theNeomatrix369

Page 56: Leaning on the two Ts

@theNeomatrix369

Devoxx UK - 17-19th June 2015

Socrates UK - 4-7th June 2015

Conferences

Page 57: Leaning on the two Ts

@theNeomatrix369

Let’s change the Java ecosystem, together!

Daniel Bryant @danielbryantuk Mani Sarkar @theNeomatrix369

With support from the JCP, London Java Community and Java communities worldwide

@adoptajsr@adoptopenjdk

[email protected]

[email protected]@openjdk.java.net

Page 58: Leaning on the two Ts

@theNeomatrix369

Resources● SonarQube resources● SonarQube Nemo project● Discussions on Sonar on JavaRanche● Installing SonarQube (formerly Sonar) on MacOsX Mountain Lion● Using SonarQube on MacOsX Mountain Lion● SonarGraph (http://www.hello2morrow.com/products/sonargraph)● Jitwatch: http://github.com/AdoptOpenJDK/jitwatch● QuickCheck (https://bitbucket.org/blob79/quickcheck)● Mutation Testing (http://pitest.org/ or http://ortask.com/mutator/)● Mutability Detector (https://github.com/MutabilityDetector/)● AssertJ - fluent assertions for Java (plus other fluent libraries)● Censum (@jclarity product - see http://www.jclarity.com/censum/)● Profilers: HonestProfiler, mjProf, Eclipse Memory Analyzer (MAT)● Books: Sonar in Action (http://www.manning.com/papapetrou/), Software

Craftsmanship by Sandro Mancuso, Uncle Bob’s Clean Code

Page 59: Leaning on the two Ts

@theNeomatrix369

Predecessor to this presentation...

http://bit.ly/1lk8NDW

to improve code quality !

SonarQubetm

Page 60: Leaning on the two Ts

@theNeomatrix369

Strategy (method in the madness)

[ ] Unit & Integration test coverage: EclEmma, JaCoco, IntelliJ Code Coverage check[ ] Most violated rules (Blockers, Critical, Major, Minor violations)[ ] Duplication removal - DRY[ ] Complexity (package-, file/class-, method-levels)[ ] Performance: profiling (memory, cpu, hardware)[ ] Performance: GC analysis*, JMH benchmarking** Java/JVM platforms only

Page 61: Leaning on the two Ts

@theNeomatrix369

Strategy (interesting, ear-marked)

[ ] Analyse & apply Squale reports[ ] Apply SonarGraph[ ] Apply Mutation testing (i.e. PITest, Mutator)[ ] Apply generative tests (QuickCheck)[ ] Apply Mutability Detector library[ ] Analyse using JitWatch (improve JIT attempts)[ ] Analyse using Censum (improve GC)

Page 62: Leaning on the two Ts

@theNeomatrix369

Quality of Music - truth tableQuality of instrument (material)

How tuned the instrument is?

Skills & experience of the performer

Quality of music(outcome)

Bad Not tuned Not skilled / Skilled Very Bad

Bad Tuned Not skilled / Skilled Bad

Medicore Not tuned Not skilled / Skilled Below Average

Good Tuned / Not tuned Not skilled / Skilled Average

Good Tuned Skilled Good

Very good Tuned Highly skilled Very good

Page 63: Leaning on the two Ts

@theNeomatrix369

Novice to expert...

In the beginning, learning from past experiences, building up knowledge and experience with repetitions, finally excelling with your own efforts...

Page 64: Leaning on the two Ts

@theNeomatrix369

Layers of qualityContinuous Deployment*

Continuous Integration*

Code quality

Tools & Methods

(Developing) Good Habits

Page 65: Leaning on the two Ts

@theNeomatrix369

Layers of quality (contd.)Continuous Deployment*

Continuous Integration*

See what Dr. Daniel Bryant has to say about the above:http://slidesha.re/1rKdOdUhttp://slidesha.re/VwKDB0

(Devops the TDD approach)