Saturday, March 31, 2007

Some useful web resources

I came across a couple of useful websites today which I thought I'd post here for others and for my own information.

First is Domain Tools, which provides the usual Who Is lookup and a whole lot more. Most useful I thought was the SEO text browser that shows how a website looks to a search engine and gives a few pointers to how your pages could be improved for SEO.

That site led me to About Us, that is an interesting attempt at generating a Wiki for websites. I imagine this could become an interesting site to browse and find new sites to visit. If nothing else, adding your site will add another inbound link to your site.

Another useful resource that I didn't find today but follows on from the SEO text browser above is the HTML Validator provided by the W3C. Running your site through this will show any problems with your HTML code. I've no idea if valid HTML will improve your search rankings but I'm fairly certain it won't hinder them.

Friday, March 30, 2007

The evil #if DEBUG

I recently received a bug report for an ASP.NET site I've been maintaining but when I went off to test out the problem running the site through Visual Studio everything worked fine. Slightly confused, I went back to the live site and immediately reproduced the problem. So I thought the problem must be caused by the site not being in sync with the the development box so I uploaded the latest code. The problem was still occurring... I was fairly unfamiliar with the code so I started stepping through it. You've no doubt guessed the problem by now from the title of this post. There was some code wrapped in an #if DEBUG directive that actually overrode the parameters passed into the page via a query string. I removed that and the problem on the live site was reproducible in Visual Studio. But I wasted an hour or so getting to the bottom of it.

So the moral of the story is don't change behaviour of your code with #if DEBUG statements. The only use I've found for #if DEBUG is to log things, and generally that can be avoided through the use of the trace listener infrastructure. 

Monday, March 26, 2007

Not everything is high priority

If every email you send to me is marked as high priority, they tend to lose their impact, I assume none of them are important. What will you do when you really do want to send me a high priority email? There is no priority zero...

I presume you're familiar with the boy who cried wolf?

Saturday, March 24, 2007

Meaningful descriptions for enums

Getting a string representation of an enum is pretty simple, just call ToString() on the enum. However, we often want to have a more user-friendly string to display to the user, that includes spaces and the like. I guess one way of achieving this would be to override ToString on our enum class, except you can't override ToString in an enum... And how to go the other way, from the string representation to the enum? The solution set out below uses an EnumDescription attribute that can be applied to the values of an enum. Now I can't claim to have come up with the idea for this, I think I first saw it on Richard Blewett's blog, but his archive doesn't seem to go back as far as it should. Saying that, I've also made quite a few alterations so I can claim some of this code as my own. The use of generics means it will only work with .NET 2.

using System;
using System.Reflection;

namespace Utils
{
  /// <summary>
  /// Attribute used to give textual descriptions to enums.
  /// </summary>
  [AttributeUsage(AttributeTargets.Field)]
  public sealed class EnumDescriptionAttribute : Attribute
  {
    /// <summary>
    /// Creates a new <see cref="EnumDescriptionAttribute"/> instance.
    /// </summary>
    /// <param name="text">Text.</param>
    public EnumDescriptionAttribute(string text)
    {
      this.text = text;
    }

    private string text;
    /// <summary>
    /// Gets the text description.
    /// </summary>
    public string Text
    {
      get
      {
        return text;
      }
    }
  }

  /// <summary>
  /// Helper class to get descriptions of enums.
  /// </summary>
  public sealed class EnumDescription
  {
    private EnumDescription()
    {
    }

    /// <summary>
    /// Gets the description of the specified enum. If there is no description attribute, returns the 
    /// enum as a string
    /// </summary>
    /// <param name="e">The enum to get the description of.</param>
    public static string GetDescription(Enum e)
    {
      string ret = e.ToString();
      Type t = e.GetType();
      MemberInfo[] members = t.GetMember(ret);
      if (members != null && members.Length == 1)
      {
        object[] attrs = members[0].GetCustomAttributes(typeof(EnumDescriptionAttribute), false);
        if (attrs.Length == 1)
        {
          ret = ((EnumDescriptionAttribute)attrs[0]).Text;
        }
      }
      return ret;
    }

    /// <summary>
    /// Gets the enum value from its description.
    /// </summary>
    /// <param name="description">Enum description.</param>
    public static T GetEnum<T>(string description)
    {
      Type type = typeof(T);
      FieldInfo[] fields = type.GetFields();
      foreach (FieldInfo info in fields)
      {
        // if the passed-in description is the name of the Enum, return that
        if (info.Name == description)
          return (T)Enum.Parse(type, info.Name);

        // otherwise look at descriptions
        object[] attrs = info.GetCustomAttributes(typeof(EnumDescriptionAttribute), false);
        if (attrs.Length == 1)
        {
          if (((EnumDescriptionAttribute)attrs[0]).Text == description)
          {
            return (T)Enum.Parse(type, info.Name);
          }
        }
      }

      return default(T);
    }
  }
}

Usage is something like follows

  public enum LogEntryType
  {
    Workflow,
    [EnumDescription("User information")]
    User,
    [EnumDescription("Workflow runtime")]
    Runtime,
    Error
  }

  string logEntryTypeString = EnumDescription.GetDescription(logEntryType);

  LogEntryType eventType = EnumDescription.GetEnum<LogEntryType>(logEntryTypeString);

Wednesday, March 21, 2007

Not liking Vista so much

Doing a search on Google for 'liking Vista' brings up this site as the third in the list. I'm not triyng to show off by saying this, but it perhaps shows that there's not that many people who are liking using Vista. And I'm slowly moving from the liking Vista camp to the not liking Vista so much camp. To be fair most of the problems I'm having probably aren't Microsoft's fault but they are still annoying.

My major problem is the lack of sound coming out of my Dell Dimension machine. This was forgivable initially since I installed Vista before it hit the shops but even though Dell have released new drivers I still can't get anything to come out of my speakers. Vista thinks everything is OK, the only indication that something is wrong is the 'Failed to play test tone' error message when I do a test of my speakers. I've contacted Dell and talked to a tech support guy who said he'd get back to me and I've never heard anything from him since. It seems like other people are having the same problem so I'm hoping this should be resolved soon. Good job I've got an XP machine with sound for Skype.

Next up is my USB wireless connection. It works fine but every time Vista starts up it tells me the driver has been blocked (5 times for good measure) and doesn't tell me how to get rid of the error message.

Finally, SonicWall haven't released a version of their VPN client that works with Vista. Apparently they should have one out by Q2. Again my XP machine has saved me, since I need to use SonicWall virtually every day.

Dude, where's my AdSense revenue?

I was never going to become rich from my AdSense income, but I used to get a small amount of spending money from it. But over the last few months, even though I'm getting more hits to my sites, I'm getting less and less money from ads. I think it's down to the fact that I'm getting less money per click. There was a time when some clicks would earn me a dollar or more (which, to be fair, seems ridiculous) but now I'm lucky to get more than 20 cents per click. So I guess the question is whether there is a general downward trend in prices being paid for clicks or if Google is taking a bigger slice of the action. Of course it could be just me who's suffering from this and it may be something specific to my sites causing the lack of cash. 

Tuesday, March 20, 2007

Twitter - What the ...?

I don't get it, why would I want to use it? Why would I even want to read it, do I really care that complete strangers are on their way to work or having a dump? Even if there were people on there I knew, I wouldn't be interested. "Hmm, it's 11pm at night, what do you know, my rate Roger is off to bed, what a fecking surprise"

I believe we are meant to be looking for ways to save energy these days, so if anybody has access to the power switch on the Twitter server, just turn it off. You'll be saving us from the most pointless website ever and helping the environment at the same time.

Sunday, March 18, 2007

Has my fire really gone out?

So Paul Weller asked in 1993, to which the obvious answer was "In short yes. The Jam were pretty good, The Style Council had their moments (although sometimes in an unintentionally laugh out loud way) but your solo career has been pretty unspectacular". Just like the vast majority of musicians, Weller started suffering from Musician's Dementia when he hit the age of 30. Rather than produce anything worth listening to, they start to make sad facsimiles of their older material or they try and branch out into new genres and tend to look ridiculous.

So it is also true of IT? Do programmers in their 30s suffer from Programmer's Dementia? Have I got it? Would I even recognise it if I did have it? Am I just producing a sad facsimile of what I was doing in my 20s? Have I lost the ability to pick up new skills? Is there a good reason why coders over 30 are viewed with suspicion?

Or is this just the start of my mid-life crisis? Surely 10 years too soon.

Friday, March 16, 2007

Google, you are such a tease

You really are. The Random Pub Finder gets an inbound link and you start indexing all our pages, we get lots of hits, then a couple of weeks later our pages start dropping out of your index again. It's a little bit frustrating. And perhaps more concerning is the power you wield. But so long as you stick to your 'Do no evil' mission statement, I'm sure there isn't a problem, right?

Thursday, March 15, 2007

WFPad - DIY workflow designer

So previously I'd thought writing our own designer for Windows Workflow might be too time consuming, but today I found this lovely little designer which could be the basis for our own designer. It doesn't have any support for adding code to a workflow but I consider that a plus point. I don't actually want our business analysts to even see a code editor. If we can import and export to Visual Studio whilst keeping any code behind intact this may be a marvellous solution. Keep watching...  

Tuesday, March 13, 2007

Loving Windows Workflow, hating Windows Workflow

I've been messing around with Windows Workflow lately and it's a bit of a love-hate relationship. Here's what I love, the fact I've got a workflow runtime that I can host in any application and, even better, it costs nothing. Hosting the runtime and persisting workflows to SQL Server is also reasonably straightforward, although I'm not sure my implementation is rock solid (I'm sure I'll find out if/when we go live). I love the fact I can develop workflows in Visual Studio and I can drop into C# whenever the activities provided don't quite do what I want. I love being able to write my own activities so I can parcel up commonly used functionality. I love being able to plug activities and properties together without writing any code. But then I'd like to think a business person might be able to design workflows and I can't see them picking up Visual Studio to do that. OK, I can host the Designer as well, but that's a pretty big job that I don't have time to do. I guess we could look at using SharePoint or BizTalk, but that would rather defeat the purpose of using Windows Workflow, which is primarily the cost. This seems to be the major problem workflow has always faced, making it simple enough for your average business person to understood (not suggesting they are simple of course...) but powerful enough so it can be used for real integration work. Coming from a background of using Metastorm e-Work there's a few obvious things missing from Windows Workflow that are available in e-Work. One is roles management, the other is easy forms integration. I guess both can be achieved but I need to investigate how easy it will be to do them, especially integrating forms in a fairly generic way. There is a good reason for not providing these features, since Windows Workflow is meant to be database and client platform agnostic. As ever, making a product as flexible as possible tends to make it somewhat complex and I think Windows Workflow has turned up the flexibility to 11. I have a few other niggles. Versioning doesn't seem to be supported. Workflows are persisted using .NET serialization so rebuilding a workflow assembly can cause any running workflows to fail. In fact I've had situations where I'm unable to do anything with a workflow, even terminate it. One other problem is there seems to be no simple way of getting data in and out of a workflow, without designing this data exchange into the workflow itself, something I was hoping to avoid since I was hoping to be able to do it in a generic way. But overall, given it's a version 1 product, I think Windows Workflow is pretty cool. Hopefully some of my problems are just caused by not understanding how it all fits together, so it's time for me to go and read a book.

Thursday, March 08, 2007

Panic Over - Climate Change is a Swindle

I was under the impression that we were all in agreement, that climate change is happening and it's out fault. But according to Channel 4's documentary this evening, we've all been conned. Apparently, although historical rises in CO2 do match rises in temperature, it's the rises in temperrature that drive the rises in CO2 rather than the other way round. I get the feeling that if this were the case, there would be a few more dissenting voices in the scientific community so I won't be going out to buy a mechanical hippo tomorrow. Even if it is true, the fact is fossil fuels will run out one day so we have to find alternatives, and the sooner we start to do that the better.

Sunday, March 04, 2007

Is Peak Oil here?

Apparently Saudi oil production was down 8% in 2006. I don't know enough about the subject to know if this is important or not, but it makes for interesting reading. http://www.theoildrum.com/node/2325

New template

I've finally taken the plunge and upgraded my template for the latest version of the Blogger software. I think the design looks much slicker and the template editing tools in Blogger look more powerful, although I haven't really done much with them yet. I've lost a few things from my template which I will be adding back when I notice them. Edit- Yes, the template editing is much better. Adding tags to posts is a pretty poor experience though. It looks much like adding tags in GMail but the usability is pretty poor. If you add a tag to a post, you're then sent back to the top of the first page of your posts after applying the tag. You can choose to show 300 posts per page but then it all gets very slow and after applying a tag to a post, the post remains selected. This means you have to trawl through all your posts again to find the post to deselect it before adding any other tags.