Hacker News new | ask | show | jobs
by RealityVoid 21 days ago
Yes, it's copy pasting but it's tedious and it adds up fast.

Even the doFoo to performBar is tedious because you need to catch all instances and your find/replace script strategy might have unintended victims.

In this case indeed, it's just much more convenient.

2 comments

The languages I use the IDE literally does this for you, perfectly, deterministically.

And instantly, certainly when compared to AI.

Yeah, VSCode will rename functions and vars perfectly, using the language semantics. It'll handle changing imports in python if you change file names.

Like you said, it's basically instant.

That doesn't update documentation or comments referring to the function. I prefer search-and-replace.
Sure it does. IntelliJ will do that just fine.
Sounds like it doesn't catch everything and they recommend search-and-replace. From their docs: "For example, if you want to replace a variable name with a new name for a large project, use the Replace in path instead of the Rename refactoring since your variable can appear in the config files as well."
If IDE can do it, a custom tool can do it to. IntelliJ even have a built in MCP server ready to help any agent with such tasks.
Which languages, just out of interest?
That should be most? Unless you do very weird stuff like using strings in JS to call functions, or reflection in C# and similar very special cases, any IDE can handle that.
Kotlin, Java, Python, C#, Typescript. Anything that has a trustworthy and consistent pointer between code.

Ruby would be the one exception I’ve worked on in my head, and for they language, ctrl+f *usually* (but not always) finds the rest.

Ruby is particularly magical with being able to evaluate methods from dynamic strings into running, production code[0]; but otherwise, languages and capable IDEs, like IntelliJ and Visual Studio just support that. I don’t happen to use VS Code, but I assume it has basic refactor, too.

[0] Devise. https://github.com/heartcombo/devise/blob/main/lib/devise/co...

Java has very good refactor support. I use jdt.ls which is eclipse based, but I've heard intellij is even better. I've wished for similar refactor actions in other langs.
don't LSPs and IDE's help with that?
I'm right there with you - prefer classic, deterministic tools wherever possible - but there's a limit. E.g. it's easy to rename a single getter from classic enterprise java `Foo getFoo() {..}` to a modern style `Foo foo() {..}` ... but to rename dozens of getters/setters across hundreds of classes is still tedious.

Even harder would be to update your setters from `void setFoo(Foo f) { this.foo = f; }` to fluent-style `Parent foo(Foo f) { this.foo = f; return this; }` - I'd be surprised if there's an LSP action for that at all. (I'd love to be proven wrong though)

Not sure about LSP, but IntelliJ has had a "structural search and replace" feature for many years, and it can easily handle changes like the one in your second paragraph. It's conceptually like a regex search, but it matches language-specific AST subtrees instead of character sequences.
I've found that for super large but simple refactors, codex and Claude struggle and will just quietly stop doing what you asked it if it's a long running task.

I actually had better luck asking codex to write temporary sed scripts based on the requirements then apply them.

Perhaps, but do they handle all the other aspects of refactoring, too?
Yes, LSPs can supply a variety of refactoring commands (rename, extract to, inline, etc.) that the LSP server can implement directly, deterministically, locally.