Tigraine

Daniel Hoelbling-Inzko talks about programming

Why Win7 succeeds where Vista failed

I’ve been running Windows Vista since it’s launch day and still think nothing bad about the operating system. It served me well for over 3 years now and I’d never ever go back to Windows XP.

Not so much because I hate XP: XP was my operating system of choice before in the day. But because I am a geek that loves spending money on hardware and who loves running the latest “shiny new thingy”.

And while everyone was disappointed with Vista, I loved it. When run on the appropriate hardware, it was exactly what I needed from a operating system: Fast, stable, secure and better than the one before.

But, most people hated Vista. Even my father who has absolutely no idea what an operating system really is came one day to me and said “Hey that dude told me Vista sucks, please don’t put it on my PC”.
And over the years I have developed numerous theories on why Vista was talked down by everyone, but I guess it was a combination of these three mistakes:

1: Biggest mistake:

Vista Capable.jpgThis badge was supposed to go on laptops that can run Vista, but won’t be able to deliver Aero and everything.
This thing spelled doom. We where still stuck in a time where 1 gig of ram was considered high-end (I was already running 2 at that time) and people threw this badge on lowest-end computers and laptops that wouldn’t even boot XP properly so preinstalled Vista was just awful.
Perfect scenario: Unknowing computer user boots up system, sees this alien thing called Vista that is so slow that he can’t get anything done. Guess who he will blame?

2: Vista Ready

This was supposed to tell people that this computer is able to run Vista with Aero. I actually once saw a 512mb Ram computer marketed as Vista Ready with just ridiculous hardware specs. While Vista Capable was a desaster – at least they admitted they won’t run it well. Vista Ready was even worse, most PCs that where sold with WinXP with the VistaReady sticker where nowhere near Vista specs, so once the free upgrade from XP to Vista came around people actually made their machine substantially slower than before, with only one thing to blame: Vista.

3: UAC

The two above where the thing that generally killed Vista, this third one was the last nail in it’s coffin. While even non-techies started hating Vista for 1+2, techies who had the machine to run Vista started hating it for all those prompts that popped up right in their face. Imagine all those people with the “I know what I’m doing”-attitude, running Vista for the first time and having to click this damn UAC dialog for 30 times a day.

Nobody actually cared that the UAC thing was only popping up because you are currently installing all your software back to the system, and that it almost went away after a week or so. All they cared about was getting this thing disabled or reinstalling WinXP on day one.

Vista was left in a spot where even regular users knew it as “the bad thing”, and where the techies where all in rage about how annoying Vista is to them. Now imagine Joe Average  walking up to a techie for computer advice, what OS would you think he’d get recommended?

The solution: Remarket Win7 as Vista

So, Win7 now is the one to deliver what Vista couldn’t because I never had the chance to do so. Win7 is just regular Vista but delivered to capable machines and with enough graphical improvements and tweaks to make it look like a real step forward even for the non-tech-savvy user. (Along with other improvements, but at heart it’s just a WinNT 6.X while Vista was WinNT 6.0)

And it is just so awesome, I can’t keep myself away from it any longer.
Unfortunately I don’t have a active MSDN subscription at the moment since I am a student again, so I am only enrolled in the MSDN-AA agreement through the imagineClub at Klagenfurt and we don’t get Win7 until after it’s release. But: We get Win7 RC1.
So while the RTM is already shipping and people are already updating/installing that through MSDN and TechNet I installed Win7 RC1 two days ago on my main machine as my main operating system.

It was the right thing to do, although people will call me crazy. I did an in-place upgrade from Vista-64 Business to Win7-64 Ultimate RC1 with absolutely no trouble. Once Win7 RTM comes out I would have paved the machine anyway, so the upgrade for now saved me the trouble of reinstalling everything and still allows me to enjoy Win7 in all it’s awesome glory.

If you are worried about driver compatibility etc: Don’t, Win7 is mostly the same as Vista under the covers so all the driver issues have been worked out with Vista already. I only had to re-install my network card driver since it didn’t come back after hibernation, but other than that everything has been fine on the two machines I upgraded to Win7.

Filed under windows-vista

DefaultValue attribute for Castle MonoRail

While reading through ScottGu’s announcement of the ASP.NET MVC 2 Preview 1 I noticed this rather interesting little feature that’s in there:

DefaultValue attribute in ActionMethod

MonoRail is much smarter about action methods than MVC so there are already things going on with default values through routing etc. But this particular thing wasn’t in the framework until now. So I took Ken Egozi’s sample about using IParameterBinder to implement the DefaultValueAttribute in MonoRail.

The result in syntax is identical to ASP.NET MVC 2 P1 and it was very easy to do:

public void Browse([DefaultValue("beer")] string category, [DefaultValue(1)] int page)
{
    
}

How is this done? Well, I suggest you read Ken Egozi’s post since he does a much better job at explaining that thing. Anyway, here is the code to make that happen:

using System;
using System.Reflection;
using Castle.MonoRail.Framework;

[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] public class DefaultValueAttribute : Attribute, IParameterBinder { private readonly object value; public DefaultValueAttribute(object value) { this.value = value; }

public int CalculateParamPoints(IEngineContext context, IController controller, IControllerContext controllerContext, ParameterInfo parameterInfo) { var token = context.Request[parameterInfo.Name]; if (CanConvert(parameterInfo.ParameterType, token)) return 10; return 0; } private static bool CanConvert(Type targetType, string token) { if (token == null) return false;

try { Convert.ChangeType(token, targetType); return true; } catch (FormatException) { return false; } }

public object Bind(IEngineContext context, IController controller, IControllerContext controllerContext, ParameterInfo parameterInfo) { string token = context.Request[parameterInfo.Name]; Type type = parameterInfo.ParameterType; if (CanConvert(type, token)) return Convert.ChangeType(token, type); return value; } }

Filed under net, castle, programmierung

Most annoying thing to ever happen: Configuration manager screwup

I think I was pretty close to a major nervous breakdown due to this one misconfiguration of my Visual Studio that I have no explanation for:

image

Imagine yourself trying to test some new behavior that according to your unit tests works, but simply refuses to work inside your web-app because the call to it hasn’t been compiled yet!

Breakpoints don’t get hit, changes don’t appear.. Mayhem! (Oh, and to top it off, since views aren’t compile you still see some of your changes, just not the ones in real code).

I first thought it’s some problem with the ASP.NET MVC project type, but eventually I noticed that if I don’t manually recompile the project none of my changes appear.

Way to go, I should have seen that yesterday instead of spending almost an hour hunting bugs where none where to be found.

Update: To add insult to injury I again forgot that checkbox turned off after taking the above screenshot.

Filed under net, programmierung

A better way to write enumerations

One thing I constantly struggle with is enumerations. They are inherently dumb, carry little more than one integer of actual information and usually mean a lot more than their name conveys.

Let aside Enumerations as method option flags (where they actually do make sense!), the usual line of business application will have these three enumerations somewhere:

image

Now, let’s ignore all the others our most basic example would be the Sex enumeration that has usually one but only one use: How to salute your user when communicating.

Like the obvious emails you get:

Hello Mr. Hölbling, we’d like to thank you for your …

You get the drift. If I’d perform a sex change someday the system should address me as Mrs. Hölbling (and actually, that type of thing is much more of a problem in German than in English, but anyway).
And the code to do that would look something like this:

string salutation = "Mr.";
if (sex == Sex.Female) salutation = "Mrs.";

Console.WriteLine("Dear {0} Hölbling", salutation);

In a typical web application you’ll be repeating this piece of code numerous times, since being polite doesn’t hurt. Where this would actually hurt is if you’d mindlessly copy&paste that piece of code wherever you have to greet your user. You’d be violating DRY and the guy maintaining your code in 2 or 3 years will find out where you live and kill you in your sleep some day.

What I’d like to see as a solution to this is to simply have a method living on that enumeration. Like:

Console.WriteLine("Dear {0} Hölbling", sex.GetSalutation());

And that’s possible, just not very convenient. You’ll have to emulate the enumeration through a class:

public class Sex
{
    public int Id { get; private set; }
    public string Salutation { get; private set; }
}

Should work like a charm, but you loose the benefit of typing Sex.Female when setting a gender. So here is how to make a class look & feel like a enum without the limitations:

public class Sex
{
    public static Sex Male = new Sex{Id = 0, Salutation = "Mr."};
    public static Sex Female = new Sex{Id = 1, Salutation = "Mrs."};

    public int Id { get; private set; }     public string Salutation { get; private set; } }

You can now do stuff like:

new User()
    {
        Name = "Daniel",
        Sex = Sex.Male
    };

And if you have added equality on the id (as you always should) you could make decisions like with real enumerations:

if (user.Sex == Sex.Female)
{
    //Do Something
}

Now you could even go ahead and subclass your Sex class and dump logic in there if you please. Hell, even persist that type to a database using NH and the WellKnownInstanceType as Fabio points out.

The full implementation of our above Sex enumeration is beyond the jump.

public class Sex
{
    public static Sex Male = new Sex {Id = 0, Salutation = "Mr."};
    public static Sex Female = new Sex {Id = 1, Salutation = "Mrs."};

    public int Id { get; private set; }     public string Salutation { get; private set; }

    #region Equality methods

    public bool Equals(Sex other)     {         if (ReferenceEquals(null, other)) return false;         if (ReferenceEquals(this, other)) return true;         return other.Id == Id;     }

    public override bool Equals(object obj)     {         if (ReferenceEquals(null, obj)) return false;         if (ReferenceEquals(this, obj)) return true;         if (obj.GetType() != typeof (Sex)) return false;         return Equals((Sex) obj);     }

    public override int GetHashCode()     {         return Id;     }

    #endregion }

Filed under net, programmierung

My Photography business

Projects

dynamic css for .NET

Archives

more