This document discusses best practices for writing high quality Visual Studio extensions, including:
- Writing testable, stable, performant, and memory efficient extensions through techniques like test-driven development, behavior-driven development, integration testing, and avoiding memory leaks.
- Key tips around debugging extensions effectively through applying the scientific method and writing tests at different levels of abstraction.
- How to deal with crashes, avoid poor performance, and prevent memory leaks and garbage collection pressure issues in extensions.
The document provides code examples and links to demonstration projects on these topics.
2. 2
@omerraviv on Twitter (twitter picture)
@omerraviv on Gitter.im/extendvs (Gitter logo)
Omer Raviv
Creator and CTO of OzCode
Senior Consultant @ CodeValue
.NET open-source enthusiast
Passionate about dev productivity
@omerraviv on Twitter
@omerraviv on Gitter (gitter.im/extendvs)
5. The two most common ways to use a debugger:
1. Wasting time
2. Quality time
6. Wasting time:
Not knowing what your hypothesis is at any given time
Getting into a rot mindlessly hitting F10
Quality time:
Apply the Scientific Method, religiously
Simplify the scenario, then write a test!
The Debugging Process Overview
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
13. Synthesis and refinement of practices stemming from TDD & ATDD
User story:
"As a [role] I want [feature] so that [benefit]
Acceptance Criteria
Given [initial context]
When [event occurs]
Then [ensure some outcome]
Whats this BDD thing?
15. Use natural language to express intentions (GivenWhenThen)
Use a general purpose programming language
to express test mechanics
Use a tool that will let you operate in either domain seamlessly
BDD offers a solution
21. Having flakey tests is a lot worse than having no tests at all.
A flakey test is like a virus
quarantine it, then triage.
Visual Studio Integration Tests Pro-Tip
24. The ActivityLog.xml
MessageBox
of pain and suffering github.com/oz-code/OzCode.VisualStudioExtensionAnalyzers
PM> Install-Package OzCode.VisualStudioExtensionAnalyzers
25. Use an Exception Monitoring Tool
Use an Exception Monitoring Tool
30. Visual Studio 2017 will warn users about extensions that are slowing things down.
Performance as a Feature
31. 1. Delay loading your extension as much as possible (using UIContextRule)
2. When you do load, load in the background. (using AsyncPackage)
Performance as a Feature
35. Memory Leaks vs. GC Pressure
Pro-Tip: Dont Close your Diagnostics Tools Window!
36. Dealing with GC Pressure
Memory Leaks vs. GC Pressure
Always be measuring (allocations, % time spent in GC)
Watch out for duplicate strings
Use object pooling / a string intern pool
Use Roslyn Heap Allocation Analyzer
39. Which means
a business sponsor could request that the current
development version of the software can be deployed
into production at a moment's notice - and nobody
would bat an eyelid, let alone panic.
Got good Subcutaneous Tests?
Start practicing True Continuous Delivery!
Martin Fowler