Leaning on the two Ts

Post on 14-Jun-2015

974 views 1 download

Tags:

description

Leaning on the two Ts is a talk on improving code quality, personal practise and developing good habits using tools and techniques. Attendees of this talk will learn about my experience when learning to use static analysis tools (i.e. SonarQube) and some of its features. In addition also find out how it can be used to improve your code quality and personal practice. A number of tools will also be mentioned and how to include them in your practise. Powerpoint-like presentation sharing information from a perspective higher than just the use of tools, although no runtime implementation or live coding will be performed. Live examples might be shown depending on time constraints. The presentation is definitely for intermediate and experienced Java developers, but also beginner developers who would like to know more about code quality and tools that can be of help. Also for those already using static analysis or other tools in anger or just casually. Especially those who would like to know how to use tools as a medium to learn from.

Transcript of Leaning on the two Ts

@theNeomatrix369

Are you pairing with tools to improve code quality ?

Leaning on tools & techniques to improve code quality

@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

@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

@theNeomatrix369

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

@theNeomatrix369

How it all started for me...

@theNeomatrix369

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

My first game - Digger (not PacMan)

Mid-1990s

@theNeomatrix369

Between 2000-2010

Career started as a hobby - years later become a profession

@theNeomatrix369

Early 2010

Desire…more knowledge,

experience & skills

@theNeomatrix369

Sowing of seeds...

@theNeomatrix369Source: SonarQube (aka Sonar)

What does code quality mean to you ?

Is it the seven axes of quality ?

@theNeomatrix369

How do we improve quality ?

@theNeomatrix369

Pair programming is good...

@theNeomatrix369

...but not always available...

@theNeomatrix369

Then I had an idea...

@theNeomatrix369

Why not use tools...

@theNeomatrix369

First steps to learning to use these tools...

@theNeomatrix369

Treemaps are awesome...

10,000 feet view !

@theNeomatrix369

Dashboard - my own Quality metrics

@theNeomatrix369

Issue violations & Duplications

Checkstyle, Findbugs, PMD rules

@theNeomatrix369

What is Cyclomatic Complexity

or Complexity ?

@theNeomatrix369

In simple words, it is thenumber of pathways

due to decision logic in a software program.

See Wikipedia definition

@theNeomatrix369

ComplexitySee Definitions glossary

@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)

@theNeomatrix369

Refactoring resources...

@theNeomatrix369

Test coverage - unit & integration tests

Hint: EclEmma, JaCoCo and IntelliJ Code Coverage

@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)

@theNeomatrix369

Performance tuning tools(short feedback loop)

Profiling tools

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

@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

@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

@theNeomatrix369

The others... Google CodePro

Coverity ThreadSafe

IntelliJ IDEA Squale

Veracode

@theNeomatrix369

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

(Hippie completion)

@theNeomatrix369

Inventions...

@theNeomatrix369

Strategies (checklists)

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

Find the checklists in the Resources section at the bottom

@theNeomatrix369

Continuous Inspection

Individual inspections

(local first)

@theNeomatrix369

Continuous Inspection (local first)

Some more individual inspections

@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

@theNeomatrix369

Observations...

@theNeomatrix369

Repetition...helps build muscle memory

@theNeomatrix369

Kata (型) ?

きょうしつ (kyoushitsu)

@theNeomatrix369

Katas - individual partsissues violations

duplicationscode (test) coverage

mutation testingquickcheck

immutability checkcomplexity check

performance check

@theNeomatrix369

Introspection...

@theNeomatrix369

Trust but verify

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

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

@theNeomatrix369

Do these factors make up quality ?

developer: knowledge and skillsx

tool: tunability, features & capabilitiesx

(environment & team)

@theNeomatrix369

(when you take a plunge)

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

Discovery…

@theNeomatrix369

Discovery…

...firstly a tool is onlya temporary scaffolding…

@theNeomatrix369

Discovery…

...its about methods and techniques...

(because tools are only a dumb conduit)

@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

@theNeomatrix369

Realisations...

Writing good quality code takes practice, effort and time

@theNeomatrix369

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

Realisations...

@theNeomatrix369

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

Conclusion

@theNeomatrix369

Summary

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

@theNeomatrix369

Q & A

Keep them coming !

@theNeomatrix369

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

Please tweet your feedback at @theNeomatrix369

@theNeomatrix369

Devoxx UK - 17-19th June 2015

Socrates UK - 4-7th June 2015

Conferences

@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

members@adoptajsr.java.net

adopt-openjdk@googlegroups.comadoption-discuss@openjdk.java.net

@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

@theNeomatrix369

Predecessor to this presentation...

http://bit.ly/1lk8NDW

to improve code quality !

SonarQubetm

@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

@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)

@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

@theNeomatrix369

Novice to expert...

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

@theNeomatrix369

Layers of qualityContinuous Deployment*

Continuous Integration*

Code quality

Tools & Methods

(Developing) Good Habits

@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)