6

I have a large codebase that uses Systems Hungarian for most variable names, which basically means I have lots of objQueue's, objCommon's, dtDataSet's et cetera.

Is there any way to convert most of them? Especially, I want to get rid of irritating obj ones that have absolutely no sense, make variable names seem similar and the code completely unreadable.

There was a similar question but it was asking whether it's worth to do the replace.
Answers like “leave it as is” are not of any use to me because I'm definitely sure I need to do this.

The codebase is really large, and I don't want to rename variables one by one. Neither do I want to run Find & Replace because I'll get false hits and mess up code even further.

Is there any automated tool to make such replacements in Visual Studio? Some addin for Resharper, whatever?

Community
  • 1
  • 1
Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
  • Sadly, your best option is *probably* to write a plugin for ReSharper and use it's rich API to programmatically traverse all the declarations in your entire solution and apply an algorithm that can automatically perform the rename based on the name and perhaps contextual information like the declaration's type. Unfortunately, this is decidedly non-trivial and not for the feint of heart. – Kirk Woll Feb 22 '11 at 18:48
  • 2
    What argument did you use to get rid of hungarian notation at your firm? I want to know, because I want to use it at mine. I'm so tired of putting xyzzy in front of every freaking variable! – corsiKa Feb 22 '11 at 18:49
  • Oh, hopefully my company is modern enough :-). We are outsourcing company, but before us our client used to work with another company which left some Orient flavor in the code, if you know what I mean. – Dan Abramov Feb 22 '11 at 18:51
  • Would you get false hits even if you use regex to search for all occurances of words starting with obj followed by a capital letter? – Dean Kuga Feb 22 '11 at 18:53
  • 1
    @glowcoder IMO you don't need any better argument than a DO NOT quote from page 55 of seminal Framework Design Guidelines written by the .NET architects. The quote is "DO NOT use Hungarian notation." :) – Dean Kuga Feb 22 '11 at 18:58
  • @kzen: I'm hesitant to use search&replace because it doesn't know about potential conflicts. Example: sometimes I have `query` and `objQuery` in the same scope. I hope for an automated tool that would let me know about potential conflict and ask for instructions. – Dan Abramov Feb 22 '11 at 19:03
  • @Kzen wow - it doesn't get clearer than that! I found a link to it: http://msdn.microsoft.com/en-us/library/ms229045.aspx and I'm going to remember it. I'm a Java guy, but I know my firm is Microsoft Friendly, so it might actually hold some weight. – corsiKa Feb 22 '11 at 19:07
  • Right click, refactor, rename variable. –  Jan 09 '12 at 13:20

2 Answers2

2

Alas, but it seems like there is no bulk rename tool for C#.
Please correct me if I am wrong.

Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
1

One solution would be to use something like Visual Assist's rename feature.

Other than that, a very careful search'n'replace (with a build between each modification followed by a check-in into source-control).

Max
  • 3,128
  • 1
  • 24
  • 24