Thursday, August 09, 2007

C# 3.0 - Extension Methods

Think of extension methods as normal static utility methods you can add to any object.

Extension Methods can be defined in any class. There are only two things you need to do to define an EM. First the method must be public static in a static class, and you must add this to any parameters.

Example
public static class MyExtensions
{
   public static string AddNewLine( this string s )
   {
      return s += "\r\n";
   }
}

Usage

string s = "This is my Test";
Console.Write(s.AddNewLine());
Console.Write("I'm now on a new line");
Console.ReadLine();

This is a fairly trivial example, but I'm sure you are starting to see the power of extension methods.

In C# 2.0 days the above would be:

string s = "This is my Test";
Console.Write(MyExtensions.AddNewLine(s));
Console.Write("I'm now on a new line");
Console.ReadLine();

To my mind, the above is not as readible, but also you have to remember which utility class you put AddNewLine in, or more importantly another coder has to know which class you put the method in.

Microsoft suggest you should use your own Extension Methods sparingly and warns not to extend existing types that you don't control. This is because changes in the existing type could break your code.

I guess this is all logical stuff. I think that most people will use Extension Methods for adding utility functions to standard types, for example the one I can think of, off the top of my head would be something like ToInt() to convert a string to an Int.

Great Post

Here is a great post explaining the intangible benefits of Mac use. Gets especially insightful around page five ;-)

What do you want in a computer?

If you hate Macs, then don't bother reading on.

Anyone who reads this blog will know that I am a developer for a living, what's more I develop on Windows using Microsoft tools. Without a shadow of a doubt Visual Studio and in particular C# are the best tools for getting the job done. Period. Windows, well not so much.

When I get home, I just want my computer to work. I want to catch up on email, read and write blog posts, surf the net, watch video, listen to music and import, edit and view of Digital photos. I would estimate that 80% of computer users would have the same requirements.

I don't want to have to piss around making sure my Virus, Malware and Spyware apps are up to date and my computer is clean. I can't be arsed with my machine crashing when I'm half way through something. In other words I use a Mac. Now, I can respect people thinking they are saving money by buying a budget Dell or equivalent. I'm sure they are fine and do the job 90% of the time. More power to them. For the rest of us, I really and honestly don't understand why so many people persevere with Windows.

I think other than the fact that OSX just works without fuss and is virtually Virus and Spyware free, the biggest pro for getting a Mac is the bundled software. iPhoto, iDVD, iMovie, iTunes, GarageBand, iMail and iCal are brilliant. There are apps on Windows that do the same thing for free, but none of them are included with the operating system, or work as seamlessly.

There is a new version of the so called iLife apps out. Link here. Having seen what is on offer, I think that the new iPhoto could be the killer app to make Windows users switch. It automatically imports photos from your Camera and breaks them into Events, making it easier to view your photos. This with iPhoto's already impressive ease of use, speedy search and "it just works" factor will make viewing your photo library painless.

I know this sounds like an ad for Apple, but it's more wanting to let everybody know how much simpler life with a computer can be. If you've ever used an iPod then used any other MP3 player you will understand what I mean.

Wednesday, August 08, 2007

The future is Linq and Linq to SQL

I have been playing with VS 2008 Beta 2 all morning. Where to being. I will post some more specifics later but Linq - wow.

I have read some propeller heads not liking Linq to SQL, because it isn't a true ORM, whatever that means. Me, I like it. It gives enough abstraction to handle the meanial tasks, but gives me enough flexibility to let me do what I want, and not have to buggar around with config files.

Get used to seeing code like this:

var totalInvoiceValue = db.Invoices.Where( cust => cust.City == "London" ).Sum( cust => cust.ExtendedPrice );

In a nut shell, that is all you would have to do (once the mappings are setup and thats Visual) to get all the sum of all invoices for London. No more query strings. Very nice.

It is my intention to door some more posts around Linq as I get more into it, mostly so I can write down my thoughts as I find having to explain something in words help me get a better grasp of it too, and if it is useful to others along the way then all the better.

But until then, do yourself a favour and download the beta and start playing.

New iMacs Released

New iMacs here

Even though I am an unabashed Apple fan boy, I have to admit I was surprised at how cool the new iMacs are. Might even have to get one I think.

Not sure about the new keyboard, but I like the USB port at either end.

I would wait until Leopard comes out in the next month or two before getting one though. Oh and they'll run Windows just fine, trust me. I have just installed Visual Studio 2008 Beta 2 on mine and it runs great.

Friday, July 27, 2007

Tour de Farce

I have been into cycling since about 1995. I caught my first Tour on the T.V. around that time. I was captivated, awesome scenery coupled with the drama of the tour made for awesome T.V. I guess I was a little naive and really didn't know the dark under current that was perversive in the sport.

I watched year after year from then on. I loved Jan Ulrich's tour win taking the title of his team leader Barne Riis who was the defending champion. Richard Virenque winning 5 or 6 King of the Mountains in a row. Little Marco Pantani defying the odds with his awesome come back victory. Unfortunately, they were all caught cheating (well Ullrich "retired" before he could be found guilty but was implicated in a drug ring) the very sport they were supposed to love.

Then came Lance Armstrong and all was good with the world again. Even he, the most tested athlete in history, was tainted by the drugs. I firmly believe he was clean, but I'm an optimist. I want to believe.

After the on going fiasco with last years tour, it had to be squeaky clean this year. In every sense of the word. It was looking good. We had the drama of Vinokorov falling and then his heroic time trail victory and stage victory in the Pyrenees. Last year was almost forgotten. And then the bombshell. Vino and his team were thrown off the tour and he was found guilty of blood doping. Then today Rasmussen who was leading, was thrown off the tour for irregularities in off season dope testing. These two incidents are another slap in the face, in a long line of slaps in the face.

It's not the other riders, or the sponsors, or even the organizers of the tour that are hurt most. It's you and me, the cycling fan. The guys who will never make a bean from cycling, but race and train in the rain and the wind and the incessant attacks from Magpies in the Spring. All for the love of the sport. The drug cheats are killing it for everyone and have to be stopped.

What can we do?

We can hit the cheats were it hurts. In the pocket. We're the guys who buy the bikes and the wheels and the group sets and the team shirts, and show up to watch the pro's. There would be no pro cycling without us. So lets all make a stand. Let us agree, as cycling fans, to boycott the sponsors and teams of drug cheats. Lets not fuel the vicious circle any longer. We owe it to ourselves...

Sunday, July 22, 2007

Old Code

As I have posted previously, I am modifying some old Delphi code I maintain. It is usually a yearly thing. The client has some requests I procrastinate and do it at the 11th hour. I am not a procrastinator as a rule, but going back to Delphi from C# is very very painful, and something I don't like doing.

Looking through my old code is painful too. Most of the stuff I did between 5 and 7 years ago. I thought I was good in those days, but well I wasn't as good as I thought that is for sure. It seems looking back, that I didn't fully grasp OO. Also I seem to put code in utility type files - just source code files with procedures and functions that don't tie in together. I see now that most of the code should have been wrapped up in classes but for some reason I didn't.

Would have made my life a lot easier now that is for sure.

It's a worthwhile and humbling experience to go through some old code. It makes you realise that there is always room for improvement and learning. I bet in 5 years the code you did yesterday that you thought was awesome will look just as bad 5 year old code does today.

A little reminder that taking a step back from your code and thinking about what you are doing is always a good thing...

ModelMaker Explorer

Recently, I have been coding in Delphi again. I have to take some code (mine) and refactor. In standard Delphi it's not a pleasure. I am using D7 which is getting a little old now, but I prefer it over 2006 which I also own.

I purchased ModelMaker Explorer to help out. It comes highly recommended. I bought it for refactoring features, but it has a ton of other useful features too, such as live metrics. I haven't checked out all the features yet, but at 95Euro it is a bargain. I wish I had bought it years ago.

Wednesday, July 04, 2007

If apple designed everything

Link Here

It appears to be in Italian, but you get the idea.

Friday, June 22, 2007

QuickSilver

Hey Windows freaks. Beat this.

In all seriousness if someone did code this for Windows it would rock.

Would have to be in WPF to match the "cool" factor of OSX transitions and visual/animation effects, but it could be done.

Until then you can either be jealous or buy a Mac. Do the latter you won't regret it. Trust Me.

Tuesday, June 19, 2007

Sometimes normalising data is a pain

We've all been there. Inherting some piece of crap Access app that was designed by someone who did a 5 minute polytech class. All the data is stored in one table or replicated in several tables. Above all else it's a nightmare to code against.

Of course databases like this could do with some normalisation. But sometimes, we can go a little too far. I am currently involved with a project to track data through a system and display eta's and other information on several display monitors around the physical location, to give workers a better idea of current state of play, allowing them to make better judgement calls. (can't go into specifics here).

At several locations along the route, there data is retrieved using some equipment. Each piece of equipment has a unique 6 character Id and posts information in real time to my app using tcp/ip sockets, with the 6 digit Id as the reference.

A process then filters this raw data and stores it in the database, with the primary key being the 6 digit char. Ok so far. At several points along the route decisions are made and data is manipulated and stored in another table for use by the seperate display process.

Against this spec, I start coding the system. I am lead developer on this system, but the overall lead (wrote the spec) is also designing the database. At some point he decided to normalise the data a little and move the 6 digit Id into a table of its own with an integer primary key.

This is fine, from a database point of view. It might be possible in the future that the Id field changes (6 digit char one) but not very likely. About as likely as Steve Jobs owning a Zune, likely.

So by normalising the data, my job as a developer has increased. A lot. First of all, my classes need to be rewritten to incorporate a int id field. ( I do this by hand - shoot me ), then my code needs to be rewritten to include joins to this new table . A simple change on the database creates a lot more work.

Some people at this point may argue that the design is at fault, or you shouldn't code against an incomplete db schema. This may be true. However in this system the int id field is meaningless, so I have to access two tables everytime, instead of just checking against the raw data. Ok, we may save a miniscule amount of space on the database server, but really, is it worth the extra effort, especially considering how cheap cycles and space are these days?

Normalisation, is good. But before you do it to the nth degree, it needs to weighed up against the system as a whole. Just because a DBA prefers fully normalised data, doesn't mean it should be done.

Wednesday, June 13, 2007

Safari Buzz (and fud)

There has been a lot reported about Safari 3.0 (beta) being available for Windows today. I have been running it all morning with few issues. However, if you're a Windows head, it seems to be the thing to do to bash Safari.

I think a lot of these people should remember ITS A FRICKEN BETA.

Also, if these people hate Apple so much, why are they so interested in this? I think thoust doth protest too much.

Tuesday, June 12, 2007

And now with Windows flavour

Just finished catching up with the WWDC Keynote address by Steve Jobs. Nothing earth shattering announced unfortunately. Leopard, OS X 10.5 looks very nice though. Makes Vista look a little tried. All features etc can be seen Here

The one interesting thing announced was that Apple have release a new version of Safari, that is also Windows compatible. According to (Apple) benchmarks it is the fastest browser available today. Download it here. If nothing else it makes it easier to test Websites on Windows. Until now the only way to test on all browsers was to have a mac and install Parallels or Boot Camp.

I guess it's a double edged sword. On one hand it makes it easier to make websites Safari compatible for Windows developers. On the other hand it takes away one excuse Windows developers can use for justifying a mac purchase. Not that one is needed, but Windows users are a little slow, lets face it....

Parallels for Mac 3.0 Review

I upgraded my version of Parallels to version 3 as soon it was released on Friday. The major draw card for me was 3D graphics support. I like to play the odd Windows game from time to time, so this is a major(ish) feature.

There are a slew of new features, including the ability to boot a Boot Camp partition within Parallels.

Install was fairly painless. I have a XP parallels image and a Vista boot camp drive. I tried both. I didn't notice any real world difference in my existing XP image to be honest. My Vista boot camp image loaded nicely within Parallels. It has to load some drivers to the OS first and requires a couple of reboots first, but it up and running within 10-15 minutes.

The Vista image running under Parallels had Aero turned off, and I couldn't get it running even with Direct3D support turned on. It run pretty sluggishly too. Quite a bit slower than native boot camp. This is understandable I guess but a little disappointing. I think it is down to memory issues with Vista (my version is Premium or Ultimate or wtf it's called) as much as anything else. My machine is a Macbook Pro @ 2.16Ghz and 2Gb Ram. The image had 1.5Gb ram allocated to it.

My advice would be unless you absolutely need it don't run Vista in Parallels.

XP runs as fast as native under Parallels, in fact, running in full screen it would be impossible to tell it wasn't running native, using real world / seat of pants benchmarking.

3D Gaming
The marketing blurb on the website says, "New! 3D Graphics lets you run today’s most popular PC games on a Mac". This is a little misleading.

I downloaded a demo of Star Wars Lego II and it crashed on the menu screen. There is a list of games on the website, one of which is Quake 4. I downloaded the demo - I also downloaded the native Mac version, but haven't benchmarked yet.

Quake worked fine, but in game fps was hovering around 14-18 on average. I had medium detail turned on, with shadows but no AA, running @ 1082 x 768.

I will benchmark against native Mac version be commenting. I would have thought however that 14-18fps would be quite low however.

Overall, Parallels is great and I recommend it to anyone. Word on the street suggests that something similar may be built into Leopard. Time will tell on that front.

I would hold off on buying or upgrading, until after the WWDC which starts today (11/06/2007) as this info will become more clear then. Also, if you are looking to run the latest PC games, I still think dual booting with Boot Camp is the best way forward.

Friday, May 25, 2007

Life changing gadgets

On the back of Nics blog post about a Scott Hanselman blog post I thought I'd add my 2c, sorry 2p worth.

In no particular order:

  • Macbook Pro

  • I'm a born again Apple addict (as I keep telling anyone who will listen). I was getting thoroughly sick of wasting my time rebuilding Windows PC's after 6 months because of slow down, and generally getting sick of Windows. After 3 months with a Mac, my passion and excitment for computers is back. Every geek should have at least one Mac.

  • Sky+

  • Ok it's hardly bleeding edge and I should get around to getting a "proper" DVR, but being able to record two Sky channels at once, live record, and season link is brilliant.

  • iPod Video

  • Watching webcasts and listening to podcasts while commuting to work is a god send here in Britain. I didn't really understand how great these things were until I got here. I do think people use them to hide behind, so they don't have to talk to strangers on public transport but I guess that's a good thing for those people. They say copying is the greatest form of flatery, then take a look at most other MP3 players and Apple should feel very very flattered indeed.

  • Wireless Internet


  • Not really a gadget but hey it's my list. Life before Wireless broadband sucked. Surfing in a dark, dingy, cold computer room. Now I can surf infront of the box and talk to the missus! Actually the Internet in general is IMHO the single greatest invention in the history of the world. Don't agree? Ok think about your life now. Now take the internet away. Sucks doesn't it. Communication, Information and Entertainment has been changed forever because of the Internet. I was a programmer before the Internet, but can't remember too much about those days. Man it must have been hard getting information. These days a quick Google finds the solution to most issues. Huge productivity gains there I think!

  • Amstrad CPC 464


  • This little machine started it all for me. I got an interest in computers and programming because of that little 8 bit machine. Who knows what I would have been if I hadn't met the Amstrad, but I can genuinely say that my life would be completely different. So the Amstrad must rate as number 1 on my list of life changing gadgets.

Thursday, May 24, 2007

Wednesday, May 23, 2007

Notice to Microsoft - Stop. Stop now.

Silverlight, Linq, Astoria, even .NET 3.0 are all either out or on the horizon.

I want to learn all of them, but with the need to: work, commute, eat, sleep and spend time with the family - there just isn't enough time in the day. So I say to Microsoft, stop now. Let me catch up ;-)

As a born again Mac fan boy I am pretty buzzed about Silverlight 1.1 and all it entails. Hopefully it will give all those devs out there that are bi curious (Mac and PC) an excuse to buy a Mac - testing silverlight apps on Mac!

Technologies like Silverlight and to a lesser extent WPF are creating a paradigm shift in the world of software development. It won't be long before you need a designer and/or user experience person on your team. Hopefully it will mean a richer experience for the user and nicer web sites and apps to use.

And it will allow developers to get back to what they are good at - developing. To often websites are either designed by developers or developed by designers. The end result can be disastrous. I mean you wouldn't get your dentist to remove your appendix?!

New Zealands greatest export

The pilot episode from the FOTC new US TV show is up. Funny.

http://www.hbo.com/conchords/

not sure how it will go down in the States with the dry humour but hope it goes really well.

Wednesday, May 09, 2007

My first play with Oracle

On the current project I am working on, I have been introduced to Oracle. I have never come across it before - usually use SQL Server in various guises.

The installation process was a little harder than SQL Server, as the server we had been supplied had Java locked down on it. Basically the installer wouldn't run as it's a Java app. A boffin managed to find a work around and got it installed.

I guess being multi platform is a good thing - but to me the Java interface looks dated and is a lot slower than a native Windows app. The actual interface itself is a little clunky also. I don't believe it's as intuitive as SQL Server 2005 for example, although I am a lot more familiar with SQL Server.

Once you get up and running though, it's not too dissimilar than SQL Server. I did read an article talking about update-read locking and how Oracle allows users to read data on pending updates. I guess the thought process is that the update may never happen so why lock a process from reading. I guess it's a good feature to have that option. SQL Server just locks the read in that scenario.

From a front-end point of view the two are the same - I use the new .NET 2.0 data factory pattern (System.Data.Common) when connecting to databases anyway, so from that point of view nothing in my code is different for use with Oracle or SQL Server (or mySQL or any other db for that matter).

Anyway, so far no real issues with Oracle. I much prefer SQL Server, but I guess that is more to do with familiarity than any negative aspects of Oracle.

Friday, April 13, 2007

I.T. Interviews

As some of you may know we packed up and left NZ and moved to England about a month ago. I decided to go contracting as it allows greater freedom and more money! There are downsides too of course (discussed on my other Other Blog

Anyway, as such I have been to a few (3) interviews and 2 phone interviews over the last few weeks and thought I would post my views.

The Process
Interviews suck, lets face it, but some suck more than others. It is common these days to vete applicants with an initial phone interview first. This to me is fine and makes sense. I have no problem with phone interviews.

Then it seems it is becoming more and more popular to do an online "skills" test. I think these are a complete waste of time. I (and others) consider myself to be an above average developers, and I have over 10 years experience, in several languages, platforms and more importantly, business areas.

Quite frankly the stupid online tests can hope to test me on my experience. The ones I have done are a multi choice question and answer type thing. All this tests in my opinion is how well you remember semantics outside the IDE. I have pretty much been developing since Intellisense, and have (I admit) become lazy. It doesn't mean I am a bad developer, in fact in my opinon the opposite. I let the tools do the donkey work, while I am concentrating a creating a solution.

I once interviewed for a job at HP. They had the best test I have ever seen. It was a real world scenario to finish an application. It gave the testee the opportunity to really show what they were capable of, and let the testers see some code and see how the person thinks. (I didn't get the job, but was the only person to ever finish the test. Didn't get the job for other reasons than soft dev ability BTW)

I think the HP style test is the only way to go. Test people by all means, but don't make them do stupid little multi choice Q+A tests. They really are wasting everybodys time.

Tips
If you make it to the face to face interview, make sure you have are prepared. Do some research on the internet about the company, and have some questions in your mind to ask them.

I find if you ask questions along the way, it makes you :
a) seem more intested in the company
b) look intuitive and knowledgable
c) seem well prepared

Also, run through in your head some questions they may ask you, and have some answers sorted out. It helps relieve the tension.

Don't put anything on your C.V. you can defend/explain in an Interview. You may have played with Javascript before but don't make it look like yuo are an expert. It will come back to haunt you as most interviewers will ask questions based on you C.V.

Above all enjoy it.