Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to get rid of hungarian notation?

Let's say you've inherited a C# codebase that uses one class with 200 static methods to provide core functionality (such as database lookups). Of the many nightmares in that class, there's copious use of Hungarian notation (the bad kind).

Would you refactor the variable names to remove the Hungarian notation, or would you leave them alone?

If you chose to change all the variables to remove Hungarian notation, what would be your method?

like image 321
Robert S. Avatar asked Oct 13 '08 19:10

Robert S.


People also ask

What is wrong with Hungarian notation?

Some potential issues are: The Hungarian notation is redundant when type-checking is done by the compiler. Compilers for languages providing strict type-checking, such as Pascal, ensure the usage of a variable is consistent with its type automatically; checks by eye are redundant and subject to human error.

Is Hungarian Notation good?

In general, Hungarian Notation has fallen out of fashion. In strongly-typed languages, it's broadly redundant, especially the Systems Hungarian type. It can also make code more difficult to read. Any problems it might help solve are often signs of deeper flaws, such as an over-reliance on global variables.

What is Hungarian notation in Java?

Hungarian Notation (HN) is a naming convention that was originated years ago by Charles Simonyi of Microsoft and is used throughout the source code of the Windows operating system, among other places.

What is Hungarian notation example?

In Systems Hungarian notation, the prefix represents the actual data type of the object. For instance, if the object named Greeting were a zero-terminated string, its Systems Hungarian name might be szGreeting. Or, if the object YesOrNo were a boolean variable, its Systems Hungarian name would be bYesOrNo.


1 Answers

Refactor -- I find Hungarian notation on that scale really interferes with the natural readability of the code, and the exercise is a good way of getting familiar with what's there.

However, if there are other team members who know the code base you would need consensus on the refactoring, and if any of the variables are exposed outside of the one project then you will have to leave them alone.

like image 128
Rob Walker Avatar answered Sep 28 '22 10:09

Rob Walker