4 ms·
Your observation does not help with the majority of the points in the article. How do you find all usages of a parameter value literal?
by jakub_g 2y ago
Your observation does not help with the majority of the points in the article. How do you find all usages of a parameter value literal?
- troupo 2y agoThis is what the article starts with: "Even in projects exclusively written by myself, I have to search a lot: function names, error messages, class names, that kind of thing." All of that is trivial to search for with a tool that understands the language.
- renewiltord 2y agoI actually don't think there's a tool that handles usages when using PHP varvars or when using example number one there which is parametrically choosing a table name. When you string interpolate to build the name you lose searchability.
- troupo 2y agoYes, full-text search is a great fallback when everything else fails. But in the use cases listed at the beginning of the article it's usually not needed if you have proper tools
- nosianu 2y ago> All of that is trivial to search for with a tool that understands the language. Isn't string search, or grepping for patterns, even more trivial? So what is your argument? You found an alternative method, good, but how is it any better? In my own case, I wrote a library that we used in many projects, and I often wanted to know where and how functions from my lib were used in those projects. For example, to be able to tell how much of an effort it would be for the users to refactor when I changed something. However, your method of choice at least with my IDE (Webstorm) only worked locally within the project. Only string search would let me reliably and easily search all projects. I actually experimented creating a "meta" project of all projects, but while it worked that lead to too many problems, and the main method to find anything still was string search (CTRL-SHIFT-F Find dialog in IDEA IDEs is string search and it's a wonderful dialog in that IDE family). I also had to open that meta project. Instead, I created a gitignored folder with symlinks to the sources of all the other projects and created a search scope for that folder, in which the search dialog let me string-search all projects' sources at once right from within the library project and still being able to use the excellent Find dialog. In addition, I found that sometimes the IDE would not find a usage even within the project. I only noticed because I used both methods, and string search showed me one or two places more than the method that relied on the underlying code-parsing. Unfortunately IDEs have bugs, and the method you suggests relies on much more work of the IDE in parsing and indexing compared to the much more mundane string or string pattern search.
- troupo 2y ago> Isn't string search, or grepping for patterns, even more trivial? It's not trivial when you looking for symbols in context. > the method you suggests relies on much more work of the IDE in parsing and indexing compared to ...compared to parsing and indexing you have to do manually because a full-text search (especially in a large codebase) will return a lot of irrelevant info? Funnily enough I also have a personal anecdote. We had a huge PHP code base based on Symfony. We were in the middle of a huge refactoring spree. I saw my colleagues switch from vim/emacs to Idea/WebStorm looking at how I easily found symbols in the code base, found their usages, refactored them etc. compared to the full-text search they were always stuck with. This was 5-6 years ago, before LSP became ubiquitous.
- nosianu 2y ago> It's not trivial Did you miss the comparison? The "more trivial"? The context of my response? Please read the parent comment I responded to, treating my comment as standalone and adding some new meaning makers no sense. String search is more trivial than a search that involves an interpretation of the code structure and meaning. I have no idea why you wish to start a discussion about such trivial statement. > * because a full-text search (especially in a large codebase) will return a lot of irrelevant info?* It doesn't do that for me but instead works very well. I don't know what you do with your symbol names, but I have barely any generic function names, the vast majority of them are pretty unique. No idea how you use search, but I'm never looking for "doSomething(", it's always "doSomethingVerySpecific()", or some equally specific string constant. I don't have the problems you tell me I should have, and my use case was the subject of my comment, as should be clear, as well as my comment being a response to a specific point made by the parent comment.
- cma 2y ago> All of that is trivial to search for with a tool that understands the language. Some literal in a log message may come from the code or it might be remapped in some config file outside the language the LSP is looking at, or an environment variable etc.. I just go back and forth with grep and IDE tools, both have different tradeoffs.
- troupo 2y agoThe thing is, so many people are weirdly obsessed with never using any other tools besides full-text search. As if using useful tools somehow makes them a lesser programmer or something :)
- CrimsonRain 2y agoBy not using literals everywhere. All literals are defined somewhere (start of function, class etc) as enums or vars and used. Just because I have 20 usage of 'shipping_address' doesn't mean I'll have this string 20 times in different places. Grep has its place and I often need to grep code base which have been written without much thoughts towards DX. But writing it nicely allows LSP to take over.