SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Steve Rodgers
steve.rodgers@gmail.com
CODE QUALITY
AN APOLOGY
THE DREAM
Metronomic build/fix/deploy cycle
Bug count always low per release
End users love the app as it never crashes 
Stakeholder 
QA 
Support team 
Project Manager 
Devs 
Imagine a world where
WHY CARE PART 1?
Business *MUST* care
WHY CARE PART 2
Developers *SHOULD* care
WHY CARE PART 3
The Quality Trade Off
THE MISSION: BUILD A MAINTAINABLE
LEGACY
Code spends most of its life being maintained
How hard is it to learn any new code base?
What is your legacy?
My $hit code will be your problem tomorrow
Your $hit code will be my problem today
MALLEABLE CODE
Code is rarely done unless it’s demo code
Business requirements change all the time
Code must therefore be engineered to handle continual
refactor
Code must be thought of as highly malleable
Every line is always up for possible refactor
How will you survive dominate in this world?
In The Real World
TIP: WRITE UNIT TESTS
Why write tests?
Validate class behaviour now and future proof it
Domain classes with behaviour must have tests
Data classes don’t need tests
Write meaningful tests
Be highly suspicious of 100% unit test coverage 
Be judicious; spend money where needed
Write tons of tests for critical algorithm
Don’t write tons of tests for 3 line method
Learn TDD then Practice TDD
TIP: AVOID WRITING GOD CLASSES
“A ‘God Class’ is an object that controls way too many
other objects in the system and has grown beyond all logic
to become The Class That Does Everything.”
[http://c2.com/cgi/wiki?GodClass]
The signs
1200 SLOC? 50 private methods? 35 fields?
No one in the team understands how it works?
The disease
GOD CLASS: UNIT TESTS HARD TO WRITE?
Class is hard to test?
Lots of complicated test setup code?
Lots of Asserts per test?
A unit test should only have a single Assert
Unit test on Elm Street
TIP: ADOPT SINGLE RESPONSIBILITY
PRINCIPLE
Class should have one responsibility
Refactor God class into multiple SRP classes
Write unit tests for each SRP class
The cure
TIP: AVOID UNMANAGED COMPLEXITY
Signals: Many lines of code, tons of methods but few
classes
Avoid function decomposition
Private method syndrome
Private methods cannot be unit tested
Embrace class decomposition
Lots of little classes
Write battery of unit tests for each little class
Refactor big private methods out into their own class (see
‘method-object’ Kent Beck)
TIP: USE SOFTWARE DESIGN PATTERNS
Don’t miss out on GOF patterns
Factory, Null Object, Decorator, Adapter etc
Patterns signal intent to other developers
Use only when needed
Don’t force them in when not needed
Be suspicious of large code base that doesn’t use patterns

Beware Dunning-Kruger Effect
CYCLOMATIC COMPLEXITY
“Cyclomatic complexity is a software metric
(measurement), used to indicate the complexity of a
program. It is a quantitative measure of the number of
linearly independent paths through a program's source
code.”
[https://en.wikipedia.org/wiki/Cyclomatic_complexity]
TIP: REDUCE HEAVY USE OF IMPERATIVE
STYLE
Complicated code is hard to understand
Nested if/else with lots of || and &&
Cyclomatic complexity is the work of the devil
Reduce use of imperative programming style
e.g. if/else/switch
Flock of seagulls lead to the gates to Hades {{{}}}
Challenge each other to reduce heavy use of them
Good use of OO, LINQ & patterns will help achieve this goal
Favour a functional programming style
e.g. LINQ
But avoid nested lambda hell
TIP: PUBLISH CYCLOMATIC COMPLEXITY
Dashboards like Sonar publish cyclomatic complexity
during the build for all to see
Visual Studio “Code Metrics” gives cyclomatic complexity
drill down
ReSharper add-on can graphically show cyclomatic
complexity in Visual Studio
CYCLOMATIC COMPLEXITY DEMO
TIP: AVOID STATIC
Static references & classes defeat unit testing
E.g. How do you mock DateTime.Now for daylight savings
unit tests when they run on January 14th?
Wrap use of static classes in an injected singleton that
delegates to static implementation
E.g. Define and implement IDateTime interface
Avoid ‘XyzHelper’ or ‘Util’ classes like the plague!
TIP: USE AWESOME NAMES EVERYWHERE
Take time to name every artefact
Class, method, field, property, parameter, automatic variable (prod
code + test code)
Class name is a noun
Method name is a verb
E.g. dog.Sleep(), table.Clear(),
documentAggregator.Aggregate()
Stuck for class name? http://classnamer.com 
E.g.
for(int p = 0; p < 10; p++) {}
for(int personIndex = 0; personIndex < 10;
personIndex++) {}
TIP: WRITE CLEAN CODE
Broken Window Theory
“maintaining and monitoring urban environments to preve
nt small crimes such as vandalism, public drinking and toll
-
jumping helps to create an atmosphere of order and lawful
ness, thereby preventing more serious crimes from
happening”
Corollary: Keep code+tests uber clean
[https://en.wikipedia.org/wiki/Broken_windows_theory]
Uncle Bob says ‘Keep it clean!’
TIP: AVOID INHERITANCE
Default to avoid inheritance: ‘is-a’
Why? Derived often needs to know base intimately
Default to favour composition: ‘has-a’
Only cave-in when ‘is-a’ rule satisfied
Dog is-a bone: fail
Dog has-a bone: pass
Cat is-a mammal: pass
Cat has-a mammal: fail
TIP: CODE REVIEW BEFORE CHECK-IN
Ideally every check-in gets peer reviewed prior to
check-in
Each check-in should have:
Description + name of reviewer
Over the shoulder review preferential
Rotate reviewers and share knowledge and tips within the
team == free peer training; level up
Also back up with post commit code review tool e.g.
Crucible
TIP: HOW TO CONDUCT CODE REVIEW
1. Park egos at the door
2. Team first attitude
3. Test coverage good?
4. Lots of private methods? God class?
5. Inheritance satisfies ‘is-a’ rule?
6. Interface based programming? Use of ‘new’ operator?
7. Good class/method/field/prop/auto names?
TIP: USE INVERSION OF CONTROL
Domain class constructor takes interface
parameters only (C#)
Don’t new domain class from within domain class
(fine to new framework classes e.g. List<T>,
Hashset<T> etc)
Why? Testing class A would be implicit test of B as well
Constructor stores interface parameter in field
Constructor does nothing else
Why? Interface can easily be mocked therefore easy to
test
Use 2-phase construction via Initialize() method if needed
INVERSION OF CONTROL DEMO
TIP: AVOID CODE COMMENTS
Comments are very useful for big and complicated things
Warning: Comments quickly get out of date with respect to
code during refactor
Comments not necessary for small and easy to understand
things
Corollary: Only create small, easy to understand well
named things and therefore ditch comments
TIP: AVOID EXCESSIVE NULL CHECKING
Excessive null checking is a Code smell
if (dog != null) {} OR if (dog == null)
Consider Null Object Pattern
DEMO NULL OBJECT PATTERN
TIP: CONFORM TO A SIMPLE CODE
STANDARD
Author a 1 page annotated coding standard
Why? If it all looks like it was written by one person then
it’s going to be easier maintain/learn
Get dev buy-in by building team consensus on
content
Print it off for everyone to put on the wall by their desk
Police it with code review
Use tooling: e.g. Write a Resharper standard and share
with the team
TIP: PRACTICE INTERFACE BASED
PROGRAMMING
Every domain class should should be accompanied by an
interface
What is a domain class?
One that has behaviour
Pass IDogController around, not DogController
Why? Decrease coupling between classes
TIP: USE MULTIPLE METHOD RETURNS
In the old days single method return was 
Why? Because of long complicated methods in God classes
Requires carefully nested method if/else hierarchy
If you don’t have God classes with long complicated
methods then you have no fear of multiple method returns
any more 
Why? Simpler to read due to dramatic reduction in nested
if/else hierarchy
TIP: AVOID C# REGIONS
Regions (#region) are a great place to hide code 
Often commented out code can be found hiding in them
God classes often lurk within regions pretending to not be
God classes Grrrrr
TIP: AVOID SPECULATIVE GENERALITY
App developers are often wannabe framework developers
Allow base classes to emerge from ongoing requirements
Don’t try and predict the future now
Avoid marking a method as virtual unless there is a class
to override it right now
TIP: BUY RESHARPER LICENSES
All C# devs should use ReSharper
Essential for quick and accurate refactoring
Set up shared team coding style
Reformat class(es) automatically before check-in
Find type
Find implementation of interface/method
Refactor name of class/method/field/auto etc
TIP: LEARN ALL LANGUAGE FEATURES
Polymorphism: check
Interface based programming: check
Generics: check
Iterators: check
LINQ: check
async/await: check
C#
TIP: HIRE QUALITY-MINDED ENGINEERS
Do they care about code quality? Ask them!
When was the last time they checked-in a unit test?
Prove it! Get them to write an algorithm on the white
board and a unit test for it
Get them to come up with the list of tests they would write
for the algorithm
Ensure good CS background: data structures & algorithms
Make sure they really know all the latest stuff (passion)
Never hire a ‘maybe’
Ensure good team fit – everyone meets the candidate
CALL TO ACTION
Code quality directly impacts $takeholder through to end
user experience
Up the ante: Make code quality your mission
Write good quality unit tests
Maintain a hygienic code base (inc tests)
Build a legacy your team is proud of that your users will
love
REFERENCES
Clean Code: A Handbook of Agile Software Craftsmanship,
Robert C Martin aka Uncle Bob
Awesome google talk (Misko Hevery)
http://www.youtube.com/watch?v=acjvKJiOvXw

Weitere Àhnliche Inhalte

Was ist angesagt?

Understanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptUnderstanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptMark Daggett
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit TestingSĂžren Lund
 
Coding standard
Coding standardCoding standard
Coding standardFAROOK Samath
 
Code review guidelines
Code review guidelinesCode review guidelines
Code review guidelinesLalit Kale
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging TechniquesBala Subra
 
Systematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zioSystematic error management - we ported rudder to zio
Systematic error management - we ported rudder to ziofanf42
 
Throwing Laravel into your Legacy Appℱ
Throwing Laravel into your Legacy AppℱThrowing Laravel into your Legacy Appℱ
Throwing Laravel into your Legacy AppℱJoe Ferguson
 
Speculative analysis for comment quality assessment
Speculative analysis for comment quality assessmentSpeculative analysis for comment quality assessment
Speculative analysis for comment quality assessmentPooja Rani
 
Euro python 2015 writing quality code
Euro python 2015   writing quality codeEuro python 2015   writing quality code
Euro python 2015 writing quality coderadek_j
 
Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Aditya Bhuyan
 
Konstantin Knizhnik: static analysis, a view from aside
Konstantin Knizhnik: static analysis, a view from asideKonstantin Knizhnik: static analysis, a view from aside
Konstantin Knizhnik: static analysis, a view from asidePVS-Studio
 
Test Driven Development (TDD) Basics
Test Driven Development (TDD) BasicsTest Driven Development (TDD) Basics
Test Driven Development (TDD) BasicsCarlos Andrés Oquendo
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality ToolsOrest Ivasiv
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@Alex Borsuk
 
Code Review
Code ReviewCode Review
Code Reviewrantav
 
FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09Pyxis Technologies
 
01. introduction to-programming
01. introduction to-programming01. introduction to-programming
01. introduction to-programmingStoian Kirov
 

Was ist angesagt? (19)

Understanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptUnderstanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScript
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit Testing
 
Coding standard
Coding standardCoding standard
Coding standard
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
 
Code review guidelines
Code review guidelinesCode review guidelines
Code review guidelines
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
Systematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zioSystematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zio
 
Throwing Laravel into your Legacy Appℱ
Throwing Laravel into your Legacy AppℱThrowing Laravel into your Legacy Appℱ
Throwing Laravel into your Legacy Appℱ
 
Exception handling in ASP .NET
Exception handling in ASP .NETException handling in ASP .NET
Exception handling in ASP .NET
 
Speculative analysis for comment quality assessment
Speculative analysis for comment quality assessmentSpeculative analysis for comment quality assessment
Speculative analysis for comment quality assessment
 
Euro python 2015 writing quality code
Euro python 2015   writing quality codeEuro python 2015   writing quality code
Euro python 2015 writing quality code
 
Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)
 
Konstantin Knizhnik: static analysis, a view from aside
Konstantin Knizhnik: static analysis, a view from asideKonstantin Knizhnik: static analysis, a view from aside
Konstantin Knizhnik: static analysis, a view from aside
 
Test Driven Development (TDD) Basics
Test Driven Development (TDD) BasicsTest Driven Development (TDD) Basics
Test Driven Development (TDD) Basics
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Code Review
Code ReviewCode Review
Code Review
 
FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09
 
01. introduction to-programming
01. introduction to-programming01. introduction to-programming
01. introduction to-programming
 

Ähnlich wie Code quality

Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
Simple testable code
Simple testable codeSimple testable code
Simple testable codefelixtrepanier
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Gianluca Padovani
 
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...mCloud
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applicationsChandra Sekhar Saripaka
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unitKotresh Munavallimatt
 
How to do code review and use analysis tool in software development
How to do code review and use analysis tool in software developmentHow to do code review and use analysis tool in software development
How to do code review and use analysis tool in software developmentMitosis Technology
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
 
Create first android app with MVVM Architecture
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecturekhushbu thakker
 
Journey's diary developing a framework using tdd
Journey's diary   developing a framework using tddJourney's diary   developing a framework using tdd
Journey's diary developing a framework using tddeduardomg23
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionPyxis Technologies
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
C# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkC# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkDr.Neeraj Kumar Pandey
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testingGianluca Padovani
 
Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Groupbrada
 
Building Scalable Development Environments
Building Scalable Development EnvironmentsBuilding Scalable Development Environments
Building Scalable Development EnvironmentsShahar Evron
 

Ähnlich wie Code quality (20)

Code Metrics
Code MetricsCode Metrics
Code Metrics
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
 
Simple testable code
Simple testable codeSimple testable code
Simple testable code
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unit
 
How to do code review and use analysis tool in software development
How to do code review and use analysis tool in software developmentHow to do code review and use analysis tool in software development
How to do code review and use analysis tool in software development
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Create first android app with MVVM Architecture
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecture
 
Journey's diary developing a framework using tdd
Journey's diary   developing a framework using tddJourney's diary   developing a framework using tdd
Journey's diary developing a framework using tdd
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
C# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkC# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net Framework
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Group
 
Building Scalable Development Environments
Building Scalable Development EnvironmentsBuilding Scalable Development Environments
Building Scalable Development Environments
 

Mehr von saber tabatabaee

clean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptxclean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptxsaber tabatabaee
 
Ù‡Ű§ŰłŰȘÛŒÙ†ÚŻ و Ű±Ű§Ù‡ Ű§Ù†ŰŻŰ§ŰČی یک ÙŸŰ±ÙˆÚ˜Ù‡ Ù„Ű§Ű±Ű§ÙˆÙ„ - ŰąÙ†Ű§Ù„ÛŒŰČ Ùˆ Ű§Ù…Ú©Ű§Ù† ŰłÙ†ŰŹÛŒ
Ù‡Ű§ŰłŰȘÛŒÙ†ÚŻ و Ű±Ű§Ù‡ Ű§Ù†ŰŻŰ§ŰČی یک ÙŸŰ±ÙˆÚ˜Ù‡ Ù„Ű§Ű±Ű§ÙˆÙ„ - ŰąÙ†Ű§Ù„ÛŒŰČ Ùˆ Ű§Ù…Ú©Ű§Ù† ŰłÙ†ŰŹÛŒÙ‡Ű§ŰłŰȘÛŒÙ†ÚŻ و Ű±Ű§Ù‡ Ű§Ù†ŰŻŰ§ŰČی یک ÙŸŰ±ÙˆÚ˜Ù‡ Ù„Ű§Ű±Ű§ÙˆÙ„ - ŰąÙ†Ű§Ù„ÛŒŰČ Ùˆ Ű§Ù…Ú©Ű§Ù† ŰłÙ†ŰŹÛŒ
Ù‡Ű§ŰłŰȘÛŒÙ†ÚŻ و Ű±Ű§Ù‡ Ű§Ù†ŰŻŰ§ŰČی یک ÙŸŰ±ÙˆÚ˜Ù‡ Ù„Ű§Ű±Ű§ÙˆÙ„ - ŰąÙ†Ű§Ù„ÛŒŰČ Ùˆ Ű§Ù…Ú©Ű§Ù† ŰłÙ†ŰŹÛŒsaber tabatabaee
 
Ù„Ű§Ű±Ű§ÙˆÙ„ Ű§Ű±Ű§ŰŠÙ‡ 26 ŰłÙŸŰȘŰ§Ù…ŰšŰ± 2021 Ű§ŰłÚ©Ű§ÛŒÙŸ
Ù„Ű§Ű±Ű§ÙˆÙ„ Ű§Ű±Ű§ŰŠÙ‡ 26 ŰłÙŸŰȘŰ§Ù…ŰšŰ± 2021 Ű§ŰłÚ©Ű§ÛŒÙŸÙ„Ű§Ű±Ű§ÙˆÙ„ Ű§Ű±Ű§ŰŠÙ‡ 26 ŰłÙŸŰȘŰ§Ù…ŰšŰ± 2021 Ű§ŰłÚ©Ű§ÛŒÙŸ
Ù„Ű§Ű±Ű§ÙˆÙ„ Ű§Ű±Ű§ŰŠÙ‡ 26 ŰłÙŸŰȘŰ§Ù…ŰšŰ± 2021 Ű§ŰłÚ©Ű§ÛŒÙŸsaber tabatabaee
 
scrum master Ű§ŰłÚ©Ű±Ű§Ù… Ù…ŰłŰȘ۱
scrum master Ű§ŰłÚ©Ű±Ű§Ù… Ù…ŰłŰȘ۱scrum master Ű§ŰłÚ©Ű±Ű§Ù… Ù…ŰłŰȘ۱
scrum master Ű§ŰłÚ©Ű±Ű§Ù… Ù…ŰłŰȘ۱saber tabatabaee
 
Scrum master - daily scrum master story
Scrum master - daily scrum master storyScrum master - daily scrum master story
Scrum master - daily scrum master storysaber tabatabaee
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionsaber tabatabaee
 
teaching data science students to write clean code
teaching data science students to write clean codeteaching data science students to write clean code
teaching data science students to write clean codesaber tabatabaee
 
Writing clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancodingWriting clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancodingsaber tabatabaee
 
R. herves. clean code (theme)2
R. herves. clean code (theme)2R. herves. clean code (theme)2
R. herves. clean code (theme)2saber tabatabaee
 
refactoring code by clean code rules
refactoring code by clean code rulesrefactoring code by clean code rules
refactoring code by clean code rulessaber tabatabaee
 
clean code - uncle bob
clean code - uncle bobclean code - uncle bob
clean code - uncle bobsaber tabatabaee
 
sharepoint 2007 presentation in crcis
sharepoint 2007 presentation in crcis sharepoint 2007 presentation in crcis
sharepoint 2007 presentation in crcis saber tabatabaee
 
Linux DVD 03 Learnkey linux+ setup
Linux DVD 03 Learnkey linux+ setupLinux DVD 03 Learnkey linux+ setup
Linux DVD 03 Learnkey linux+ setupsaber tabatabaee
 
linux+ learnkey DVD 2
linux+ learnkey DVD 2 linux+ learnkey DVD 2
linux+ learnkey DVD 2 saber tabatabaee
 

Mehr von saber tabatabaee (18)

clean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptxclean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptx
 
Ù‡Ű§ŰłŰȘÛŒÙ†ÚŻ و Ű±Ű§Ù‡ Ű§Ù†ŰŻŰ§ŰČی یک ÙŸŰ±ÙˆÚ˜Ù‡ Ù„Ű§Ű±Ű§ÙˆÙ„ - ŰąÙ†Ű§Ù„ÛŒŰČ Ùˆ Ű§Ù…Ú©Ű§Ù† ŰłÙ†ŰŹÛŒ
Ù‡Ű§ŰłŰȘÛŒÙ†ÚŻ و Ű±Ű§Ù‡ Ű§Ù†ŰŻŰ§ŰČی یک ÙŸŰ±ÙˆÚ˜Ù‡ Ù„Ű§Ű±Ű§ÙˆÙ„ - ŰąÙ†Ű§Ù„ÛŒŰČ Ùˆ Ű§Ù…Ú©Ű§Ù† ŰłÙ†ŰŹÛŒÙ‡Ű§ŰłŰȘÛŒÙ†ÚŻ و Ű±Ű§Ù‡ Ű§Ù†ŰŻŰ§ŰČی یک ÙŸŰ±ÙˆÚ˜Ù‡ Ù„Ű§Ű±Ű§ÙˆÙ„ - ŰąÙ†Ű§Ù„ÛŒŰČ Ùˆ Ű§Ù…Ú©Ű§Ù† ŰłÙ†ŰŹÛŒ
Ù‡Ű§ŰłŰȘÛŒÙ†ÚŻ و Ű±Ű§Ù‡ Ű§Ù†ŰŻŰ§ŰČی یک ÙŸŰ±ÙˆÚ˜Ù‡ Ù„Ű§Ű±Ű§ÙˆÙ„ - ŰąÙ†Ű§Ù„ÛŒŰČ Ùˆ Ű§Ù…Ú©Ű§Ù† ŰłÙ†ŰŹÛŒ
 
Ù„Ű§Ű±Ű§ÙˆÙ„ Ű§Ű±Ű§ŰŠÙ‡ 26 ŰłÙŸŰȘŰ§Ù…ŰšŰ± 2021 Ű§ŰłÚ©Ű§ÛŒÙŸ
Ù„Ű§Ű±Ű§ÙˆÙ„ Ű§Ű±Ű§ŰŠÙ‡ 26 ŰłÙŸŰȘŰ§Ù…ŰšŰ± 2021 Ű§ŰłÚ©Ű§ÛŒÙŸÙ„Ű§Ű±Ű§ÙˆÙ„ Ű§Ű±Ű§ŰŠÙ‡ 26 ŰłÙŸŰȘŰ§Ù…ŰšŰ± 2021 Ű§ŰłÚ©Ű§ÛŒÙŸ
Ù„Ű§Ű±Ű§ÙˆÙ„ Ű§Ű±Ű§ŰŠÙ‡ 26 ŰłÙŸŰȘŰ§Ù…ŰšŰ± 2021 Ű§ŰłÚ©Ű§ÛŒÙŸ
 
scrum master Ű§ŰłÚ©Ű±Ű§Ù… Ù…ŰłŰȘ۱
scrum master Ű§ŰłÚ©Ű±Ű§Ù… Ù…ŰłŰȘ۱scrum master Ű§ŰłÚ©Ű±Ű§Ù… Ù…ŰłŰȘ۱
scrum master Ű§ŰłÚ©Ű±Ű§Ù… Ù…ŰłŰȘ۱
 
L5 swagger
L5 swaggerL5 swagger
L5 swagger
 
Crm or xrm
Crm or xrmCrm or xrm
Crm or xrm
 
Scrum master - daily scrum master story
Scrum master - daily scrum master storyScrum master - daily scrum master story
Scrum master - daily scrum master story
 
Online exam ismc
Online exam ismcOnline exam ismc
Online exam ismc
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
teaching data science students to write clean code
teaching data science students to write clean codeteaching data science students to write clean code
teaching data science students to write clean code
 
Writing clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancodingWriting clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancoding
 
R. herves. clean code (theme)2
R. herves. clean code (theme)2R. herves. clean code (theme)2
R. herves. clean code (theme)2
 
Clean code chpt_1
Clean code chpt_1Clean code chpt_1
Clean code chpt_1
 
refactoring code by clean code rules
refactoring code by clean code rulesrefactoring code by clean code rules
refactoring code by clean code rules
 
clean code - uncle bob
clean code - uncle bobclean code - uncle bob
clean code - uncle bob
 
sharepoint 2007 presentation in crcis
sharepoint 2007 presentation in crcis sharepoint 2007 presentation in crcis
sharepoint 2007 presentation in crcis
 
Linux DVD 03 Learnkey linux+ setup
Linux DVD 03 Learnkey linux+ setupLinux DVD 03 Learnkey linux+ setup
Linux DVD 03 Learnkey linux+ setup
 
linux+ learnkey DVD 2
linux+ learnkey DVD 2 linux+ learnkey DVD 2
linux+ learnkey DVD 2
 

KĂŒrzlich hochgeladen

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp KrisztiĂĄn
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžcall girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžDelhi Call girls
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 

KĂŒrzlich hochgeladen (20)

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžcall girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Code quality

  • 3. THE DREAM Metronomic build/fix/deploy cycle Bug count always low per release End users love the app as it never crashes  Stakeholder  QA  Support team  Project Manager  Devs  Imagine a world where
  • 4. WHY CARE PART 1? Business *MUST* care
  • 5. WHY CARE PART 2 Developers *SHOULD* care
  • 6. WHY CARE PART 3 The Quality Trade Off
  • 7. THE MISSION: BUILD A MAINTAINABLE LEGACY Code spends most of its life being maintained How hard is it to learn any new code base? What is your legacy? My $hit code will be your problem tomorrow Your $hit code will be my problem today
  • 8. MALLEABLE CODE Code is rarely done unless it’s demo code Business requirements change all the time Code must therefore be engineered to handle continual refactor Code must be thought of as highly malleable Every line is always up for possible refactor How will you survive dominate in this world? In The Real World
  • 9. TIP: WRITE UNIT TESTS Why write tests? Validate class behaviour now and future proof it Domain classes with behaviour must have tests Data classes don’t need tests Write meaningful tests Be highly suspicious of 100% unit test coverage  Be judicious; spend money where needed Write tons of tests for critical algorithm Don’t write tons of tests for 3 line method Learn TDD then Practice TDD
  • 10. TIP: AVOID WRITING GOD CLASSES “A ‘God Class’ is an object that controls way too many other objects in the system and has grown beyond all logic to become The Class That Does Everything.” [http://c2.com/cgi/wiki?GodClass] The signs 1200 SLOC? 50 private methods? 35 fields? No one in the team understands how it works? The disease
  • 11. GOD CLASS: UNIT TESTS HARD TO WRITE? Class is hard to test? Lots of complicated test setup code? Lots of Asserts per test? A unit test should only have a single Assert Unit test on Elm Street
  • 12. TIP: ADOPT SINGLE RESPONSIBILITY PRINCIPLE Class should have one responsibility Refactor God class into multiple SRP classes Write unit tests for each SRP class The cure
  • 13. TIP: AVOID UNMANAGED COMPLEXITY Signals: Many lines of code, tons of methods but few classes Avoid function decomposition Private method syndrome Private methods cannot be unit tested Embrace class decomposition Lots of little classes Write battery of unit tests for each little class Refactor big private methods out into their own class (see ‘method-object’ Kent Beck)
  • 14. TIP: USE SOFTWARE DESIGN PATTERNS Don’t miss out on GOF patterns Factory, Null Object, Decorator, Adapter etc Patterns signal intent to other developers Use only when needed Don’t force them in when not needed Be suspicious of large code base that doesn’t use patterns  Beware Dunning-Kruger Effect
  • 15. CYCLOMATIC COMPLEXITY “Cyclomatic complexity is a software metric (measurement), used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code.” [https://en.wikipedia.org/wiki/Cyclomatic_complexity]
  • 16. TIP: REDUCE HEAVY USE OF IMPERATIVE STYLE Complicated code is hard to understand Nested if/else with lots of || and && Cyclomatic complexity is the work of the devil Reduce use of imperative programming style e.g. if/else/switch Flock of seagulls lead to the gates to Hades {{{}}} Challenge each other to reduce heavy use of them Good use of OO, LINQ & patterns will help achieve this goal Favour a functional programming style e.g. LINQ But avoid nested lambda hell
  • 17. TIP: PUBLISH CYCLOMATIC COMPLEXITY Dashboards like Sonar publish cyclomatic complexity during the build for all to see Visual Studio “Code Metrics” gives cyclomatic complexity drill down ReSharper add-on can graphically show cyclomatic complexity in Visual Studio
  • 19. TIP: AVOID STATIC Static references & classes defeat unit testing E.g. How do you mock DateTime.Now for daylight savings unit tests when they run on January 14th? Wrap use of static classes in an injected singleton that delegates to static implementation E.g. Define and implement IDateTime interface Avoid ‘XyzHelper’ or ‘Util’ classes like the plague!
  • 20. TIP: USE AWESOME NAMES EVERYWHERE Take time to name every artefact Class, method, field, property, parameter, automatic variable (prod code + test code) Class name is a noun Method name is a verb E.g. dog.Sleep(), table.Clear(), documentAggregator.Aggregate() Stuck for class name? http://classnamer.com  E.g. for(int p = 0; p < 10; p++) {} for(int personIndex = 0; personIndex < 10; personIndex++) {}
  • 21. TIP: WRITE CLEAN CODE Broken Window Theory “maintaining and monitoring urban environments to preve nt small crimes such as vandalism, public drinking and toll - jumping helps to create an atmosphere of order and lawful ness, thereby preventing more serious crimes from happening” Corollary: Keep code+tests uber clean [https://en.wikipedia.org/wiki/Broken_windows_theory] Uncle Bob says ‘Keep it clean!’
  • 22. TIP: AVOID INHERITANCE Default to avoid inheritance: ‘is-a’ Why? Derived often needs to know base intimately Default to favour composition: ‘has-a’ Only cave-in when ‘is-a’ rule satisfied Dog is-a bone: fail Dog has-a bone: pass Cat is-a mammal: pass Cat has-a mammal: fail
  • 23. TIP: CODE REVIEW BEFORE CHECK-IN Ideally every check-in gets peer reviewed prior to check-in Each check-in should have: Description + name of reviewer Over the shoulder review preferential Rotate reviewers and share knowledge and tips within the team == free peer training; level up Also back up with post commit code review tool e.g. Crucible
  • 24. TIP: HOW TO CONDUCT CODE REVIEW 1. Park egos at the door 2. Team first attitude 3. Test coverage good? 4. Lots of private methods? God class? 5. Inheritance satisfies ‘is-a’ rule? 6. Interface based programming? Use of ‘new’ operator? 7. Good class/method/field/prop/auto names?
  • 25. TIP: USE INVERSION OF CONTROL Domain class constructor takes interface parameters only (C#) Don’t new domain class from within domain class (fine to new framework classes e.g. List<T>, Hashset<T> etc) Why? Testing class A would be implicit test of B as well Constructor stores interface parameter in field Constructor does nothing else Why? Interface can easily be mocked therefore easy to test Use 2-phase construction via Initialize() method if needed
  • 27. TIP: AVOID CODE COMMENTS Comments are very useful for big and complicated things Warning: Comments quickly get out of date with respect to code during refactor Comments not necessary for small and easy to understand things Corollary: Only create small, easy to understand well named things and therefore ditch comments
  • 28. TIP: AVOID EXCESSIVE NULL CHECKING Excessive null checking is a Code smell if (dog != null) {} OR if (dog == null) Consider Null Object Pattern
  • 29. DEMO NULL OBJECT PATTERN
  • 30. TIP: CONFORM TO A SIMPLE CODE STANDARD Author a 1 page annotated coding standard Why? If it all looks like it was written by one person then it’s going to be easier maintain/learn Get dev buy-in by building team consensus on content Print it off for everyone to put on the wall by their desk Police it with code review Use tooling: e.g. Write a Resharper standard and share with the team
  • 31. TIP: PRACTICE INTERFACE BASED PROGRAMMING Every domain class should should be accompanied by an interface What is a domain class? One that has behaviour Pass IDogController around, not DogController Why? Decrease coupling between classes
  • 32. TIP: USE MULTIPLE METHOD RETURNS In the old days single method return was  Why? Because of long complicated methods in God classes Requires carefully nested method if/else hierarchy If you don’t have God classes with long complicated methods then you have no fear of multiple method returns any more  Why? Simpler to read due to dramatic reduction in nested if/else hierarchy
  • 33. TIP: AVOID C# REGIONS Regions (#region) are a great place to hide code  Often commented out code can be found hiding in them God classes often lurk within regions pretending to not be God classes Grrrrr
  • 34. TIP: AVOID SPECULATIVE GENERALITY App developers are often wannabe framework developers Allow base classes to emerge from ongoing requirements Don’t try and predict the future now Avoid marking a method as virtual unless there is a class to override it right now
  • 35. TIP: BUY RESHARPER LICENSES All C# devs should use ReSharper Essential for quick and accurate refactoring Set up shared team coding style Reformat class(es) automatically before check-in Find type Find implementation of interface/method Refactor name of class/method/field/auto etc
  • 36. TIP: LEARN ALL LANGUAGE FEATURES Polymorphism: check Interface based programming: check Generics: check Iterators: check LINQ: check async/await: check C#
  • 37. TIP: HIRE QUALITY-MINDED ENGINEERS Do they care about code quality? Ask them! When was the last time they checked-in a unit test? Prove it! Get them to write an algorithm on the white board and a unit test for it Get them to come up with the list of tests they would write for the algorithm Ensure good CS background: data structures & algorithms Make sure they really know all the latest stuff (passion) Never hire a ‘maybe’ Ensure good team fit – everyone meets the candidate
  • 38. CALL TO ACTION Code quality directly impacts $takeholder through to end user experience Up the ante: Make code quality your mission Write good quality unit tests Maintain a hygienic code base (inc tests) Build a legacy your team is proud of that your users will love
  • 39. REFERENCES Clean Code: A Handbook of Agile Software Craftsmanship, Robert C Martin aka Uncle Bob Awesome google talk (Misko Hevery) http://www.youtube.com/watch?v=acjvKJiOvXw