Monday, June 20, 2005


Rule 11: Hungarian Notation is bad

Its quite easy to show why Hungarian notation is bad, and its a point that is often missed in the religious wars on the subject.

If you were designing a database or even an Excel spreadsheet, it would be an awful spreadsheet if the user had to enter the same number in lots of cells.

The principle that should be followed is to have one cell storing the data and refer to that cell. ie. Store the data once.

Hungarian notation goes against that priciple. Instead of storing the type of something in one place, its stores it everywhere it is used.

Dim icRow as Integer
icRow = icRow + 1

Here the type, an integer counter is stored and repeated everytime the variable is used instead of once, in the dim statement.

If you want to change the type to a long, you have to change the dim, and everytime its used. If you code is used by others, its a real problem. Just your own code is bad enough.

Instead just do this.

Dim row as Integer 'index to the rows in the range
row = row + 1

Then you can change the type in once place and one place only.
The intent comes from the comment.
Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]