5 ms·
"* no easy refactoring. In VS i love how i can just hit F2 on a method name, rename it, VS shows me all the places where it will rename it and pressing OK. This
by mjdwitt 15y ago
"* no easy refactoring. In VS i love how i can just hit F2 on a method name, rename it, VS shows me all the places where it will rename it and pressing OK. This works flawless everytime and makes refactoring so much more painless than working with a scripting language and a text-editor only"
Using vim (or sed for whole directories of files) you can do the same thing using a search and replace regex.
in vim:
:%s/<find>/<replace>/gc
- gnaritas 15y agoThat's not at all equivalent.
- mjdwitt 15y agoHow so? I haven't used VS since a couple of versions ago and never got to know it very well, so I based my above comment on the OPs description; if there's more to the feature than I could easily be wrong.
- arethuza 15y agoThe vim command is doing a search and replace over all text - Rename in Visual Studio will restrict the change to class/method/.... name definitions and calls to them.
- mjdwitt 15y agoAh, so instead of having to hand-roll your own really complex regex that would limit the scope every time, VS automatically limits the scope of the renaming for you. That is pretty nice.
- bronson 15y agoIt isn't about limiting scope, it's about parsing and understanding the language. A refactor can change every file in your project (for example, renaming a global variable named 'i'). And, yes, it is very nice. Eclipse comes close with Java but, last I tried Vim and Emacs refactoring plugins, they were nowhere near as good or even very discoverable/usable).
- henrikschroder 15y agoNo, you operate on different levels. A regex replace works on the text of your source files, a refactoring rename in Visual Studio or Eclipse works on the symbol.
- gnaritas 15y agoGlobal search and replace casts a wide net, makes tons of mistakes, requires you to inspect every change to ensure it was correct; automated refactorings don't make any mistakes no matter the size of the code base. These two things are vastly different.
- philwelch 15y agoYou don't review automated refactorings?
- phpnode 15y agoActually in jetbrains IDEs you preview your automated refactoring, before it happens. It will show you which files will be affected and how, and then you can choose whether to exclude specific instances or not. Code review happens anyway, automated refactor or not
- gnaritas 15y agoYou certainly can; however, you'll stop after a while when you realize it actually works.
- bermanoid 15y ago...which works great until you have to rename a field with the name 'value' in one particular highly-used class in a system with ten-thousand classes, many of which will also have fields named 'value'. That's where actual IDE knowledge of the language semantics is more or less required, to be able to track the actual object being referenced based on the particular imports, inheritance hierarchy, etc.
- Roboprog 15y agoWell, one way to do it would simply be to rename the field, then make/ant/maven, and then visit the error lines, especially if you can feed the compiler error messages back into your editor to auto-navigate. Not instant, but not intolerable.
- kayoone 15y agothats works for some cases but can by no means be described as "works flawless everytime" like the refactoring features of modern IDEs!
- jiggy2011 15y agoThe thought of doing global search and replace across an entire codebase (or even a section thereof) gives me a knot in my stomach. Hope you have very good unit tests.