Yesterday, I was privileged to attend the 3rd annual Chicago Code Camp. It was a great opportunity to sit under some very bright professionals and soak in some knowledge, and I’m very thankful to the organizers and sponsors for putting a ton of time, effort, and money into a free community event. I’m cataloguing some of the highlights from the sessions I sat in on.
Test-Driven Development – Tips, Tools & Techniques – Keith Burnell
TDD is one of those things I know I should be doing, but every time I start I find myself hitting this wall of fake objects and can’t help feeling like I’ve made up a bunch of stuff and haven’t actually done anything real or worthwhile. I like opportunities like this to hear other’s successes and tutelage. Here’s a few takeaways:
- Use a ReSharper template to create an Arrange…Act…Assert for unit tests
- There should be no external dependencies tested. Disconnect the network cable, detach the DB.
- A Dependency Injection framework would be really helpful in mocking out those external dependencies as it makes it easy to globally swap instances of an interface in the unit test project.
- Should Assertion Library – A tool that makes Assert statements a bit more readable by via extension methods.
- The ReSharper Test Runner is over 3x faster than the built-in Visual Studio runner.
- When writing integration tests, use the TransactionScope to populate data for the test and then roll it back.
Thanks Keith for a copy of Roy Osherove’s The Art of Unit Testing!
Continuous Learning – Marc Temkin
As someone who loves to learn, I was very excited about this session. I consider myself strong in this category and was looking for some great method to absorb content faster and better. It came up quite a bit short of expectations as much of it was pretty elementary. There were a couple things I took away though:
- Marc talked about evaluating books by looking at the table of contents, the index and one random page. This helps us get a good sampling of what its about instead of focusing too narrowly and sinking time into reading excerpts we find interesting, and missing what it’s all about.
- This session really helped shape my decisions for the sessions I would visit the rest of the day. I decided to use this day to take opportunities I don’t normally otherwise get and to learn about things I’m interested in, but haven’t dug too deeply.
Code Generation with T4 and Visual Studio – Oleg Sych
This was one of those opportunities I don’t normally get. When I looked into T4 over a year ago, Oleg’s articles kept coming up over and over.
Code Generation Specific Tips
- Couple tools: the T4 Editor from Tangible Engineering and the T4 Toolbox which is on codeplex.
- When writing a template, start by hard-coding the template with specific values, then refactor to using the metadata from your data source.
- For SQL, include the assembly Microsoft.SqlServer.Smo and the namespace Microsoft.SqlServer.Management.Smo.
- Must be sure to call the Refresh() method in the Smo API or it won’t populate the tables by default.
- PushIndent(“\t”) and PopIndent() can be used to address formatting the template
- The @ include directive allows you to include some other template inside another template.
- A cool trick when sharing templates across teams is to convert a template (say, your Delete stored procedures template) to a helper method, using the <#+…#> syntax. That way, the functions can be stored in source control and each of the teams can than use those functions via include directives to generate the specifics that they need.
- T4 runs in the devenv.exe process, so in order to debug it, it is necessary to use a second instance of Visual Studio.
General Tips
- Use the Debug –> Exceptions menu in Visual Studio to set the option to always break on CLR exceptions when debugging. This will ensure that the code breaks whenever an exceptions is encountered, even if it is caught and handled in the code.
- Database Projects are really powerful. You maintain your Create scripts in the project and when you Deploy, it compares your script against the database you’re deploying to and generates and runs the Alter script for what has changed.
Messaging with nServiceBus – Lee Harold
nServiceBus was something I pretty much knew nothing about.
- Definition of distributed – “Some other system can make yours stop working”
- nServiceBus isn’t like an ESB with a central server. It is more like a queue helper.
- It uses a Pub/Sub model where subscribers register their queues with a publisher.
- It uses MSMQ by default, but there are adapters that support other queue implementations as well.
- It serializes to XML by default, but it can serialize to a binary format as well
- It has a Distributor which can be used to scale to multiple machines. This is on the subscriber end, and is a master/slave model. The master distributor pretty much only handles routing requests to its slaves.
High Performance 2D Graphics in Silverlight – Bill Reiss
I picked this session because there really wasn’t anything else I was interested in. This turned into one of the best sessions of the day. Bill is a Silverlight MVP and a former XNA MVP, so he has a ton of knowledge in this space, and it was very practical.
- Drop Shadow effects are really poor for performance as they force redraws
- In the <object> tag in the web page hosting the Silverlight control, there are several params that can aid in debugging:
- enableRedrawRegions – Shows all the areas of the screen that are being redrawn. Does not work well with GPU acceleration.
- enableFrameRateCounter – Shows the FPS
- enableGpuAcceleration – By default, Silverlight relies only on the CPU. This will engage the GPU.
- enableCacheVisualization – Show all the items on the page that have been cached
- Use the CacheMode=”BitmapCache” to cache graphics and prevent them from being redrawn constantly. Requires GPU acceleration.
- Property setters should be wrapped so that they are only set if the new value is different. This prevents IPropertyNotified events from triggering.
- Also, don’t access dependent properties directly in your properties. For example, don’t just wrap, myTextBox.Text, actually use backing variables as it’s better performance.
- Text in a ListBox control is vector based, so may want to consider bitmap caching the text instead for better performance. (WP7 built in some of these optimizations)
- There is overhead when adding or removing elements to/from the visual tree. One trick is to load them all up, but use visibility or opacity to show or hide them.
- A big part of performance is minimizing redrawing.
- VS2010 SP1 includes a Silverlight Profiler. Red-Gate ANTS also is a good Silverlight profiler.
Links
- http://silversprite.codeplex.com/ – This is a project Bill created to run XNA games in Silverlight 3.
- http://frolic.codeplex.com – This is another framework Bill is working on for building games easier.
No comments:
Post a Comment