Wednesday, March 29, 2006

For sale: Several IDEs, one careful owner

Who will buy Borland's IDE products? My guess is no-one, certainly nobody who's actually interested in the IDE business. Somebody who wants some talented programmers perhaps but why would anyone in their right mind get into the IDE business. Delphi is a great product but it has some serious competition from Visual Studio, which is a loss leader for Microsoft. MS owns .NET and wants everybody to use it and doesn't much care if it makes money on its IDEs. Visual Studio Express is free and is probably good enough for quite a few people. Look at the figures in the UK for Delphi and C# jobs, Delphi is on life support. It is still the best development tool for native Windows desktop applications, but how big is that niche and how fast will it disappear? The other tool that may be of interest to buyers is JBuilder but that is losing out big time to Eclipse, because it's free and good enough. So good luck Borland and good luck Delphi, it was fun...

Friday, March 24, 2006

Beware the ribbon

Jensen Harris has convinced me that the new Office user interface will be lightyears ahead of the current one. But I'm going to make a prediction. I reckon soon we'll see almost every new Windows application adopting the new ribbon UI. But you need to remember that the ribbon has been created to solve a particular problem that Office suffers from. It has hundreds if not thousands of different commands. The average application doesn't have that many and the traditional menu and toolbar is still sufficient. So please spend your time fixing bugs and adding new features rather than adopting a new UI that you don't need.

Tuesday, March 21, 2006

Formatting C# code for a blog

This C# code formatter does the business. Much better than the manual fiddling I was doing before.

Creating thumbnails in ASP.NET

.NET makes some things really easy and creating thumbnail images for a website is one of them. Here's the code I'm using on one of my websites.
 private void CreateThumbnail(string fileName)
 {
   string physicalThumbFileName =
     Path.GetDirectoryName(Page.Request.PhysicalPath) +
     "\\images\\" + fileName + "_thumb.jpg";
   if (!File.Exists(physicalThumbFileName))
   {
     // create thumbnail
     using (Bitmap img = new Bitmap(ImageFileName(fileName)))
     {
       using (Bitmap smaller = new Bitmap(img,
         new Size((img.Width*120)/img.Height, 120)))
       {
         smaller.Save(physicalThumbFileName, ImageFormat.Jpeg);
       }
     }
   }
 }
The thumbnails are created when the page needs them, thus simplifying the upload process, since there's no need for any manual thumbnail creation.

Thursday, March 16, 2006

SEO works, but it shouldn't

It all started about two or three months ago. I got into an email conversation with the webmaster of a website doing a very similar site to the Random Pub Finder. He claimed to be getting about three times as many hits as we were. After looking at his site, I thought the site (to my eyes at least) was no better than ours (and I'm not talking about Beer In The Evening which is clearly better) so I couldn't work out why this was. After talking to a couple of SEO gurus I started making a few changes to the site and over the last couple of weeks or so, we've started to increase our hits. In fact, we are now getting about the same number of hits as he was claiming to get. Now this may not be entirely due to my changes, the search engine algorithms may have changed along with a whole host of other things. But if it is down to the SEO changes, then the search engines have a lot of work to do to optimise their search algorithms. For instance, why should putting the title of the page in a h1 tag make a difference? Surely the search engines should be clever enough to realise any old tag (a div for instance) with the correct style applied will look just the same. Why should h1 be considered as special? So search engines still have a lot to learn. People who put content on the web shouldn't need to know the special magic they need to apply to their pages to get attention. Until SEO gurus are no longer required, search engines will not have perfected their art...

Friday, March 10, 2006

The Road To Guantanamo

I've always followed the career of film director Michael Winterbottom since he went to the same school as me. He directed the great '24 Hour Party People', chronicling the coolest record label of my teeenage years. He also did '9 Songs', the most sexually explicit film to get a certificate in this country, a record that I'm sure will be highlighted in the school's old boys' magazine... Anyway, I saw his latest, 'The Road To Guantanamo', last night and it was great, in a horrendously depressing kind of way. Yes, the 11th of September attacks were horrific but can that excuse the kind of treatment that was handed out to these people (and is still being handed out to the 500 people still there). We protect our democracy by ignoring all the rights that democracy confers on people? Of course it can be said that the film isn't entirely objective, based as it is on the accounts of the inmates. But since the US doesn't seem too keen on letting anybody else in there to see what's really going on, it's all we've got. Required viewing for anybody who still thinks Bush's war on trrrr is worthwhile.

There's a reason they are called exceptions

Whenever you read about exceptions, one of the key points is that exceptions should only be thrown in exceptional circumstances. An example might be when a file the application can't survive without doesn't exist. However I've seen on several occassions now exceptions being used where the particular problem could be expected to happen on a fairly regular basis, if not every time the application runs. A common example can be found when trying to convert a string to an int. In .NET 1.1, int doesn't have a TryParse method so a quick and dirty approach to implementing similar functionality might be as shown here
int val = 0;
try
{
  val = int.Parse(stringVal);
}
catch (FormatException)
{
}
This solution can be fine when stringVal will generally be a valid int, but if it's used when stringVal is often not a valid int (when reading the value from a config file that by default doesn't contain any value for instance), it can become annoying. Why's that then I hear you cry? Just turn off breaking into the debugger when an exception is thrown and all is well. Well perhaps but I always want to break into the debugger when an exception is thrown. Why not just break into the debugger for unhandled exceptions? Because my applications have a global exception handler to do logging etc when an unexpected exception is thrown. So turning off breaking into the debugger when an exception is thrown means I never break into the debugger for any exceptions, which is less than ideal. When developers follow this pattern too often, it can actually become increasingly difficult to ever break into the debugger when an exception is thrown. The IDE option can be become impossible to switch on because the developer is thrown back into the IDE so often. When this happens, we've lost a very useful tool and our debugging becomes much more difficult. Having the option always switched on means we are more likely to find those obscure bugs that only happen once in a blue moon. Another point to make is that this kind of exception handling can affect not only the developers working on your project but developers working on something completely different. I've been working on an ASP.NET project that requires me to run another ASP.NET project at the same time. This other project uses a very similar technique as that shown above which constantly throws me back into the debugger when I'm working on my own project! So how to solve the problem? In the case of the code above, there are probably several solutions, although they will all require some work. Checking for an empty string often solves the problem in 90% of cases, whilst doing some kind of check of the characters in the string would cover the other cases. For most other scenarios where an exception will be thrown, there is almost always a different implementation approach that does not require exceptions.

Wednesday, March 08, 2006

The Doogal Effect

No, no, no, not the effect I have on people, but rather how the release of the film 'Doogal' (based on the drug-fueled children's programme 'The Magic Roundabout') has affected the hits to my home page http://www.doogal.co.uk. See that spike? That was the weekend it was released in the US. And it looks to me that it hasn't been too successful since my hits are already back to normal...

Friday, March 03, 2006

Does PageRank matter?

For some reason, the Random Pub Finder has now got a PageRank of zero. I'm not entirely sure what we've done to upset our lords and masters, but it doesn't seem to be having a negative effect on the number of visitors we are attracting. In fact, visitors are up and most of them are arriving from Google. So I won't take it personally...

The IT Crowd

Written by the same bloke who wrote 'Father Ted', starring Chris Morris and being about IT people, how could 'The IT Crowd' fail to deliver? Well it was reasonably amusing but was never quite the sum of its parts. I think the basic problem was that to hit the mark it would need to make techy jokes that would be lost on the general population. So the fact it is about IT people is kind of irrelevant, it's just another bunch of misfits in an on office sitcom. Saying that, I watched every episode, which is unusual since I don't really watch the telly anymore (unless you count CBeebies). The ending suggested there'll be another series, so perhaps that will allow the characters to grow somewhat.

Monday, February 27, 2006

Serialization considered harmful

The ability to serialize an object can be a very useful feature of a language or framework but there is a trap that developers often fall into when they first discover this functionality. Almost every app we ever work on requires some kind of file format to store information about the document the user is working on. So a developer will often think to themselves "This serialization stuff will save me heaps of time. I can serialize my object hierarchy with two lines of code when I need to save the document and deserialize it when I need to load the document". This way madness lies. Once you do this, your file format is completely dependent on the internal class structure. Want to change a property name or type? Bam, your file format is broken. Want to remove a property? Bam, your file format is broken. In fact, in .NET adding a new property will break your file format. Delphi is different in this respect since it will cope with adding new properties, but whether that is a good thing is open to question since it may tempt you into thinking this is a viable approach. A Delphi project I worked on used this approach for many years and it kind of worked, at the expense of being able to do any meaningful refactoring during the many years of its development. So if serialization is such a bad thing, why is it even in Delphi and .NET? Because it can be exceedingly useful. For instance, passing objects between processes, copying and pasting to the clipboard. Essentially, serialization is useful for short-lived operations. When things are written to file and we need to worry about backwards compatibility, serialization is not you friend.

Monday, February 20, 2006

Make your own radio station on the net

There are a couple of great sites that can help to find new music. First up there's Pandora that creates a radio station based on an artist or song name you choose. It works out songs based on the characteristics of that first choice, and can then be trained by giving the thumbs-up or down for particular tracks. The other site is last.fm. This seems to use various methods to choose similar songs, like accepting cash from record companies (just like a proper radio station then). It also plugs into your media player of choice which is probably pretty handy, although I've not checked this out yet. It's also a bit more of a community since you can tag songs and join groups and all that kind of stuff.

Thursday, February 16, 2006

Search engines still have a lot to learn

I found out today an interesting little fact, Google (and other search engines I presume) are not omnipotent. There is a very simple way to trick it into rating pages higher than they should be. Just put some text in a noscript tag and Google will use the content in their indexing, but it isn't visible to browsers that have enabled Javascript which, let's face it, is most of them. So a dodgy website can use this technique to include references to a competitor and be in the listings when a web user does a search on their competitor's name. I can't say more than that since the specific example I'm aware of is currently in the hands of lawyers, but it will be interesting to see how it pans out. BMW in Germany were banned for a few days before Google re-included them in their index, so I'd like to see how a much smaller company (probably not paying Google any advertising fees) is treated. To see an example of this in action, take a look at http://labs.tn38.net/google_noscript/, a page with an image and content in a noscript tag. Now do a search for Google noscript and see that the page has a pretty damn good ranking.

Friday, February 10, 2006

Have you heard of Windows XP?

Windows XP came out about five years ago, but looking at some of the software around you'd never have guessed it. Here's a dialog box from IE7, a pretty new application in anyone's book and yet it still has remnants of Windows 2000 even now. I'll let it off since it's still in beta but it's hardly the only example of the retro look. The depressing thing is it is so easy to make sure your application uses the correct XP controls. Just search for 'XP manifest' and all will be revealed. In the simplest implementation, your app doesn't even need to be recompiled and it will take about 5 minutes to get up and running. OK, a bit of testing will be required and those screenshots in the manual might need updating but it isn't a big job. So just do it. Not doing it suggests you haven't got the attention to detail required to write a decent Windows application.

Thursday, February 09, 2006

Google Sitemaps still smoking strange substances

So this week, Google Sitemaps tells me some of the best search terms to get to my site are "sex thixx game", "thixx game sex" and "thixx sex". I just wish it were true, I'm sure my hit count would be soaring... Saying that, my hit count has been soaring due to the film 'Doogal'. For some reason, the film of the drug-addled TV series 'Magic Roundabout' has been renamed for the American market. Not only has it been renamed after the main character Dougal but they've also changed the spelling of his name to Doogal. So I'm get lots of random people hitting my site. Unfortunately they aren't clicking on any of my ads, so I'm still not a millionaire...

Tuesday, January 31, 2006

Staying unfocussed

I read somewhere that blogs should stay focussed on their primary topic. Well, I'm not sure what my primary topic is and even if I did it's much more fun talking crap (that nobody reads) about various different subjects so I shall be remaining resolutely unfocussed.

string.Concat vs the + operator in C#

I was in an interview last week and I was asked what were the three ways of concatenating a string in .NET and which I would choose to use. I could only think of two, using the + operator and using a StringBuilder but guessed there must be string.Concat as well, which I've never used. I said I'd use a StringBuilder in code that got called a lot or a loop and I'd use the + operator any other time. The interviewer told me the + operator had some serious performance problems and I thought "does it???" So I thought I better investigate. I wrote a simple app to concatenate strings and checked in Reflector to see how using the + operator and string.Concat differed. The first thing to note is that the string class doesn't actually overload the + operator and looking at the IL for my app, the + operator version of the code, by some compiler magic I presume, actually got converted to calls to string.Concat. The IL in both cases was exactly the same. So I'll stick with "a" + "b"...

Monday, January 30, 2006

Arctic Monkeys are the best band in the world apparently

So if CD sales are anything to go by, Arctic Monkeys are a brilliant new band. I've listened to their album and it's not bad and I'm sure if I was ten years younger I'd probably think it was superb, because it's loud and in-yer-face. But the quality of the music isn't what really interests me. Here's a band that got started by letting people download their music from their website and are now have the fastest selling debut album of all time, on a tiny indie label. There are so many lessons for the big music labels here. Like, perhaps this new-fangled internet thing might actually be a useful marketing tool, rather than just full of evil-doers trying to rip off your music. And perhaps if you were actually doing your job of looking for new talent instead of suing your customers and infecting their computers with rootkits, you might have actually noticed this band and signed them. And considering internet pirating is "killing music", 360,000 copies of a CD sold in a week isn't bad going. I could go on, but I think you get the idea.