Daily Archives: March 16, 2007

Back from Hungary

No i’ve not been on a sly holiday without telling anyone, more I’ve decided to undo one of the bad habits I picked up in my previous job (Scott i’m blaiming you)

While I call it a bad habit it’s not really, well not in the right context.

Let me explain for the non techies that read the site,

If your Techie and know why i shouldn’t be using Hungarian notation you can stop here ;)

 I’m talking about something called hungarian notation. Basically when your writing software generally it works to adhere to a standard format, so that when i read some code that someone else on the team i don’t have trouble understanding it and vica versa. However one of these techniques has become unfavourable.

It basically says that before a name of a variable, which is a name for a place where you have stored a value, you should put a prefix to say what type of variable it is.

i.e. if i have a statement that says x = 1, where x is an integer (a whole number) hungarian notation states that x shouldn’t be called x, it should be called iX, and then some other rules would come along and you couldn’t call it X (What does x stand for? what does it mean) so for example if it was to store the value of a power regulator switch youd have to call it iPowerRegulatorValue

All good if you ask me.

But with the move to something called until you get a new law that comes along and say that you shouldn’t have two places where you say the same thing. (Called DRY [Don't Repeat Yourself])

now if i hover over the variable in my editor it tells me what type of variable it is.

so i’m repeating information between two places, so i should just be calling the variable powerRegulatorValue.

Also with hungarian notation in .net you tend to call everything objects, so you get a lot of variables that start with obj, a waste of space.

So now i’ve been through all my code i’ve written for ASP.net Fitnesse and taken out all the hungarian notation.

I might find myself doing it again, but hey as long as we keep to standards amongst ourselves, what harm can it do?

Tagged
Follow

Get every new post delivered to your Inbox.