Chris McGrath’s Blog

Just another Developer’s Blog

Posts Tagged ‘Programming

Grids suck

leave a comment »

I’ve heard a lot of people ask, “What is the benefit in moving to WPF? I’m just making a plain line of business app I don’t need any special effects.”  Well I think that using WPF there is one thing that it really makes stand out – Grid suck.

I know all you winform enthusiasts out there are saying, “Have you seen the DataGridView? I can create a list in seconds.” Well I’ve got news for you DataGridViews suck too.

I’m not talking about from the programming point of view, you’re right nothing compares to the DataGridView for quickly showing data. The problem is from the user experience point of view, it’s ugly and anything more than three columns is really hard to use.

So here is the big problem with WinForms, it’s hard to create “ViewAll” screens without using a DataGridView, as such you don’t bother with anything else. So if you want a reason to change to WPF, you no longer need the DataGridView.

Instead of Grids WPF focuses strongly of List Items. You provide a template for one item – and it’s as customisable as you like, any control can go in it, you can use multiple lines – and it repeats that template for every item in the list.

Written by Chris McGrath

July 18, 2009 at 6:03 pm

Posted in Blog

Tagged with , , ,

Keeping Names positive

leave a comment »

Just read this blog –

This is something that has always annoyed me too. Things like e.Cancel = true; just seem wrong.

The absolute worst case of this I have ever come across is in the Local Security Policy. In security options, there’s a policy of, “Domain member: Disable machine account password changes” which you can set to Enabled or disabled.

So you can enable the disabling of the machine account password changes or disable the disabling of the machine account password change.  This is just mind-boggling.

Written by Chris McGrath

July 10, 2009 at 9:53 am

Posted in Blog

Tagged with ,

In value set

leave a comment »

One thing which I quite often wish C# had a clean way to say if a variable is equal to one of many values.

Traditionally we’re stuck doing

myVal == 5 || myVal == 8 || myVal == 100;

we could say

new [] { 5, 8, 100 }.Contains(myVal);

but to me this doesn’t allow your intent to be read nicely. In fact, it just seems the wrong way around.

What we need is something like SQL’s in. so I could say

myVal in (5, 6, 100)

that reads much better. I remember that Delphi also had a similar command.

Written by Chris McGrath

July 9, 2009 at 3:38 pm

Posted in Blog

Tagged with , ,

One of the biggest problems with software… Updates

leave a comment »

Seriously, how come there isn’t a standard pattern for handling updates? Updating is annoying. Any program that makes updating it easy should be recognised.

So I’ll start it off with my favourite, Firefox. They do a great job at making the process simple. When an update is available it pops up a dialog you hit one button and it’s installed. Further, it makes it even less intrusive by waiting for restart before doing the actual install. This should be the goal of all software developers.

I think a major problem we’ve got ourselves into is thinking that an update is just an install. It may sound logical, you’re installing a new version over an old version, but there is a big difference. An install has to find out information – where to install it, what parts to install and other options. An update already knows (or should already know) this information. Hell, you don’t even need to make people re-agree to the licence agreement if it hasn’t changed.

Now let’s look at some bad ones: TortoiseSVN. It seems to make an update about once a month, and how does it tell you? It pops up a dialog saying an update is available and go to the website to download it. You then go to the website, download the full installer and perform a full installation. Also the dialog has no “Don’t tell me about this update again!” button, so it will keep popping up until it’s installed.

But at least TortoiseSVN waits until you use it to pop up the message. Daemon Tools pops up the message as soon as windows starts. And that’s a tool that I don’t use very often and am happy with how it works, why should I update it?

Finally there’s iTunes. I think iTunes has some great examples of horrible user interactions (I’ve written about it before here) and how to handle updates is no exception. First, an update is 60MB! I can’t understand why the full installer is 60MB, for an update they should be able to make it much smaller. Then they have this “Apple Software Update” which runs in the background.  Yet iTunes itself can detect when an update is avaliable. Now the Software Updater also tries to push Safari on you; and quite aggressively. After seeing this apple fan boys can’t complain about Microsoft pushing stuff on us. Then the installer runs, takes much longer than a update should and oh, it decides to add those shortcuts back that I deleted.

Which leads me to my final difference between installers and updates – shortcuts. An installer puts shortcuts on the machine, if they aren’t there when an update is run it’s because the user deleted them – SO DON’T PUT THEM BACK!

Written by Chris McGrath

July 2, 2009 at 2:49 pm

Posted in Blog

Tagged with ,

Path.Combine Problem

leave a comment »

In a recent post I praised this method. However, I have found out a querk with it which really takes away from it’s usability.

The idea of the function is provide a location and a relative location and it creates the absolute URL. Like this…

Path.Combine(@”C:\Windows”, “System32”);

The case that it handles that makes it so useful is it figures out whether it should add a slash after the first path.

But for some reason there is a special exception – when the first string ends in a colon…

If I say

Path.Combine(“C:”, “Windows”);

I would expect the output to be
but instead it’s

This case is outlined by the documentation but I can’t see why they did it. I posted a note about it here. And they gave the reason “intentional for FAT compatibility.” I would love if someone could give me the exact case that it is needed for.

Written by Chris McGrath

July 2, 2009 at 2:19 pm

Posted in Blog

Tagged with ,

Casting in LINQ

with one comment

I recently wrote a LINQ query on a List of WeakReferences. The target of the weak references all implemented my interface (let’s call it IMyInterface). I wanted the query to return a list of all alive IMyInterfaces. It’s a very simple query but was wondering what is the best way to cast the target to IMyInterface? The two ways are…

ref.Where(o => o.IsAlive).Select(o => (IMyInterface)o.Target).ToList();


ref.Where(o => o.IsAlive).Select(o => o.Target).Cast<IMyInterface>().ToList();

The traditional o-o developer in me initially to the first. But then when I thought of the second I couldn’t help but like it. It reads so well from left to right. The only ambiguity it has is whether it is casting each element or the list object to IMyInterface. Maybe it should have been called CastAll or CastEach

Written by Chris McGrath

May 11, 2009 at 12:02 pm

Posted in Blog

Tagged with , , ,

How I’m learning python.

leave a comment »

As object-orientated programmers we like to think that we can pick up a new o-o language and run with it. And this is mostly true. However this can lead us to play with a language for 10 minutes with no direction and proclaim ourselves experts in the langauge. This I have a problem with. Such an exercise just handles very simple situations and doesn’t let us get familar with the quirks and features that makes a language unique.

The only way to do this is by playing around with a language but to have direction – to have a problem to solve. For python I’ve found a great domain to play in – XBMC plugins. I’ve mentioned XBMC before but one great thing about it is its support for plugins through python.

So what type of plugin should you make? Well the obvious one – a plugin to grab videos off sites and play them in XBMC. Why? well because there a heaps of examples to play around with yet a lot of sites are unique enough to not make it simply a copy and paste job.

I’ve decided to make one to view videos from the ABC Australia website – I’ll post updates on how the progress goes.

Written by Chris McGrath

April 30, 2009 at 5:52 pm

Posted in Blog

Tagged with ,