Removing Hungarian Notation from Java project
If you hate Hungarian notation for it’s unreadable format, you might experience hard time replacing it into standard Google Java Style variable notation. I found myself in this situation.
There are couple ideas of how to change that:
1. Manual refactor
Well, it is as simple as it sounds, it may work for small project but if you have couple hundred files plagued with disease it will not be practical to spend couple hours to change them all.
2. IntelliJ structural search and replace
It is common idea to replace variable names automatically with IDE. It is easy to work with structural search, it will find all mVariables but structural replace is broken. I filed a bug to issue tracker without response.
3. Writing custom script
If none of the above fit, our team came to conclusion that we must write custom script. And thats what my colleague did.
Feel free to customize this script, add prefixes to search for as necessary. You can run it in a test case.
Caveats:
- It will brutally replace hungarian notation in a given directory so be careful, have a backup.
- If you have field assignment from setter/constructor like
it will replace it with
instead of
so be careful and test your code. Such bugs can be found by running IntelliJ’s Structural Search with ‘Variable is assigned to itself’ lint.
Enjoy more readable code!