Best way to get rid of hungarian notation?

前端 未结 20 1167
萌比男神i
萌比男神i 2021-01-18 20:52

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 th

相关标签:
20条回答
  • 2021-01-18 21:07

    If you have a legitimate need to remove and change it I would use either the built in refactoring tools, or something like Resharper.

    However, I would agree with Chris Conway to a certain standpoint and ask you WHY, yes, it is annoying, but at the same time, a lot of the time the "if it aint't broke done't fix it" method is really the best way to go!

    0 讨论(0)
  • 2021-01-18 21:09

    I agree with @Booji -- do it manually, on a per-routine basis when you're already visiting the code for some other good reason. Then, you'll get the most common ones out of the way, and who cares about the rest.

    I was thinking of asking a similar question, only in my case, the offending code is my own. I have a very old habit of using "the bad kind" of Hungarian from my FoxPro days (which had weak typing and unusual scoping) — a habit I've only recently kicked.

    It's hard — it means accepting an inconsistent style in your code base. It was only a week ago I finally said "screw it" and began a parameter name without the letter "p". The cognitive dissonance I initially felt has given way to a feeling of liberty. The world did not come to an end.

    0 讨论(0)
  • 2021-01-18 21:10

    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.

    0 讨论(0)
  • 2021-01-18 21:10

    What would I do? Assuming that I just have to maintain the code and not rewrite it any significant way? Leave it well alone. And When I do add code, go with the existing style, meaning, use that ugly Hungarian notation (as dirty as that makes me feel.)

    But, hey, if you really have a hankerin' fer refactorin' then just do a little at a time. Every time you work on it spend ten minutes renaming variables. Tidying things up a little. After a few months you might find it's clean as a whistle....

    0 讨论(0)
  • 2021-01-18 21:10

    Don't forget that there are two kinds of Hungarian Notation.

    The original Charles Simonyi HN, later known as App's Hungarian and the later abomination called System Hungarian after some peckerhead (it's a technical term) totally misread Simonyi's original paper.

    Unfortunately, System HN was propagated by Petzold and others to become the more dominant abortion that it is rightfully recognised as today.

    Read Joel's excellent article about the intent of the original Apps Hungarian Notation and be sorry for what got lost in the rush.

    If what you've got is App's Hungarian you will probably want to keep it after reading both the original Charles Simonyi article and the Joel article.

    If you've landed in a steaming pile of System Hungarian?

    All bets are off!

    Whew! (said while holding nose) (-:

    0 讨论(0)
  • 2021-01-18 21:12

    I wouldn't make a project out of it. I'd use the refactoring tools in VS (actually, I'd use Resharper's, but VS's work just fine) and fix all the variables in any method I was called upon to modify. Or if I had to make larger-scale changes, I'd refactor the variable names in any method I was called upon to understand.

    0 讨论(0)
提交回复
热议问题