Mavnn's blog

Stuff from my brain

Perls Before Swine

Buried in the depths of our code base (.NET house) has been a single
Perl script, hacked together by an ex-college one afternoon to
eliminate an infrequent and boring (read: error prone) task.

Which is great and all, but that ‘infrequent’ moment has arrived once
more, and none of the rest of us have Perl installed. None of the rest
of us really want to install it, either…

An other afternoon later, and we now have an F# version of the script
checked into source control, and the first (and last) piece of Perl
has left source control. The new version is just as quick and dirty as
the old, but at least can be run on any of our machines. As a matter
of general interest, before and after versions below:

Before:

After:

Get With It, C# Compiler!

Who doesn’t want to build recursive lambda functions?

Func upChain = move =>
                {
                    if (move.ChainParentId != null)
                        upChain(Coa.MoveRequests.Single(
                            m => m.Id == move.ChainParentId));
                    return move;
                };

should work (according to me), but it complains that the second upChain is an unassigned local variable.

And I don’t feel like rolling my own y-combinator.

NCrunch

Why has no one pointed me at NCrunch before?

http://www.ncrunch.net/

Real time updates of test results as you write the code, complete with in editor code coverage.

Awesome stuff, whether you're using full TDD or just adding unit tests where none have gone before…

Terms of Engagement

I was looking to express a concept recently and realised I didn't have the terminology for it, so I decided to coin something.

So I now have a new category if friendship:

A 'real' friend is someone who I can express an opinion to, disagree with and still be friends with.

This is mostly independent of whether they are also a 'good' friend (someone with whom there is a lot of shared knowledge and time) or a 'true' friend (stuck with the friendship through crap, or at least given me strong reason to believe they would even if they haven't had to yet).

Of course being in any of the categories makes moving into the others more likely…

New Job.

Same as the old job (literally, I’ve been doing it for about a
year…) but with several grand extra pay and a better job title.

Bonus. Just wish the whole process of getting there had been a bit smoother.

Who Wants a Council Tax Exemption? (T&Cs Apply)

Terms and Conditions apply.
You must have lived in Coventry and been liable for Tax during April this year.
You may be declared in prison, dead, in hospital or a minister of the religion of my choice.
Exemptions may be declined.
Applies to testing database only…

Dynamics and Extension Methods

Filed under: I should have thought of this months ago…

This is a particularly geeky post, mostly for the benefit of a work college (hi Caroline!) who's going to start seeing this appearing in some of our code base, but I thought it might appeal to some other people as well.

When coding against Microsoft Dynamics CRM 4.0, it's frequent that you end up having to use 'Dynamic Entities' (mostly for custom data types you've added to the system). You basically get access to these as a hash table with string key in your code, e.g.:

    object personName = dynamicEntity["ccc_personname"];

Great, except the compiler doesn't know the type of personName. So:

    string personName = (string)dynamicEntity["ccc_personname"];

Except that for everything apart from strings, the Dynamic SDK wraps values in a property type:

    bool personNice = ((CrmBoolean)dynamicEntity["ccc_personnice"]).Value;

Except that CrmBoolean can be null, but isn't Nullable. There are also other fiddly details to account for. It all gets pretty verbose, pretty annoying, and very error prone very quickly.

So, without further ado: DynamicEntity extension methods that return a strongly typed result, and play nicely with the ?? operator.

Census State

2011: 32, married, computer programmer with 3 year old son. Life is good if frequently tiring!

2001: 22, working in desktop publishing (for a bank!) and about to meet the lady who will be my wife - although still going out with someone else. Shortly about to lose my job and descend into a (comparatively) short period of depression I utterly failed to recognise.

1991: 12, secondary school student reading A-level biochemistry text books for fun and trying to readjust to British society (I've been back for about 18months after 4 years abroad). My brother is about to leave the house to go to uni, leaving me an unshared bedroom…

1981: 2, I'm walking on broken milk bottles and chugging white spirit. Then my brother used my pram to take out the side of a Rolls Royce. The way my parents tell it it's a miracle I survive.