Actually, I'll mutate if you don't mind

After I had changed all my extension methods to be functions and return a new object rather than mutating the self parameter, I changed them all back to be refs. Why? Well mainly because the library I am writing is in VB, and these methods are internal. VB supports ByRef parameters as the first param in an extension method, so no problems there. The only reason I was changing them so that they were C# compatible was so that I could test them with MSpec in C#....

September 10, 2010 · 2 min

To mutate or not to mutate

I have been working on a project recently that involves a lot of work with Flags Enums. To aid with this I created a set of Extension Methods: Add(Of T as Structure)(self as T, value as Int) as T Add(Of T as Structure)(self as T, values() as Int) as T Remove(Of T as Structure)(self as T, value as Int) as T Remove(Of T as Structure)(self as T, values() as Int) as T Has(Of T as Structure)(self as T, value as Int) as Boolean HasAll(Of T as Structure)(self as T, values() as Int) as Boolean HasAny(Of T as Structure)(self as T, values() as Int) as Boolean Now the last 3 methods I am happy with - they are self explanatory and do what’s expected....

September 8, 2010 · 2 min

Using Visual Studio's Regex Find and Replace

The Visual Studio Find and Replace dialog is often overlooked, and when parts of it are looked at (Regex searching) it often gets a bad rep. Sure it doesn’t implement all of the Regex syntax (non greedy search springs to mind), but that’s not to say it isn’t useful. For instance, I was working on some code that involved a Model View Presenter type style, but used Subroutines (void methods) rather than WriteOnly properties for brevity (in C# you can do a Set only property in 1 line, VB it takes 5)....

August 31, 2010 · 3 min

Multilining If statements conditions should be banned. now.

Multilining if statement conditions is bad. I was modifying some code and came across this: If String.IsNullOrEmpty(_selectedGUID) OrElse _ _selectedGUID = FeeAgreement.GetDefaultContractAgreementGuid OrElse _ _selectedGUID = FeeAgreement.DefaultPermAgreementGuid Then fgFeeAgreements.SetCellCheck(rowAdded, 0, CheckEnum.Checked) _selectedTitle = ag.Title _lastIndexRowSelected = rowAdded End If Which at a glance looks like this: Single Line If Variable Assignment Variable Assignment One person suggested that if someone had to do multiline the condition they could at least indent it....

March 24, 2010 · 2 min

Converting from NUnit to MSTest

While this is not something I personally would want to do, we (for whatever reason…) are to use MSTest at work (I think it is due to the whole “Its Microsoft, so it’s supported” argument). Now as no one else on the team does any kind of unit testing (serious), the only test projects we have are written by me, on the quiet before being told if I wanted to unit test then use MSTest....

January 12, 2010 · 3 min

Thanks Google for solving my problem!

Following on from yesterday’s post about separation on concerns and where to put some undefined logic for a multi state checkbox, I did a fair amount of research. I must say the Quince website is a good repository of UI Design Patterns, as is Welie. I couldn’t find anything like what I was after, which I guess means I shouldn’t be doing it this way? After a while a brainwave struck me: “Gmail lets you select things, how does it do it?...

December 16, 2009 · 1 min

Functionality and Seperation of Concerns

When I am writing a winform in an MVP style, I often wonder how far to go with the separation. Say I have the following situation: A small form which should display a list of messages, and allow the user to select which ones they want processed. It processes each message in turn. If a message has more than one attachment, a dialog is shown to ask the user to select which attachment should be used for that message....

December 15, 2009 · 3 min

Software Fuzzying maybe?

This morning I read this post by Alfred Thompson about whether we are Software Engineers or something else. I can’t help but agree with him, as I don’t feel we are engineers (yet), our discipline is a little fuzzy to be classified as engineering I think. However I think we are not alone in this boat. Not all engineering disciplines are quite so well cut. My father is an Engineering Pattern Maker....

October 7, 2009 · 2 min

Region Hate

There seems to be a lot of negativity towards the #Region in .net at the moment, with many people hating them and calling all usages of them ‘retarded’. I can see their point, especially when you see the odd class with regions like this: Class Foo { #Private Members #Protected Members #Friend Members #Public Members #Private Constructors #Protected Constructors #Friend Constructors #Public Constructors #Private Methods #Protected Methods #Friend Methods #Public Methods } Clearly the person who wrote this was ill at the time (I hope…), and besides, where would Protected Friends go?...

October 6, 2009 · 2 min

Fluency at a cost?

I like fluent interfaces. I find them easy to read, and nice to program with. However the more I write them the more I notice there is a cost associated with them. It’s not much of a cost, but it is there none the less. To demonstrate say we have a class called Animator. It has the following properties and methods on it: + Control + Distance + DistanceType + AnimationType + Direction + Time + Algorithm - Animate() Now while you could just set all the properties and then call Animate(), a Fluent Interface makes thing nicer:...

July 29, 2009 · 2 min