mhinze.com

Matt Hinze, learning in public

Archive for the ‘C#’ Category

Breaking up with the ternary operator

I love the ternary operator.  It’s so terse and clever.  It’s been my bread and butter for years.  It does things no other operator can do, and on three operands!  It’s really a shining example of programming language designer genius. 
But lately we’ve been having problems.  Things between us just aren’t working out.
I generally catch [...]

Aggregated specifications

An example from my inversion of control talk involves a message formatter.  It applies formatting rules to a string.
public interface IMessageFomatter
{
string Format(string message);
}

Instead of doing all the work in the implementation of this interface, the message formatter will aggregate several distinct rules.  An inversion of control tool is configured to [...]

Simple Nested Closure

Nested closure is one of those fancy patterns Martin Fowler first coined (as far as I know) and published on his DSL WIP site. His formal definition:
Express statement sub-elements of a function call by putting them into a closure in an argument.

You pass a delegate as a method parameter. The receiving method executes the function [...]