Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

36
Rules to Healthier Code Presented by Adam Cogan (Chief Architect for www.ssw.com.au )

Transcript of Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Page 1: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Rules to Healthier Code

Presented by Adam Cogan (Chief Architect for www.ssw.com.au)

Page 2: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

About

• Chief Architect for www.ssw.com.au doing:

– internal corporate development and

– generic off-the-shelf databases

– Clients: Royal & Sun Alliance, Westbus, Microsoft…

• President .NET User Group, Sydney

• Speaker for Microsoft TechEd and Roadshows, Dev Conn, VSLive….

• Microsoft Regional Director, Australia …

[email protected]

Page 3: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Agenda

• Unit Testing– NUnit– Test Driven– Other Unit Tests

• Code Analysis– Microsoft FxCop– SSW Code Auditor

• Code Profiling– JetBrains dotTrace Profiler

• Build Server– Cruise Control

• The Future– Other Tools– Visual Studio Team System

Page 4: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

What is Healthy code?

What is Healthy Code anyway?

Why is it Important?

What about Documentation?Is your spec in bite-sized pieces?Does your spec have the 3 important things?

Page 5: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

NUnit

www.nunit.org

How many unit tests do you write…?

Page 6: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

When do you write Unit Tests?

100% unit tests is 100% impractical

Unit tests should be written for:– Dependencies – e.g. DLLs Run time errors (JIT)– Dependencies – e.g. Database Schema, Datasets, Web Services– Fragile Code – e.g. Regular Expressions– When errors can be difficult to spot – e.g. Rounding, arithmetic,

calculations– Performance – e.g. Slow forms

• Don’t:– When the unit tests are bigger than the original (Insert)– Generated Code like Insert, Update, Delete

Rules to Better Unit Testing

http://www.ssw.com.au/ssw/standards/Rules/RulesToBetterUnitTests.aspx

Page 7: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Do you have ‘Run Unit Tests’ on your Help Menu?

• http://www.ssw.com.au/ssw/Rules/RulesToBetterUnitTests.aspx#MenuUnitTests

• A user should be able to run unit tests through an application.

• This aids the developers quickly identify any problems with the application by running the unit tests.

Page 8: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Test Driven .NET

• Do you run Unit Tests with the right click of your mouse?• Run unit tests from your right click menu

http://www.testdriven.net/

Page 9: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

What about other things?

• Access Unit Tests– SSW Performance PRO (www.ssw.com.au/

ssw/PerformancePRO)– FMS Total Access Analyzer (http://

www.fmsinc.com/Products/analyzer/)• SQL Reporting Services Unit Tests

– SSW Report Validator• Performance Unit Tests

– MBUnit (http://mbunit.tigris.org)• Javascript Unit Tests

– JsUnit (http://www.edwardh.com/jsunit/)• www.edwardh.com/jsunit/runner/tests/jsUnitTestFailures.html

• And The Backend?

Page 10: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

SSW Performance Pro

Page 11: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

SSW Report Validator

Page 12: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

MBUnit

Page 13: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

JsUnit

Page 14: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

FxCop

What is FxCop?Code analysis tool

• for .NET managed code assemblies

Checks:• Library design• Naming conventions• Performance• Security

Don’t:• Globalization

http://www.gotdotnet.com/team/fxcop/

Page 15: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

SSW Code Auditor

What is Code Auditor?1. Maintains coding

standards2. Checks C# and VB.NET

code3. Prevents bad coding

practices4. Integration into Visual

Studio

www.ssw.com.au/ssw/CodeAuditor

Page 16: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

SSW Code Auditor

• Extensive rule set that is customizable– http://www.ssw.com.au/

ssw/CodeAuditor/default.aspx#Rules

Page 17: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

SSW Code Auditor

• Produces an XML Report

Page 18: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

JetBrains dotTrace Profiler

• Measures the performance of ASP.NET or Windows Form Application

• Quickly identify bottle necks through Hot Spots

http://www.jetbrains.com/profiler/

Page 19: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Test Driven Process

Q: What is VSS?A: It is not a file share

• Check Out• Compile• Run Unit Tests• If it is OK then Start

• Develop… Develop… Develop…

• Run Unit Tests• If OK Check In• Get Latest• Run Unit Tests Again to confirm

• http://www.ssw.com.au/SSW/Standards/Rules/RulesToBetterUnitTests.aspx#TestDrivenProcess

• Want to poison the system – I smell a rat

Page 20: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Cruise Control

What is Cruise Control?– Automated Continuous Integration server– Integration with a variety of Source Control

systems – Integration with other external tools, such as

NAnt and Visual Studio – Can build multiple projects on one server – Remote management and reporting – There is always one

http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET

Page 21: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Cruise Control

Features:– Web Portal for

build info– Tray icon

notification

Page 22: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Visual Studio Team System

Key Features:– Integration of:

• Unit Testing– Code Coverage

• Source Control• Code Analysis (FxCop)• Code Profiling

http://lab.msdn.microsoft.com/teamsystem/

Page 23: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Overview

TeamTeamCommunicationCommunication

QualityQualityEarly & OftenEarly & Often

PlatformPlatformFor InnovationFor Innovation

Design forDesign forOperationsOperations

ProjectProjectManagerManager

SolutionSolutionArchitectArchitect

DeveloperDeveloperTesterTester

InfrastructureInfrastructureArchitectArchitect

Page 24: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Visual Studio Team System

• Integrated Unit Testing

• Code coverage– See what code has been executed

• Static code analysis– FxCop in the task list

• Code profiling– Based on two internal profilers:

• Sampling (Light weight)• Instrumented (Heavy duty)

– Sequence view examines running threads– Caller-callee, callstack, and function views (there today)

• Why was it built? To avoid the cat problem

Page 25: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Integrated Unit Testing

Integrated Unit TestingIntegrated Unit Testing

Page 26: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Code CoverageCode Coverage

Page 27: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Static Code AnalyzerStatic Code Analyzer

Page 28: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Code ProfilingCode Profiling

Page 29: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Perf Counter integrationand monitoring

Perf Counter integrationand monitoring

Load TestingLoad Testing

Page 30: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Integrated Reporting

Page 31: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Integrated Build Server

Page 32: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Conclusion

• To achieve healthy code:– Unit Testing - NUnit– Code Analysis – FxCop and SSW Code Auditor– Build Server – Cruise Control .NET– Visual Studio Team System (everything is integrated)

• The resources don’t hurt either!– http://www.ssw.com.au/ssw/Standards/

DeveloperGeneral/netTools.aspx

Page 33: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

Resources

• SSW .NET Toolkithttp://www.ssw.com.au/ssw/NetToolkit/

• SSW Code Auditorhttp://www.ssw.com.au/ssw/CodeAuditor/

• SSW Performance PRO

http://www.ssw.com.au/ssw/PerformancePro/• FMS Total Access Analyzer

http://www.fmsinc.com/products/analyzer/ • NUnit

http://www.nunit.org• MBUnit

http://mbunit.tigris.org • Test Driven

http://www.testdriven.net/

Page 35: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).

2 things

[email protected]

Page 36: Rules to Healthier Code Presented by Adam Cogan (Chief Architect for ).