News for hackers. Stuff that matters.
Re:Greppability is an underrated code metric by zarzavat on Tuesday September 03, 2024 @02:12AM (#41431793)
Go to definition and find usages only work one symbol at a time. I use both, but I still use global find/replace for groups of symbols sharing the same concept.

For example if I want to rename all “Dog” (DogModel, DogView, DogController) symbols to “Wolf”, find/replace is much better at that because it will tell me about symbols I had forgotten about.

Re:Greppability is an underrated code metric by gugagore on Tuesday September 03, 2024 @02:16AM (#41431822)
I am familiar with the situation you describe, and it's a good point.

However, it does suggest that there is an opportunity for factoring "Dog" out in the code, at least by name spacing (e.g. Dog.Model).

Re:Greppability is an underrated code metric by zarzavat on Tuesday September 03, 2024 @04:11AM (#41432509)
That gets to the core of the issue doesn’t it? There are two cultures: Do you prefer to refactor DogView into Dog.View, or do you prefer to refactor Dog.View into DogView.

Personally I value uniqueness/canonicalness over conciseness. I would rather have DogView because then there is one name for the symbol regardless of where I am in the codebase. If the same symbol is used with differently qualified names it is confusing - I want the least qualified name to be more descriptive than “View”.

The other culture is to lean heavily on namespaces and to not worry about uniqueness. In this case you have View and Dog.View that may be used interchangeably in different files. This is the dominant culture in Java and C#.

Re:Greppability is an underrated code metric by kccqzy on Tuesday September 03, 2024 @09:11AM (#41434632)
The second culture that you describe happens also to be how OCaml structures things in modules. It's quite a turnoff for me.
Re:Greppability is an underrated code metric by f1shy on Tuesday September 03, 2024 @02:27AM (#41431877)
That really depends on the context, and specific situation.
Re:Greppability is an underrated code metric by f1shy on Tuesday September 03, 2024 @02:28AM (#41431884)
For that use case I think you can use treesitter[1] you can find Dog.* but only if it is a variable name, for example. Avoiding replacement inside of say literals.

[1] https://www.youtube.com/watch?v=MZPR_SC9LzE

Re:Greppability is an underrated code metric by turboponyy on Tuesday September 03, 2024 @02:35AM (#41431930)
There's no reason they have to work one symbol at a time - that's just a missing feature in your language server implementation.

Some language servers support modifying the symbols in contexts like docstrings as well.

Re:Greppability is an underrated code metric by setopt on Tuesday September 03, 2024 @02:46AM (#41432000)
I’ve never seen an LSP server that lets you rename “Dog” to “Wolf” where your actual class names are “Dog[A-Za-z]*”?

Do you have an example?

Re:Greppability is an underrated code metric by Maxion on Tuesday September 03, 2024 @03:07AM (#41432121)
IntelliJ's refactor tool?
Re:Greppability is an underrated code metric by yen223 on Tuesday September 03, 2024 @10:10AM (#41435153)
IntelliJ doesn't use LSP as far as I know.

It does usually make that kind of DogModel -> WolfModel refactoring.

Re:Greppability is an underrated code metric by turboponyy on Tuesday September 03, 2024 @04:55AM (#41432785)
Neither have I; and no, I don't - I misinterpreted what you said.

But I don't see why LSP servers shouldn't support this, still. I'm not sure if the LSP specification allows for this as of current, though.

Re:Greppability is an underrated code metric by setopt on Tuesday September 03, 2024 @01:00PM (#41436842)
I would actually love a regexp search-and-replace assisted by either TreeSitter or LSP.

Something that lets me say that I want to replace “Dog\(.*\)” with “Wolf\1”, but where each substitution is performed only within single “symbols” as identified by TS or LSP.

Re:Greppability is an underrated code metric by nickcox on Tuesday September 03, 2024 @06:50PM (#41440117)
Re:Greppability is an underrated code metric by sandermvanvliet on Tuesday September 03, 2024 @04:26AM (#41432605)
Jetbrains ReSharper (and Rider) is smart enough to handle these things. It’ll suggest renames across other symbols even ones that have related names
Re:Greppability is an underrated code metric by chipsrafferty on Thursday September 05, 2024 @05:08PM (#41460421)
And when it fails to find all the related names, you don't know what it missed.