One of the key factors for success as a software developer is to work smarter, not harder. These posts contain tips on how you can do just that.

The Liskov substitution principle goes both ways

Saturday, March 21 2020 smart-code

The Liskov Substitution Principle (or LSP) is one of the big five SOLID principles and one that is often poorly understood. Yet, ignorance of the LSP can lead to subtle, expensive, and sometimes embarrassing bugs.

Read more »

Avoid hardcoded wait times

Saturday, May 26 2018 smart-code

When developing systems that must wait for key things to happen (often, things that are outside their direct control), we need to consider how long we’re willing to wait for an answer.

Read more »

Guaranteed Progression

Saturday, May 19 2018 smart-code

Long ago, before storing things in the cloud was commonplace or economic, I used an online mirroring tool to replicate all our family photos between my desktop PC and my wife’s netbook. This was both effective and painful - here’s why.

Read more »

Prefer declarative method names

Saturday, February 03 2018 smart-code

Coming up with the right name for a method can be a challenge even if you’re sure you know exactly what it should do. All too often, I find that part of the reason why I’m having trouble choosing a name is that I haven’t really decided the purpose of the method.

Read more »

Using Premeditation

Saturday, January 27 2018 utility-class smart-code

If you have a utility class in your current code base, there’s something very important you should do - even before you apply any of the techniques we’ve discussed previously.

Read more »

With Relocation

Saturday, January 20 2018 utility-class smart-code

Sometimes you’ll find a method on your utility class that’s only used once - or only from a single consuming class. This frequently happens when a developer genuinely believes the method will be generally useful and should be available for reuse, but is wrong.

Read more »

Using Consolidation

Saturday, January 13 2018 utility-class smart-code

Sometimes your utility class will contain methods that smell strongly of feature envy, prompting you to relocate them onto an existing class. This is a much simpler cleanup than introducing a semantic type.

Read more »

Using Semantic Types

Saturday, January 06 2018 utility-class smart-code

Following on from our discussion on extension methods, another technique you can use when eliminating the dumping ground of your utility class is the extraction of buried semantic types. This is possible when you find a set of closely related methods with linked semantics.

Read more »

Using Extension Methods

Saturday, December 30 2017 utility-class smart-code

Think about the larger projects you’ve worked on during your career. Did you have a dumping ground for odd pieces of functionality? Perhaps a utility class or even multiple multiple utility classes? It’s a very common thing to see a utility class in any codebase of reasonable size, especially one that has been around for a while.

Read more »

Error Methods

Saturday, November 25 2017 smart-code

Make the exceptions thrown by your methods more informative and useful by including more information with each exception. Do this by delegating the creation of exceptions instances to helper methods that focus on one task.

Read more »

Pass implementations, not representations

Saturday, October 14 2017 smart-code

A friend/colleague of mine, George, made an interesting assertion - that he prefers passing implementations, not representations. As we talked and unpacked what he meant by this, I discovered a deceptively simple idea that can make our code significantly more flexible and adaptable.

Read more »

Avoiding the Singleton Pattern

Saturday, July 22 2017 smart-code

Last time, we discussed the singleton pattern and looked how it can be easily implemented in a correct way by leveraging the Lazy<T> class. Now let’s look at why you almost certainly don’t want to do this.

Read more »

Older posts

Implementing the Singleton Pattern  15 Jul 2017
Static Analysis tools for the Win  15 Apr 2017
Exception Logging  19 Jan 2016
On the Merits of Simple Code  28 Nov 2015
Semantic Types  27 Sep 2015
Command Line Processing  21 Sep 2014
Easy String Conversion  24 Aug 2014
Simpler code with DirectoryInfo  13 May 2014
So you should never catch Exception ...  21 Feb 2013
The Trap of Discarding information  13 Jun 2012
Improving Method Signatures  10 Mar 2012
NUnit to the Rescue  01 Dec 2011
Avoiding Null Checks  13 Sep 2010
Avoiding Stack Overflow with Params  24 Jun 2010
Extension methods for XElement  08 Jun 2010
Spoken Numbers  15 Apr 2010
Catching 'Exception' is Bad. Isn't It?  04 Mar 2010
Evil ToString()  23 Feb 2010
Improving on POCO Associations  21 Jan 2010
Dude, you're working too hard  20 Jan 2010
Range Properties  14 Jan 2010
Still working too hard  05 Oct 2009
Performance of Dynamic  12 Jul 2009
Scoped Values  18 Jun 2009
Working smarter with XElement  07 Apr 2009
Easier Enums  04 Mar 2009
Validation and Domain Driven Design  27 Feb 2009
Using Lambdas as Event Handlers  09 Feb 2009
Finding Configuration Files  23 Nov 2008
Linq Aggregates  30 Oct 2008
Extension Methods and Null Pointers  13 Jul 2008
Conditional Compilation  09 Apr 2008
Safe coding and IDisposable  02 Jul 2006
Semantic Types for Events  02 Mar 2025
Ideas to blog  02 Mar 2025
How could this code go wrong?  02 Mar 2025
Consistency is a two edged sword  02 Mar 2025