Programming Practices

Legacy Projects, Technical Debt and NDepend

Legacy systems are commonplace, but it's difficult to come up with anything concrete to justify the expense of an update to someone with an eye on their bottom line. Thankfully, the folks at NDepend have now built technical debt computation on top of their code analysis tools, giving you a much easier way to have these sorts of discussions. Here's a real-world example.

Mapper vs Mapper: The Performance Plot Thickens

The last mapper performance blog (for a while, at least), including updated versions of AgileMapper, AutoMapper and Mapster, and discussion of some performance nuances.

Mapper vs Mapper: Performance Revisited

I recently wrote a blog on the performance of various object-object mappers, but it turns out my tests weren't quite fair and equal at that point. Having updated the relevant mapper classes and re-measured, here are my results.

.NET Standard and Testing Partially Trusted Code

Because libraries written for .NET Standard can run on multiple platforms – with more to come in the future – it's worth considering how or if they run in partially trusted environments. Having implemented support in both ReadableExpressions and AgileMapper - here's pointers on how.

Mapper vs Mapper: Performance

The first in a series of posts comparing a subset of the available mappers. This blog is on that favourite thing we're not supposed to obsess too much about (in programming) - performance. This blog now lives here.

AgileMapper: a zero-configuration, highly configurable, transparent, id-aware object mapper

Regular readers of my blog (maybe even both of you) will have seen sporadic references to ‘my pet mapper project’. It’s now – finally! – in a beta stage I’m happy to talk about.

Interview Trivia Questions

There is a style of technical interview question which I think is more or less pointless. Here's some examples, with what I think is a question worth asking instead.

ReadableExpressions Debugger Visualizers now in the Visual Studio Gallery

Bowing to vast, popular demand (one comment), I've now put an installer for the ReadableExpressions Debugger Visualizers on the Visual Studio Gallery.

ASP.NET Core and MVC 6 Lessons Learned

I recently finished a small website using ASP.NET Core and MVC 6 - I only scratched the surface of the framework, but here's some gotchas and things I picked up along the way.

Finding a Balance: Code 'Complexity'

On any project, there's a tension between writing code everyone finds easily accessible, and using more [relatively] modern techniques which make code more terse and expressive. Here's some thoughts on addressing that tension.

Extending WatiN 2: Wait for JQuery document.ready() Functions to Complete

WatiN's DomContainer.WaitForComplete() method pauses test execution until the DOM has finished loading, but if your page has functions registered with JQuery's ready() function, you'll probably want to wait for those to finish executing before testing it. Here's a WatiN extension method which pauses test execution until that happens.

No More NCrunch For Me

NCrunch is a Visual Studio add-in which runs your tests while you work so you know if you've broken anything, as well as providing coverage indicators in the IDE and coverage metrics on demand. It recently went commercial, and time is running out for the free version I've been using for the last couple of months. From my experiences using NCrunch I'm going to let it expire, and go about my business without it. Here's why.

Spotting a Missing Object

There are various tell-tale signs when a system is missing an object, and I spotted some of them recently while writing the ReadableExpressions library. Here's how.

Death of a Scrum Room

A friend of mine works at a company where the scrum process is gradually being phased out. Why is it happening, and what are the consequences?

NDepend on a Real Project (Again): My Critical Errors

Following on from my look at the non-critical errors NDepend 6 told me about on my project, here's a look at the more serious stuff - the critical errors.

NDepend on a Real Project (Again): My Non-Critical Errors

Following on from last time, here's a look at some of the non-critical errors NDepend 6 told me about on my project.

NDepend on a Real Project (Again): Version 6's New Stuff

There's a new version of NDepend out in the wild, so I thought I'd give it a whirl on my pet object-object mapper project. Here's a quick overview of some of the new features.

Naming Things Is Hard: Using Object Pattern Names

Design Patterns - tried-and-true solutions to common problems - have now been around long enough that many of them have very familiar names. We can use those names as part of an object-naming strategy.

Node.js and TypeScript Modules: Internal, External... Shake it All About

When I decided to write a JavaScript game, I knew I'd need to run the same logic on the server and the browser, so Node.js was an obvious choice. It's JavaScript on the server, right? Anything I write to run in a browser will be runnable on the server as well. Easy! Well… not so much. Here's the misunderstandings and problems I faced, along with my solution.

Dependency Injection, Angular and Node

My current pet project uses Node, Angular and TypeScript. This is my first time working with Node or Angular and the differences in the way they approach Dependency Injection led to this post.

Naming Things is Hard: Keeping Context in Mind

Nothing that you name in coding exists in a vacuum. It will all be used and referenced in a certain way, and this should inform the names you choose. Here's some examples.

Naming Things is Hard: Method-Naming Patterns

Some of the method-naming patterns I've come across / developed / adopted.

Naming Things is Hard: Dictionaries

I've been working with a codebase recently which makes a lot of use of dictionaries - here's a few words about naming them.

Naming Things is Hard: Finding the Right Level of Abstraction

It is said and experience has confirmed - in programming, naming things is hard. So hard it's common for programmers with years and years (and years) of experience to regularly name things poorly. Here's some of the processes I use to name variables and types, focusing on finding the right level of abstraction.

NDepend on a Real Project, Round 1.4: Mutually Dependent Namespaces

This is the fourth in a series of blogs looking at things NDepend told me about a personal project of mine - this time mutually-dependent namespaces.

NDepend on a Real Project, Round 1.3: An Exception by Any Other Name...

This is the third in a series of blogs looking at things NDepend told me about a personal project of mine - this time a curious problem with Exception naming.

NDepend on a Real Project, Round 1.2: Dead Methods

This is the second in a series of blogs about things NDepend told me about a personal project of mine. This time, methods which are apparently never called.

NDepend on a Real Project, Round 1.1: the Dashboard and a Non-Protected Abstract Class Constructor

The other day I got an email from Patrick Smacchia, generously offering me an NDepend licence on the grounds that if I find it useful I can write about it on my blog. NDepend allows you to write Linq queries against an assembly or a code base to interrogate it for quality issues and see various metrics and reports. I have a personal project underway which I've been working on for some time, so I figured I'd give it a go and see what it can tell me. This is the first of the results.

I See AnemicDomainModels

AnemicDomainModel is an anti-pattern I seem to keep coming across. Here's an overview of it, the problems it causes, and some pointers on leaving it behind.

Using Dependency Injection When Calling .NET Over COM

I've recently been working with a number of VB6 systems which use C# .NET components via COM, and wanted to keep the same sort of organisational structures and patterns in the C# part of the application as I would if it was a standard MVC app or WCF service - namely, using Dependency Injection to plug the various C# classes together. This is easier said than done with COM, but here's an approach I've used to achieve it.

Why Automated Tests Are So Great

I've recently done work at a company where there are no automated tests, and tests aren't part of the culture. I've been writing tests for so long now that it's jarring to consider working without them, so I've gone ahead and written tests for my part of the work. As I've done so it's really brought home the advantages of writing tests, and I wanted to list them out.

A Generic, IDisposable, Unit-Testable, Error-Handling WCF Service Client

I recently reused my generic, disposable WCF service client, and made some changes to make it simpler to use and easier to unit test. Here's what I did.

GetValueOrDefault() For An Expression of Arbitrary Length Using Expression Trees

In my most recent project we had to support classes with fairly deep object graphs where any of the nodes could validly be null. We didn't want to have lots of 'if not null' checks everywhere, so I wrote an extension method which takes an expression of any length and returns the expression value or a default value if any of the nodes are null. Here's the extension method code, along with an overview of how it works.

Extending WatiN 3: Detecting if a PDF Has Opened In a New Window

WatiN lets you attach to browser windows so you can verify their contents and close them as part of your tests, but the standard API doesn't detect windows with PDF documents in them. Here's an extension method which does.

Extending WatiN: Useful Extension Methods

I've been doing a fair amount of UI testing using WatiN recently – here’s some extension methods I've found useful.

Agile Programming Practices 101 with the Nimble Pros Calendars

For the last two years, I’ve ordered the Nimble Pros Software Craftsmanship calendars, which use ‘motivational poster’ style pictures to depict various software practices and principles worth keeping in mind. Here’s one of the walls at work, where I’ve got the calendars cut up and displayed for easy reference: I like being able to point to a principle when its use pops up, and they provide a nice illustration of things everyone should be aware of. I’ll be following this up with a post on each month’s ......

A Super-Fast C# Extension Method using Expression Trees to Create an instance from a Type

Having written an extension method to create an instance from a Type and been a bit underwhelmed by its performance, I looked into exactly what was happening and have now got it working much, much faster. Here's how.

Clean Code: Writing Readable Unit Tests with Domain Specific Languages

I'm currently reading Clean Code: A Handbook of Agile Software Craftsmanship by 'Uncle Bob' Martin, which includes a section on writing readable unit tests. I've had an article about using Domain Specific Languages (DSLs) to write readable unit tests in the works for a while now, and was inspired to finish it off using a 'clean' unit test from the book.

C# Performance: new vs Func vs Activator.CreateInstance()

I recently wrote an extension method which uses an Expression Tree to create a Func which creates an instance of an object from its Type. With that done I thought I'd check the performance difference between my method and Activator.CreateInstance(), which it was intended to replace. Here's what I found.

A C# Extension Method using Expression Trees to Create an instance from a Type

I recently wrote a Type.GetInstance() extension method, and used the opportunity to play around with Expression Trees, which I'd recently read up on. Here's the set of extension methods I came up with, which allow you to quickly create an instance of a Type from the Type itself.

My Programming Reading List

I've made a list of programming books I've read, am reading and am going to read on the Bookshelved Wiki; would anyone like to recommend good books for a web-oriented, C# Agile programmer which I've not discovered or not considered?

A Friendlier NUnit PredicateConstraint

I've taken to using NUnit's constraint model for my unit tests, as I find it a great way to write readable tests which state exactly what they prove. NUnit has lots of built-in Constraints, but its PredicateConstraint doesn't return very helpful error messages; here's a friendlier version, which does.

Populating ASP.NET MVC ViewModels using ViewModelBuilders

The ViewModels in my current project had got quite complex; as well as properties copied from model objects, they increasingly had flags used by Views to know whether to render links or sub-sections. The logic which set these properties was bloating Controllers, so I factored it out into objects which populate all non-editable properties of a ViewModel; ViewModelBuilders. Here's how :)

Interview question - there's a lot wrong with this code :)

I had some really great responses to my last post regarding some bad code I've shown to interviewees - pretty much everything I intended to be bad was spotted, as well as some interesting points I hadn't considered. Here's the code again along with the bad bits as I saw them, and then I'll go over the extra points raised in the comments.

Interview question - what's wrong with this code?

You can learn a lot about good code from reading bad code, and at least something about how well someone codes from what they can tell you about bad code. With this in mind I handed a print out of some bad code to the latest prospective developers I've interviewed, to see what they made of it. I'll write another blog with the things I think is wrong with the code soon (there's quite a few of them), but it'd be very interesting to hear what people think is wrong with it before I do :)

Self-Configuring Domain Event Handlers

I recently implemented Domain Events as a way of organising domain logic in our application; I really liked the way it worked out, so I wanted to share an overview of using Domain Events, as well as a class which automatically looks up all the available IDomainEventHandlers.

A Generic, IDisposable WCF Service Client

WCF clients need to be cleaned up properly, but as they're usually auto-generated they don't implement IDisposable. I've been doing a fair bit of WCF work recently, so I wrote a generic WCF client wrapper which effectively gives me a disposable service client.

Book Review: Growing Object Oriented Software Guided By Tests by Steve Freeman and Nat Pryce

The second programming book I read on holiday was Growing Object Oriented Software Guided By Tests by Steve Freeman and Nat Pryce. To sum up early: its a very, very good book on TDD.

Book Review: Apprenticeship Patterns by Dave Hoover and Adewale Oshineye

If, on your holiday to Mexico, you find yourself on the beach reading programming books, you are probably officially a geek. Having accepted that, I read a couple of programming books on the beach on holiday in Mexico recently, and figured I'd review them both. This is the first.

Self-Configuring Enterprise Library Validation

A recent project used Enterprise Library Validation to validate domain objects, and needed it configured for a web front end, a WCF front end, and (of course) unit tests. The same configuration in 3 different places didn't strike me as very DRY, so I figured hey - why not have it configure itself? Here's a quick paraphrase of how I did it.

Dynamically accessing deployed Assemblies and Types in C# - Part 2

Well, will you look at that - no sooner do I write my first blog about an extension method I've written for accessing deployed Assemblies and Types, than I discover today that it doesn't actually work quite how I intended it. Excellent!