77
Inside Architecture What I meant to say at dotnetsheff 2016/08/02 Zeb Mason pyright © 2016 by Zeb Mason

Inside architecture

Embed Size (px)

Citation preview

Inside ArchitectureWhat I meant to say at dotnetsheff 2016/08/02

Zeb MasonCopyright © 2016 by Zeb Mason

Agenda: Frivolity, Theory & Tools Copyright © 2016 by Zeb Mason

The Colosseum Copyright © 2016 by Zeb Mason

The ColosseumRomeCopyright © 2016 by Zeb Mason

Roman Architecture? Copyright © 2016 by Zeb Mason

Yes Copyright © 2016 by Zeb Mason

Yes and noCopyright © 2016 by Zeb Mason

Framework Architecture Copyright © 2016 by Zeb Mason

Framework Architecture Why?Copyright © 2016 by Zeb Mason

It’s full of holes! Copyright © 2016 by Zeb Mason

The humble scarab beetle

Copyright © 2016 by Zeb Mason

Ancient Egyptians saw the god Ra rolling the sun around the heavens

Copyright © 2016 by Zeb Mason

But is this how you feel when trying to get to grips with your code?

Copyright © 2016 by Zeb Mason

Note that’s not a big ball of mud

Architects drawArchitecture

in VisioCopyright © 2016 by Zeb Mason

Architects drawArchitecture Marketing

in VisioCopyright © 2016 by Zeb Mason

Architecture Marketing

Copyright © 2016 by Zeb Mason

Markitecture

Copyright © 2016 by Zeb Mason

Markitecture

Copyright © 2016 by Zeb Mason

Markitecture

Box

Copyright © 2016 by Zeb Mason

Markitecture

Boxin a box

Copyright © 2016 by Zeb Mason

Markitecture

Boxin a boxin a box

Copyright © 2016 by Zeb Mason

Markitecture

Boxin a boxin a box to keep

things tidy

Copyright © 2016 by Zeb Mason

Markitecture

Gradient fill implies vague

boundaries?Copyright © 2016 by Zeb Mason

Theory

Leonhard Euler

Copyright © 2016 by Zeb Mason

The Seven Bridges of Königsberg

Copyright © 2016 by Zeb Mason

Graph Theory

Copyright © 2016 by Zeb Mason

Directed graphs

C

B D

A

Copyright © 2016 by Zeb Mason

Structure matrix

C

B D

A

A B C DAB 1C 1 1D

Copyright © 2016 by Zeb Mason

Sorted

C

B D

A

A B D CAB 1DC 1 1

Copyright © 2016 by Zeb Mason

Cycles don’t sort out

C

B D

A

A B D C EAB 1 1DC 1 1E 1

E

Copyright © 2016 by Zeb Mason

Carl Friedrich Gauss

Copyright © 2016 by Zeb Mason

Triangular numbers•Add 1 + 2 + 3 + … + N

Copyright © 2016 by Zeb Mason

Triangular numbers•Add 1 + 2 + 3 + … + N•Add N + N-1 + … + 1

Copyright © 2016 by Zeb Mason

Triangular numbers•Add 1 + 2 + 3 + … + N•Add N + N-1 + … + 1•So N lots of N + 1

Copyright © 2016 by Zeb Mason

Triangular numbers•Add 1 + 2 + 3 + … + N•Add N + N-1 + … + 1•So N lots of N + 1

•Sum is

Copyright © 2016 by Zeb Mason

Triangular numbers•Add 1 + 2 + 3 + … + N•Add N + N-1 + … + 1•So N lots of N + 1

•Sum is •Schoolboy maths!

Copyright © 2016 by Zeb Mason

Edges in a graph•Undirected graph•N nodes•+1 node => +N edges• i.e. triangular number •Max /2 edges

•Directed graph•Double the sum•Max edges

Copyright © 2016 by Zeb Mason

Edges in a graph•Undirected graph•N nodes•+1 node => +N edges• i.e. triangular number •Max /2 edges

•Directed graph•Double the sum•Max edges

Copyright © 2016 by Zeb Mason

Edges in a graph•Undirected graph•N nodes•+1 node => +N edges• i.e. triangular number •Max /2 edges

•Directed graph•Double the sum•Max edges

Copyright © 2016 by Zeb Mason

MetricsCyclomatic number:

E + P – N Cyclomatic complexity:

E + 2P – Nwhere

E is the number of edgesP is the number of parts

Copyright © 2016 by Zeb Mason

Metric invarianceCyclomatic number:

E + P – N = 2 + 1 – 3= 0

Copyright © 2016 by Zeb Mason

Metric invarianceCyclomatic number:

E + P – N = 2 + 2 – 4= 0

Copyright © 2016 by Zeb Mason

Metric invarianceCyclomatic number:

E + P – N = 3 + 1 – 4= 0

Copyright © 2016 by Zeb Mason

Metric invarianceCyclomatic number:

E + P – N = 2 + 1 – 3+ 1 + 1 – 2 = 0

Copyright © 2016 by Zeb Mason

Spot the difference

3 layer architecture

3 tier architecture

A

B

C

A

B

C

Copyright © 2016 by Zeb Mason

Spot the difference

3 layer architecture

3 tier architecture

A

B

C

A

B

C

using B

Copyright © 2016 by Zeb Mason

Spot the difference

3 layer architecture

3 tier architecture

A

B

C

A

B

C

using C

using B

Copyright © 2016 by Zeb Mason

Spot the difference

3 layer architecture

3 tier architecture

A

B

C

A

B

C

address of B

using C

using B

Copyright © 2016 by Zeb Mason

Spot the difference

3 layer architecture

3 tier architecture

A

B

C

A

B

C

address of B

address of Cusing C

using B

Copyright © 2016 by Zeb Mason

Find architecture patterns in code• Dependency analysis• e.g. Layered architecture

• Heap analysis• e.g. Tiered architecture

• Change in heap• e.g.

Copyright © 2016 by Zeb Mason

Find design patterns in code• Dependency analysis• e.g. Factory method

• Heap analysis• e.g.

• Change in heap• e.g.

Copyright © 2016 by Zeb Mason

Find design patterns in code• Dependency analysis• e.g. Factory method

• Heap analysis• e.g. Composite

• Change in heap• e.g.

Copyright © 2016 by Zeb Mason

Find design patterns in code• Dependency analysis• e.g. Factory method

• Heap analysis• e.g. Composite

• Change in heap• e.g. State machine

Copyright © 2016 by Zeb Mason

Tools•Ndepend•Lattix•structure101•Visual Studio•DeepEnds•NsDepCop

Copyright © 2016 by Zeb Mason

Tools•NDepend•Lattix•structure101•Visual Studio•DeepEnds•NsDepCop

Copyright © 2016 by Zeb Mason

Visual Studio 2015

$2999 p.a.

Copyright © 2016 by Zeb Mason

Visual Studio 2015

$2999 p.a.

Copyright © 2016 by Zeb Mason

Visual Studio 2015

$2999 p.a.

•Create digraphs in Enterprise•Save as a DGML file•Open in Community or Professional

Copyright © 2016 by Zeb Mason

Tools•NDepend•Lattix•structure101•Visual Studio•DeepEnds•NsDepCop

Copyright © 2016 by Zeb Mason

Tools•NDepend•Lattix•structure101•Visual Studio•DeepEnds•NsDepCop

• Visual Studio extension• Listed on Visual Studio gallery

• Input• csproj files

• parsed by Roslyn• .NET assemblies

• decompiled by Mono.Cecil• vcxproj.filter files

• Output• DGML file

• Structured by namespace or filter• Nodes hyperlink to source code files

• HTML report• Cyclomatic number• Underlying dependencies

Copyright © 2016 by Zeb Mason

Tools•NDepend•Lattix•structure101•Visual Studio•DeepEnds•NsDepCop

• Visual Studio extension• Listed on Visual Studio gallery

• Input• csproj files

• parsed by Roslyn• .NET assemblies

• decompiled by Mono.Cecil• vcxproj.filter files

• Output• DGML file

• Structured by namespace or filter• Nodes hyperlink to source code files

• HTML report• Cyclomatic number• Underlying dependencies

Copyright © 2016 by Zeb Mason

Tools•NDepend•Lattix•structure101•Visual Studio•DeepEnds•NsDepCop

• Visual Studio extension• Listed on Visual Studio gallery

• Input• csproj files

• parsed by Roslyn• .NET assemblies

• decompiled by Mono.Cecil• vcxproj.filter files

• Output• DGML file

• Structured by namespace or filter• Nodes hyperlink to source code files

• HTML report• Cyclomatic number• Underlying dependencies

Copyright © 2016 by Zeb Mason

A DGML file - inside Mono.Cecil

Copyright © 2016 by Zeb Mason

Expand Mono.CompilerServices

Copyright © 2016 by Zeb Mason

Expand Mono.CompilerServices.SymbolWrite

r

Copyright © 2016 by Zeb Mason

A cycle is spotted

Copyright © 2016 by Zeb Mason

Why the cycle?

Copyright © 2016 by Zeb Mason

Concrete class inherits interfacenamespace Mono.CompilerServices.SymbolWriter{

public class CompileUnitEntry : ICompileUnit{}

}

Copyright © 2016 by Zeb Mason

Interface returns concrete class!namespace Mono.CompilerServices.SymbolWriter{

public class CompileUnitEntry : ICompileUnit{}

public interface ICompileUnit{

CompileUnitEntry Entry {get;

}}

}

Copyright © 2016 by Zeb Mason

Underlying dependencies

Copyright © 2016 by Zeb Mason

Summary of metrics

Copyright © 2016 by Zeb Mason

The effect of time and refactoring

Copyright © 2016 by Zeb Mason

Tools•NDepend•Lattix•structure101•Visual Studio•DeepEnds•NsDepCop

Copyright © 2016 by Zeb Mason

NsDepCop• Some dependency analysis tools enforce design intent by rules• i.e. one component cannot depend on another• e.g. NsDepCop rules on namespace dependencies

• These rules can be run automatically• e.g. NsDepCop is run by MSBuild• Rule violations can be acted upon

Copyright © 2016 by Zeb Mason