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

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

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

Key Bindings

When I was at college studying Electronics and Computer Engineering, we used a piece of software called Proteus. This software took a long time to get used to due to its interesting key bindings and mouse usage. To select a track in Ares (PCB Layout package) you Right Click on it. Hmm not too standard, but okay, I can live with that. Now what happens if you were to right click on that track again?...

July 17, 2009 · 2 min

Overuse of the Var keyword

When I first got hold of VS2008, and had a play with the new version of C# I loved the Var keyword. To me the most amazing thing was no more declarations like this: System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex(); Instead I could write the following: var rx = new System.Text.RegularExpressions.Regex(); Making it akin to VB developers being able to write: Dim rx As New System.Text.RegularExpressions.Regex() (I have had however to cope with a coding standard that explicitly forbid this declaration in VB…Backwards or what?...

June 29, 2009 · 2 min

Coming From Something as opposed to Going To Something

Over the last week I have noticed myself preferring methods being called IntegerFromString rather than StringToInteger. Is sometimes takes me a little longer to read (only a few milliseconds, mind) but I think I am getting more used to it, and I do think it enhances readability. The main point for readability comes from the fact that I work a lot (in my spare time when coding) on graphics processing in GDI....

June 19, 2009 · 2 min

Fluent Validation

A few days a go i was going through my bookmarks, and came accross this post on the GetPaint.Net blog about using a fluent interface for parameter validation. After reading the article, I tried the code out at home, and was very impressed. Not only does it read well, but also does not create any objects untill a piece of validation fails. Very nice. However i wanted to use this at work, and this presented me with a problem....

June 12, 2009 · 2 min