Mar 20 2012

Should code contracts be tested?

Category: .Net | Software DesignRory Primrose @ 16:26
I have been writing unit tests for my classes that use code contracts (Contract.Requires<T>) just like I did with the old style guard clauses basically since code contracts were released. My reasoning for testing them has always been that the unit test code should not make any assumptions about the implementation of the SUT and ideally should have no understanding about how it is implemented. Instead it should just test the behaviour. If a method that takes a reference type as a paramete... [More]

Tags:

Feb 16 2012

Quick Poll–UX of UI navigation for list with a single item

Category: Software DesignRory Primrose @ 17:31
I’m after some feedback from the community regarding the UX of UI navigation when dealing with a list of items where there is only one item in the list. I have a scenario in a UI where there is a list of subscriptions for a user account. Most of the time (~>90%) there will only be one subscription. There are two options for handling this. Always display the list when the user navigates to the list UI and force the user to manually select the only item available Automatically redirect... [More]

Tags:

Jan 29 2012

How much do I love the yield statement?

Category: .Net | Software DesignRory Primrose @ 17:15
Quite simply, a lot. The yield statement seems to be such a simple part of C# yet it can provide such amazing power (being delayed enumeration). Outside of that power however, it can provide beautiful simplicity. Take the following abstract class for example: namespace MyApplication.Diagnostics { using System; using System.Collections.Generic; public abstract class DiagnosticTask { public abstract IEnumerable<DiagnosticTaskResult> ExecuteAll(); ... [More]

Tags:

Oct 25 2011

Designing Action and TryAction members

Category: Software Design | .NetRory Primrose @ 08:13
I have a pet peeve with how Action and TryAction style members are often implemented. Too often I see the following style of implementation. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; public class SomeClass { public Stream GetSomething(String referenceData) { if (String.IsNullOrWhiteSpace(referenceData)) { throw new InvalidOperationException(); } return new MemoryStre... [More]

Tags:

Jun 15 2010

Law Of Instance Ownership

Category: Software Design | .NetRory Primrose @ 05:41
I’ve been writing a custom Unity extension for disposing build trees when a container is asked to tear down an instance. This has brought up some interesting ideas about the conditions in which an instance should be destroyed. This has lead to me come up with the Law of Instance Ownership. Law of Instance Ownership An instance is owned by the highest stack frame that holds a direct reference to an instance, or the application domain for globally held instances. A common misconception is... [More]

Tags:

Feb 17 2010

Recommended reading for developers

I was reminded this morning of an email that I sent to the junior developers on my team when they joined us. It is an overview of some of the development practices, patterns and products that they would get exposed to on our project. I have included it here as a reference collection for others. Principles and Patterns These are things that I often use and are still learning to use. SOLID – Originally put together by Bob Martin (http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod). A g... [More]

Tags: , , , , , , , ,

Mar 11 2009

Lightning fast Australian broadband

Category: .Net | IT Related | Software DesignRory Primrose @ 19:45
I've been on ADSL2+ for a few years now. Having a possible maximum speed of 24Gb is nice, but the actual floats between 5-7Gb being 3.5km from the exchange. That's not great, but is fast enough for general net usage. Tonight however, surfing the net has been slow. Really really slow. So slow in fact, that www.speedtest.net tells me this. In the test before this one, the upload speed was actually a tad faster than the download speed. Did someone say broadband??? Yep, I&... [More]

Tags:

Nov 24 2008

Class vs Struct

Category: .Net | Software DesignRory Primrose @ 08:09
There is a lot of information around that discusses the differences between classes and structs. Unfortunately there isn't a lot of information available about when to use one over the other. MSDN has a good resource which provides guidance on how to choose between classes and structs. It starts by describing the differences between the two and then provides the following advice. Consider defining a structure instead of a class if instances of the type are small and common... [More]

Tags:

Oct 8 2008

WCF service contract design article

Category: .Net | Software DesignRory Primrose @ 18:26
I had a conversation yesterday regarding WCF service contract design with my tech lead at work. Funnily enough, I then got a comment on an old post that afternoon from Ciaran O'Neill which is really about the same topic. I thought that I should write up my thoughts on the subject. See here for the article.

Tags:

Oct 8 2008

Cache expiration policies article

Category: .Net | IT Related | Software DesignRory Primrose @ 08:11
I was asked recently about caching expiration policies in response to my rant in my Caching should not be the source of truth post and a comment I made in a post by Chris Blankenship. I have written an article about cache expiration policies which you can find here. It discusses the high level concepts in expiration polices and some suggestions about which options to pick. It makes references to HttpRuntime.Cache and the Caching Application Block in Enterprise Library.

Tags: