+ All Categories
Home > Business > A modern architecturereview–usingcodereviewtools-ver-3.5

A modern architecturereview–usingcodereviewtools-ver-3.5

Date post: 28-Nov-2014
Category:
Upload: ssw
View: 718 times
Download: 0 times
Share this document with a friend
Description:
For any project that is critical to the business, it’s important to do ‘Modern Architecture Reviews’. Being an architect is fun, you get to design the system, do ongoing code reviews, and play the bad ass. It is even more fun when using modern cool tools.
151
A Modern Architecture Review Using Code Review Tools Delivering Awesome Web Applications @AdamCogan | #vsalm #tee12 #dev324
Transcript
Page 1: A modern architecturereview–usingcodereviewtools-ver-3.5

A Modern Architecture ReviewUsing Code Review Tools

Delivering Awesome Web Applications

@AdamCogan | #vsalm #tee12 #dev324

Page 2: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 3: A modern architecturereview–usingcodereviewtools-ver-3.5

Agenda

• #1 The 1st things to look out for

• Processes• Does it work?• Documentation

•#2 High Level tools• Architecture• Code Analysis• Code Metrics

•#3 Manual Checking• SOLID Design Principles• Code Review tools

V9.5

Page 4: A modern architecturereview–usingcodereviewtools-ver-3.5

Chief Architect at SSW Developing custom solutions for

businesses across a range of industries such as Government, banking, insurance

Microsoft Gold Partner

Microsoft Regional Director

VSTS MVP

@AdamCogan

About Adam

Page 5: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 6: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 7: A modern architecturereview–usingcodereviewtools-ver-3.5

I Believe

Page 8: A modern architecturereview–usingcodereviewtools-ver-3.5

The first things to look out for

Page 9: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you evaluate the processes?

Often times this is the source of problems Are devs getting bogged down in the UI? Do you have a Scrum Master? Do you have continuous integration? Do you have continuous deployment? Do you have a Schema Master? Do you have a TFS Master?

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouHaveTheDesignersFixingUpTheUI.aspx

Page 10: A modern architecturereview–usingcodereviewtools-ver-3.5

Are they on the latest version?

…of VS

…of TFS

Alternatively for a ‘Gold Star’ … Resharper, add-ins, extensions

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/CanYouGetLatestAndCompile.aspx

Page 11: A modern architecturereview–usingcodereviewtools-ver-3.5

Can you ‘Get latest’ and compile? #L1

It's amazing how often you can't simply do a "Get Latest" and compile

Add _Instructions_Compile.docx

Then run unit tests…

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/CanYouGetLatestAndCompile.aspx

Page 12: A modern architecturereview–usingcodereviewtools-ver-3.5

Can you get latest and compile? #L1

See the Integration.Test project fail

Add _Instructions_Compile.docx

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/CanYouGetLatestAndCompile.aspx

Page 13: A modern architecturereview–usingcodereviewtools-ver-3.5

Can you get latest and compile? #L2

Creation of the database via scripts (incremental)Tip: use OSQL, SQLCMD or SSW SQL Deploy

and re-run the tests. They will now pass.

Page 14: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you want a ‘Gold Star’ ? #L3

Streamline setup of a new development environment

Problems to check for: Windows 8 not supported Many things to build Lots of dependencies

Recommendation: All manual work station setup steps should be scripted with PowerShell

Recommendation: A get + compile should work within 1 minute, and work without a dev being on the domain (to support external consultants)

Page 15: A modern architecturereview–usingcodereviewtools-ver-3.5

Figure: You see the problems in the devs environmentNote Prefix e.g. _01Setup-Environment.ps1

PS C:\Code\Northwind> .\Setup-Environment.ps1

Problem: Azure environment variable run state directory is not configured (_CSRUN_STATE_DIRECTORY). Problem: Azure Storage Service is not running. Launch the development fabric by starting the solution. 

WARNING: Abandoning remainder of script due to critical failures. To try and automatically resolve the problems found, re-run the script with a -Fix flag.

Page 16: A modern architecturereview–usingcodereviewtools-ver-3.5

Figure: The script tries to automatically fix the problems

PS C:\Code\Northwind> .\Setup-Environment.ps1 -fix

Problem: Azure environment variable run state directory is not configured (_CSRUN_STATE_DIRECTORY).Fixed: _CSRUN_STATE_DIRECTORY user variable set Problem: Azure Storage Service is not running. Launch the development fabric by starting the solution.WARNING: No automated fix available for 'Azure Storage Service is running' 

WARNING: Abandoning remainder of script due to critical failures.

Page 17: A modern architecturereview–usingcodereviewtools-ver-3.5

Figure: Note on 2nd run only 1 script remains – see there is less to fix

PS C:\Code\Northwind> .\Setup-Environment.ps1 -fix

Problem: Azure Storage Service is not running. Launch the development fabric by starting the solution.WARNING: No automated fix available for 'Azure Storage Service is running'

WARNING: Abandoning remainder of script due to critical failures.

Page 18: A modern architecturereview–usingcodereviewtools-ver-3.5

Can you ‘Check In’ and Deploy #L1

Add _Instructions_Deploy.docx

Alternatively for a ‘Star’ …

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/Default.aspx

Page 19: A modern architecturereview–usingcodereviewtools-ver-3.5

Can you ‘Check In’ and Deploy #L2

Use PowerShell scripts as your documentation build.ps1 deploy_dev.ps1 deploy_test.ps1 deploy_prod.ps1

Alternatively for a ‘Gold Star’ … TFSBuild + Portal

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/Default.aspx

Page 20: A modern architecturereview–usingcodereviewtools-ver-3.5

Can you ‘Check In’ and Deploy #L2TFSBuild + Portal

Page 21: A modern architecturereview–usingcodereviewtools-ver-3.5

The compile problem….

A team issue?

Does it matter?

No?

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/CanYouGetLatestAndCompile.aspx

Page 22: A modern architecturereview–usingcodereviewtools-ver-3.5

Methods of compiling [Pain] ?

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/CanYouGetLatestAndCompile.aspx

Page 23: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 24: A modern architecturereview–usingcodereviewtools-ver-3.5

Tip: Should you compile? [Pain]

Look at the page…

Alt+Tab to Visual studio

Modify file

Save

F5

Wait 15 sec…

Change the url (sometimes a crazy error)…

Hit F5… Wait 5 sec

Review change… (report)

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/CanYouGetLatestAndCompile.aspx

Page 25: A modern architecturereview–usingcodereviewtools-ver-3.5

Tip: Should you compile? [Pain]

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/CanYouGetLatestAndCompile.aspx

Page 26: A modern architecturereview–usingcodereviewtools-ver-3.5

Tip: Should you compile? [Pain]

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/CanYouGetLatestAndCompile.aspx

Page 27: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you review the Solution and Project names?

The name of your solution and the names of the project in your solution should be consistent

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouReviewTheSolutionName.aspx

Page 28: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 29: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you review the documentation?

Old School: Heavy, long documents Sequence Diagrams UML

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouReviewTheDocumentation.aspx

Page 30: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 31: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 32: A modern architecturereview–usingcodereviewtools-ver-3.5

Suggestions for doco e.g. Enterprise Architect

Use Red for unimplemented stuff

Use the DateTime shape To see the last time the diagram was modified and by whom

Mark items as ‘TODO: Adam’. For items still pending

Page 33: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you review the documentation

New School:

4 docs• Business.docx• _Instructions_Compile.docx• _Instructions_Deploy.docx• Technologies.docx

Unit Tests (low level) Code and Work Items (low level PBI)

Page 34: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 35: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 36: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 37: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 38: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 39: A modern architecturereview–usingcodereviewtools-ver-3.5

Vote:

Page 40: A modern architecturereview–usingcodereviewtools-ver-3.5

High Level Tools

Page 41: A modern architecturereview–usingcodereviewtools-ver-3.5

Agenda

• #1 The 1st things to look out for

• Processes• Does it work?• Documentation

•#2 High Level tools• Architecture• Code Analysis• Code Metrics

•#3 Manual Checking• SOLID Design Principles• Code Review tools

Page 42: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you look at the architecture?

2 Choices:

VS Dependency Graph or … ?• Ultimate Edition + Take screenshots

nDepend ?• 3rd Party Tool for a few hundred $ + Take screenshots • Bad - Attach… Detach…. Noisy UI• Bad - Complicated• Good - No need for VS Ultimate• Bonus: See problems in the ‘Queries + Rules Explorer’ • Awesome - Customizable

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouLookAtTheArchitecture.aspx

Page 43: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 44: A modern architecturereview–usingcodereviewtools-ver-3.5

My Dream

Page 45: A modern architecturereview–usingcodereviewtools-ver-3.5

My Dream – instead of this

Page 46: A modern architecturereview–usingcodereviewtools-ver-3.5

My Dream – it automatically does this

Page 47: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 48: A modern architecturereview–usingcodereviewtools-ver-3.5

Ndepend Relationships 101Dependancy Graphs Intro• Drill into a major relationship• Edge Thickness: # Types• [Major] Select Types | That are using me directly or

indirectly

Doco:Relationship | Export to HTML

• Relationship | Export to Graph• Relationship | Generate a code rule that warns if this

dependency exists• Relationship | View internal Dependency cycles on graph

Page 49: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 50: A modern architecturereview–usingcodereviewtools-ver-3.5

Something for the wall

• http://www.ndepend.com/Res/DiagramBoxAndArrowGraphBig.jpg

Page 51: A modern architecturereview–usingcodereviewtools-ver-3.5

Ndepend Relationship 201• See bidirectional relationships• Potentially not healthy• Relationship | Open this dependency on Matrix

About Erosion• Much more green… then the blue is erosion• Solution? Adaptive Design… moving towards the way the software

has evolved• Fix by remove the hard dependency in the wrong direction. Add

some Inversion of Control (aka interfaces) in the middle

Page 52: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 53: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 54: A modern architecturereview–usingcodereviewtools-ver-3.5

Look at what to refactor

Page 55: A modern architecturereview–usingcodereviewtools-ver-3.5

Ndepend Relationships 301Continuing….the matrix

Before fixing understand the scope

Right click | Build a graph representing one of the shortest paths

Page 56: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 57: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 58: A modern architecturereview–usingcodereviewtools-ver-3.5

Ndepend 401The rules

Q: Which ones do you care about?

(use the Metrics view for a picture)

Page 59: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 60: A modern architecturereview–usingcodereviewtools-ver-3.5

Or…

Page 61: A modern architecturereview–usingcodereviewtools-ver-3.5

Great Overview tool and learning toolNot for day-to-day use as a code analysis tool.Note: Don’t be distracted by a colour problem

Page 62: A modern architecturereview–usingcodereviewtools-ver-3.5

The Goal for your Code Analysis?

Page 63: A modern architecturereview–usingcodereviewtools-ver-3.5

The Goal for your Code Analysis?

Encourage team members to check in their code regularlywith no Code Analysis warnings, and Code Metrics in green.

Eg.

Page 64: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 65: A modern architecturereview–usingcodereviewtools-ver-3.5

Lets have a look at my Norwegian Ninja

Page 67: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you use the best Code Analysis tools?

Level 1 – ReSharper – All Rules

Level 2 - VS Code Analysis (FXCop) – Default Settings

Level 3 - VS Code Analysis (FXCop) – All Rules

Level 4 – StyleCop – All Rules

Level 5 – SSW Code Auditor – All Rules

?

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouDoCodeAnalysis.aspx

Page 68: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 69: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 70: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 71: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 72: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 73: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you use the best Code Analysis tools?

Level 1 – ReSharper – campsite scout rule

Level 2 - VS Code Analysis (FXCop) – Default Settings

Level 3 - VS Code Analysis (FXCop) – Custom

Level 4 – StyleCop

Level 4 – StyleCop - Custom

Level 5 – SSW Code Auditor

Level 5 – SSW Code Auditor - Custom

TIP: Have a document with rules that you turn off and the reason

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouDoCodeAnalysis.aspx

Page 74: A modern architecturereview–usingcodereviewtools-ver-3.5

ReSharper

Page 75: A modern architecturereview–usingcodereviewtools-ver-3.5

Resharper Custom

Page 76: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Analysis

Run

Options to make a Custom set (Hard UI)

Page 77: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Analysis

Page 78: A modern architecturereview–usingcodereviewtools-ver-3.5

Find the options….

Page 79: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Analysis Custom

Page 80: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Analysis – Suppress #1Add in ‘Suppression File’ or in code?

?

Page 81: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Analysis – Suppress #2

Add in ‘Suppression File’ or in code?

Rule No Good – removed from Rule Set

Rule N/A in this case – in ‘Suppression File’

Rule is Valid – in this case I am overriding it

Page 82: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Analysis – Create work item #1Add as Bug, PBI or Task...

?

Page 83: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Analysis – Create work item #2

Option 1: German (Neno Loje)Select 30 in a PBI

Leave as warning

Option 2: Boy Scout Easy ones (all into 1 PBI) eg. Alt+Enter on

ResharperHard ones (1 per PBI)

Page 84: A modern architecturereview–usingcodereviewtools-ver-3.5

StyleCop

Page 85: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Auditor

Page 86: A modern architecturereview–usingcodereviewtools-ver-3.5

Rules turned off

Page 87: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 88: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you check the code coverage?

See if there are unit tests

See if they are any good (~ 80% coverage)

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouLookForCodeCoverage.aspx

Page 89: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 90: A modern architecturereview–usingcodereviewtools-ver-3.5

Report time?

If you are doing a report, gather some more reports…

E.g. Code Metrics, Code Coverage, Code Clones

But lets assume we are continuing to ‘Probe’… So from: SRP … … Naming Conventions

Page 91: A modern architecturereview–usingcodereviewtools-ver-3.5

Our solution is clean now. What next?

Page 92: A modern architecturereview–usingcodereviewtools-ver-3.5

Agenda

• #1 The 1st things to look out for

• Processes• Does it work?• Documentation

•#2 High Level tools• Architecture• Code Analysis• Code Metrics

•#3 Manual Checking• SOLID Design

Principles• Code Review tools

Page 93: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you run Code Metrics to find dodgy code?

Use the “Hot Spots” feature to quickly identify smelly code

It measures: Maintainability Index Cyclomatic Complexity Depth of Inheritance Class Coupling Lines of Code

Page 94: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 95: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Metrics Results

Page 96: A modern architecturereview–usingcodereviewtools-ver-3.5

Manual Checking:Getting our hands dirty

Page 97: A modern architecturereview–usingcodereviewtools-ver-3.5

Manual Review

After using the automated high level tools it’s time to actually jump into the code

Look for code that doesn’t follow SOLID principles… and then design patterns

Speak to the devs

Page 98: A modern architecturereview–usingcodereviewtools-ver-3.5

SOLID Principles

Single Responsibility Principle

Open Close Principle

Liskov Substitution Principle

Interface Segregation Principle

Dependency Inversion Principle

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouKnowCommonDesignPrinciples.aspx

Page 99: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 100: A modern architecturereview–usingcodereviewtools-ver-3.5

Single Responsibility Principle

A class should have one and only one responsibility

public class Address { // Standard Address Properties public Image GetGoogleMaps() {} public decimal GetDistance(Address destination) {} public bool ValidateAddress() {}}

Page 101: A modern architecturereview–usingcodereviewtools-ver-3.5

Single Responsibility Principle

The Address class has too many responsibilities Showing an image of the address (tied to UI) Calculations based on the address Validation of the address

Another UI may use BingMaps instead of Google Maps

Some, if not all of these functions should be moved to other classes like MapHelper and AddressHelper

Page 102: A modern architecturereview–usingcodereviewtools-ver-3.5

Single Responsibility Principle

public class AddressHelper { public decimal GetDistance(Address start, Address destination) {} public bool ValidateAddress(Address address) {}}

public class GoogleMapProvider : IMapProvider { public Image GetMap(Address start) {}}

public class BingMapProvider : IMapProvider { public Image GetMap(Address start) {}}

Page 103: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 104: A modern architecturereview–usingcodereviewtools-ver-3.5

Open Closed Principle

Open for extension, but closed for modification

Use Abstract base classes that specify some base functionality

E.g. In .NET WebRequest allows you to connect servers via web protocols HttpWebRequest FtpWebRequest FileWebRequest

Page 105: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 106: A modern architecturereview–usingcodereviewtools-ver-3.5

Liskov’s Substitution Principle

Subtypes must be substitutable for their base types

public abstract class Duck { public abstract void Quack();}

Page 107: A modern architecturereview–usingcodereviewtools-ver-3.5

Liskov’s Substitution Principle

public class PekinDuck : Duck { public void Quack() {}}

public class BatteryPoweredDuck : Duck{ public BatteryPoweredDuck(Battery energizer) {} public void Quack() {}}

Can’t swap PekinDuck with BatteryPoweredDuck because you need pass it some batteries first

Page 108: A modern architecturereview–usingcodereviewtools-ver-3.5

Another example

public class Rectangle { protected int _width; protected int _height; public int Width { get { return _width; } public int Height { get { return _height; } public void SetWidth(int width) { _width = width; } public void SetHeight(int height) { _height = height; }}

public class Square : Rectangle { public override void SetWidth(int width) { _width = width; _height = width; } public override void SetHeight(int height) { _width = height; _height = height; }}

Page 109: A modern architecturereview–usingcodereviewtools-ver-3.5

Another Example (cont…)

If we try to use these classes

var shape = new Rectangle();shape.SetWidth(2);shape.SetHeight(5);Console.WriteLine(String.Format(“Area = {0}”, shape.Height * shape.Width))// Prints 10 as expected (2 * 5 = 10)

Page 110: A modern architecturereview–usingcodereviewtools-ver-3.5

Another Example (cont…)

If we try the Square

var shape = new Square();shape.SetWidth(2);shape.SetHeight(5);Console.WriteLine(String.Format(“Area = {0}”, shape.Height * shape.Width))// Prints 25 not as expected since we set the Width = 2 and Height = 5

Page 111: A modern architecturereview–usingcodereviewtools-ver-3.5

Another Example (cont..)

The Square violates the Liskov substitution principle as we don’t get expected behaviour as setting the width will also modify the height and vice versa

Page 112: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 113: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 114: A modern architecturereview–usingcodereviewtools-ver-3.5

Interface Segregation Principle

Don’t create interfaces with lots of methods that don’t necessarily get used in their implementationspublic interface IBird {

public void Chirp(); public void Flap(); public void Fly(); public void Eat();}

public class MockingBird : IBird { public void Chirp() {} public void Flap() {} public void Fly() {} public void Eat() {}}

Page 115: A modern architecturereview–usingcodereviewtools-ver-3.5

Interface Segregation Principle

public class Emu : IBird { public void Chirp() {} public void Flap() {} public void Fly() {} public void Eat() { throw new NotImplementedException(); }}

Page 116: A modern architecturereview–usingcodereviewtools-ver-3.5

Interface Segregation Principle

public interface IBird { public void Chirp(); public void Flap(); public void Eat();}

public interface IFlyingBird : IBird { public void Fly();}

public class Emu : IBird { public void Chirp() {} public void Flap() {} public void Fly() {}}

Page 117: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 118: A modern architecturereview–usingcodereviewtools-ver-3.5

Dependency Inversion PrincipleDepend on abstractions, not on implementations. Anything required to create a valid instance of an object, should have those dependencies passed in as arguments to the constructor

Higher level classes to depend on abstractions of lower level classes (swappable)

public class Employee { public Employee() { FavCoffee = new Cappuccino(); Skills = new List<Skills> { new MSAccessSkill(), new SharePointSkill(), new DotNetNukeSkill() } } }

Page 119: A modern architecturereview–usingcodereviewtools-ver-3.5

Dependency Inversion Principle

public class Employee { public Employee(IDrinkable iamthirsty, IEnumerable<Skills> skills) {} }

Page 120: A modern architecturereview–usingcodereviewtools-ver-3.5

Dependency Inversion Principle

var MarkLiu = new Employee( CoffeeFactory.Get(“Skim Cappuccino”), new List<Skills> { new MSAccessSkill(), new SharePointSkill(), new DotNetNukeSkill() });

var EricPhan = new Employee( CoffeeFactory.Get(“Latte”), new List<Skills> { new BusinessIntelligenceSkill(), new MVC4Skill(), new DotNetSkill() });

Page 121: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you know the common Design Patterns?

?

“Communicate massive amount of data in a few words”

Adam Cogan

“Accepted solutions to well known problems”

Ben Day

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouKnowCommonDesignPatterns.aspx

Page 122: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you know the common Design Patterns?

Inversion of Control

Dependency Injection

Factory

Singleton

Repository

Unit of Work

MVC

MVP

MVVM

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouKnowCommonDesignPatterns.aspx

Abstract factory

Adapter

Bridge

Mediator

Proxy

Flyweight

Chain of responsibility

Command

Memento

Iterator

Visitor

State

Composite

Facade

Observer

Decorator

Null object

Interpreter

Page 123: A modern architecturereview–usingcodereviewtools-ver-3.5

Anti-Patterns

Page 124: A modern architecturereview–usingcodereviewtools-ver-3.5

Abstractness vs Instability Diagram

Shows the assemblies that are painful to maintain

i.e concrete and stable, and which assemblies are potentially useless

i.e abstract and instable

Abstract: The assembly contains many abstract types (i.e interfaces and abstract classes) and few concrete types

Stable: The assembly is considered stable if its types are used by a lot of types of tier assemblies. In this condition stable means painful to modify.

Page 125: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you start reading code? Comments

Q:\ Good or Bad?

Comments are a smell

Includes comments that explain the intent (the why rather than the what)

Page 126: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you start reading code?

Is clear and easy to read

Has consistent and meaningful names for everything

Has no duplicate or redundant code

Has consistent styles and formatting

Explains "why" when you read down, and "how" when you read left to right

http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/DoYouStartReadingCode.aspx

Page 127: A modern architecturereview–usingcodereviewtools-ver-3.5

Do you know Code Reviews after check in are bad?

If you are aiming to get the to nirvana of Continuous Deployment, then you cant *rely* on code reviews after the fact.

Code Reviews have different status:* Important* Nice to have

Page 128: A modern architecturereview–usingcodereviewtools-ver-3.5

The Scenario

Mark is migrating from DotNetNuke to MVC

He’s unsure of his code because he doesn’t know Razor

Add some code with a comment ‘this could be done better’

Checks in anyway

Page 129: A modern architecturereview–usingcodereviewtools-ver-3.5

Use the Code Review tools in TFS 2012

TFS 2012 has built in Code Review tools

Hooks into the check-in/shelving process

This allows code to be manually reviewed before checking in

Page 130: A modern architecturereview–usingcodereviewtools-ver-3.5

Suspend current changes

Page 131: A modern architecturereview–usingcodereviewtools-ver-3.5

Request a Review

Page 132: A modern architecturereview–usingcodereviewtools-ver-3.5

Assign Reviewer

Page 133: A modern architecturereview–usingcodereviewtools-ver-3.5

Reviewer Gets the Request

Page 134: A modern architecturereview–usingcodereviewtools-ver-3.5

Check out the changeset

Related work items

Modified files

Page 135: A modern architecturereview–usingcodereviewtools-ver-3.5

Shows the changed code

Page 136: A modern architecturereview–usingcodereviewtools-ver-3.5
Page 137: A modern architecturereview–usingcodereviewtools-ver-3.5

Side by Side (Standard Diff)

Page 138: A modern architecturereview–usingcodereviewtools-ver-3.5

#1#2

Page 139: A modern architecturereview–usingcodereviewtools-ver-3.5

Finalizing the Code Review

Page 140: A modern architecturereview–usingcodereviewtools-ver-3.5

Check the Code Review

Page 141: A modern architecturereview–usingcodereviewtools-ver-3.5

Check any comments

Page 142: A modern architecturereview–usingcodereviewtools-ver-3.5

View code marked for review

Page 143: A modern architecturereview–usingcodereviewtools-ver-3.5

Mark any flagged code as completed

Page 144: A modern architecturereview–usingcodereviewtools-ver-3.5

Mark the Code Review as Complete

Page 145: A modern architecturereview–usingcodereviewtools-ver-3.5

Code Review Summary

Today: Developer does some work and wants to get it checked before committing to source control

Suggestion to MS: Add a new scenario No touching of code Architect ‘Adds comments’ during code review Automatically adds the developers who originally worked

on that section (instead of manually using annotate) Creates “Code Review” work items

http://www.ssw.com.au/ssw/Standards/BetterSoftwareSuggestions/TeamFoundationServer.aspx

Page 147: A modern architecturereview–usingcodereviewtools-ver-3.5

Summary

• #1 The 1st things to look out for

• Processes• Does it work?• Documentation

•#2 High Level tools

• Architecture• Code Analysis• Code Metrics

•#3 Manual Checking

• SOLID Design Principles• Code Review tools

Page 148: A modern architecturereview–usingcodereviewtools-ver-3.5

Evaluations + 2 things

Include best tip or tool you heard. Plus your tip to me.

@[email protected]

Come and visit us (+ Sydney .NET User Group)

Come and visit Damian Brady, Steven Nagy (+ Brisbane .NET User Group)

Page 149: A modern architecturereview–usingcodereviewtools-ver-3.5

Delivering Awesome Web Applications

Thank You!

Sydney | Melbourne | Brisbane | Adelaide

[email protected]

www.ssw.com.au

Page 150: A modern architecturereview–usingcodereviewtools-ver-3.5

Questions? Take a business card.


Recommended