A C# Postcode Struct with Parser

As discussed recently, I’ve been trying to knock together a class struct to represent a UK postcode, provide a means of parsing a string as potentially being a valid postcode (or optionally just an outer code), and split that postcode into “outer” and “inner” code. I say potentially because, as you’ll know if you’ve looked into this topic at all, it’s impossible to validate whether a string truly does represent a postcode without querying the (copyrighted and expensive-to-license) Postcode Address File. As a result, my solution is not very stringent – it is possible to persuade it to successfully parse an invalid postcode, but hopefully there should be no occasions when a valid postcode is rejected. ...

29 May 2007

Postcode Validation

Wikipedia cracks me up sometimes. I’m sat here at my desk, trying to knock together some C# code to quickly validate an entered string as being a UK postcode. Naturally I turned to this Wikipedia article for assistance, where I find this quip: “Automatic validation of postcodes on the basis of pattern feasibility is therefore almost impossible to design, and the system contains no self-validating feature such as a check digit. Completely accurate validation is only possible by attempting to deliver mail to the address, and verifying with the recipient.” ...

23 May 2007

SQL 2005 Unleashed

Many moons (and about four jobs) ago, a wise DBA by the name of David Hanson once recommended to me a book called Microsoft SQL Server 2000 Unleashed. I took his advice, bought a copy, and it rapidly became one of the most dog-eared and oft-thumbed computing books I have ever owned. It is comprehensive, deep, broad, well-written and covers everything one might ever wish to know about SQL Server 2000. With its help and guidance I came to love and respect Microsoft’s premier database product, passing the 70-229 exam by a comfortable margin. ...

18 May 2007

MSDN Technical Roadshow 2007

I’m off to the MSDN Technical roadshow in Harrogate tomorrow, and am actually really looking forward to it this time. These events are free, so always well worth attending when they’re local, but some years are certainly better than others – it mostly depends on the material being covered. I remember one year circa 2003-4, when .NET was well established, but before the Whidbey release, so the majority of the day was effectively just a sales pitch covering elementary .NET concepts, presumably for those laggards who hadn’t yet made the great leap from VB6. Another data-binding demo, anybody? Yawn. ...

12 March 2007

Ian Nelson, MCSD.Net

I am now a Microsoft Certified Solution Developer in .NET 1.x technologies. This is a qualification that I’ve been working towards on and (more often than not) off for the past four years or so. It’s not really the case that the exams were super-hard, just that it took occasional motivation to get round to taking them! So, was it worth it? Did I learn anything en route? Did the exams boost my employability? Would I be more inclined to employ someone with an MCSD than an applicant without? ...

11 February 2007

A Serializable KeyValuePair Class

Having accepted that Returning DataSets from WebServices is the Spawn of Satan and Represents All That Is Truly Evil in the World (or at least, not exactly best practice), I’ve been trying to make a conscious effort to instead use lightweight custom objects in my middle tier, to be exposed via web services for use by other applications. I felt sure that some of the new Generic classes in the .NET 2.0 FCL would help me in my quest. Specifically, as I often need to expose simple arrays of Key/Value Pair metadata, I planned to create an instance of the System.Collections.ObjectModel.Collection class, containing a bunch of System.Collections.Generic.KeyValuePair objects. ...

17 September 2006

Big Integer

As I mentioned last summer, I do enjoy whiling away a few hours attempting to solve the maths / progamming challenges set on Project Euler. My language of choice for most puzzles is C#, but this hampered me on some of the questions as there is no in-built support for really big integers. However, a little bit of Googling and I came across this excellent BigInteger class on Code Project which does everything I need and more – and it seems bloody fast, too. Thanks to this class, I’ve been able to knock off several more problems this weekend, and now have a rating of “11% Genius” – still some way to go, then… ...

17 July 2006

Universal Comparer for .NET

Back in November 2004, I had the idea of making a “Generic Sorter for Strongly-Typed Collections”, by harnessing the mighty power of reflection. Well, earlier this month somebody anonymously emailed me some code that takes this to a whole different level, enabling sorting on multiple properties and to arbitrary depths within the domain model hierarchy, all by taking a single SQL-like parameter. It’s really very clever indeed, and I’m going to use this method in the future – thanks, anonymous code fairy! ...

27 February 2006

String.IsNullOrEmpty

The single most popular entry on this blog is, surprisingly enough, this quick post from Summer 2004 where I did a quick experiment to “prove” that in .NET the quickest way of proving that a string is empty is to compare its length to zero. Well, as of .NET 2.0, we have a new static method on the System.String class – IsNullOrEmpty – that allows you to easily test whether a string is, well, null or empty! ...

25 February 2006

John's Background Switcher

What’s on your desktop background? Some bland corporate logo perhaps, or maybe one of the bog-standard Windows wallpapers, or maybe a photograph you took years ago? Let’s face it, when was the last time you changed your background? Wouldn’t it be great if you could specify a few keywords and have your background periodically change to show a new image courtesy of Flickr? Say, a sunrise, a mountain, a wintry scene, a favourite holiday destination, or, well, whatever takes your fancy? ...

10 December 2005

ASP.NET 2.0 – one month on

It’s over a month now since Visual Studio 2005 officially RTM’d, and during that time I’ve been fortunate enough to have been using it for the majority of my time on most working days. One of the things we’re trying to achieve is the integration of several distinct internal corporate web applications into a bespoke portal system, with single sign-on, common authorization model, common look and feel, etc. There’s been quite a heavy R&D / proof-of-concept aspect to the workload so far, as we try out different ways of achieving this, and grow familiar with the new technologies available to us in ASP.NET 2.0. ...

10 December 2005

Rounding Up The Result of Integer Division

Here’s a damn useful piece of information which should be in the armoury of every modern codemonkey: In Java, if it is required to round up the result of dividing m by n (where m and n are integers), one should compute (m+n-1)/n Source: Number Conversion, Roland Backhouse, 2001 I’ve used this deliciously elegant result in production J2EE code in the past, but it’s equally valid in C#, as long as you can make the additional assertion that m/n is positive. This is because whilst Java treats integer division by rounding to zero, C# merely truncates the result (in an unchecked context). In my experience, the most frequentuse for this result is the deft answering of questions such as “if I have x items in my dataset and I display y per page, how many pages do I have in total?”, where it is obviously safe to make the assertion of a positive result. ...

6 September 2005

10 Things That Should Be More Popular

Some days I feel like I’m spitting in the wind. It amazes me that the following ten concepts, websites and applications aren’t more widely used: RSS Feeds – why waste your time repeatedly trawling dozens of sites looking for new content? Let it come to you! Flickr – practically everyone I know has a digital camera, but still relatively few have a Flickr account. Share your photos, don’t keep them unseen on your hard drive! GMail – by far the most effective web-based email. FireFox – if only for the tabbed browsing. But really, it’s so much nicer than IE6, and a myriad of different extensions are available. OneNote – so much better than scraps of paper. Desktop Search – I don’t care which desktop search program you use, but please install one! You’ll find it so much easier to find old emails and other files. del.icio.us – access your bookmarks anywhere, and share them with friends. ClearType – if you have a flatscreen monitor, you should turn ClearType on. Period. Virtual PC – there’s no need to test beta software on your main machine, or keep several differently-configured computers around the house any more! SyncToy – this is a great little app for synchronizing and backing-up folders; it’s really useful for combining media folders, and for synching files with a portable hard drive.

31 August 2005

Computer Games I Have Loved

Isn’t it funny how one’s tastes change as maturity progresses? I used to spend my summer holidays at the sea-side, playing in arcades and seeking the perfect milkshake (lime); more recently I’ve been spending them in the highlands, playing on the hills and seeking the perfect dram (lagavulin).Hmmm… I think I may have mentioned that the wife is away in the States for a while.At the start of this period of solitude, I panicked, wondering whatever I could do with myself, and came to the conclusion that it would be a good idea to buy a computer game to while away the hours.After all, I spent much of my formative years killing time on a variety of computer and console games, so why not rekindle that prior love affair? So it was that I bought The Sims 2, a truly excellent game, and had an enjoyable evening trying to motivate my wee Sims to improve their skills, better themselves, and generally enjoy life.All good harmless fun. ...

22 August 2005

Project Euler

If you like maths problems, and you like programming (and hey, who doesn’t?), then you’ll love Project Euler.

22 August 2005