Author |
Topic |
|
Mordachai
Tomato Guru
USA
224 Posts |
Posted - Feb 11 2013 : 10:09:10 AM
|
One of the things that drives me nuts with editing source code, is I sometimes (more frequently than is probably expected) need to make global or at least multi-file search & replaces.
On such occasions, it is frustrating that the changes affect even that which is a comment. It seems goofy and needlessly stupid in this day & age where the editors all have access to the parsing engine, and can trivially determine what is comment, and what is not-comment.
Even doing searches can end up giving me tons of hits on things that clearly are not valid - they're in the comments - which is again, frustratingly barbaric.
Any chance that VAX could offer a Search and Search&Replace feature that offered a checkbox for "ignore comments"? |
|
Mordachai
Tomato Guru
USA
224 Posts |
Posted - Feb 11 2013 : 10:11:01 AM
|
I realize that this is really something that VisualStudio should be offering. However, you're infinitely more accessible than they are, and it might offer a sales bullet point for VAX - which is by far my favorite programming tool (outside of VS itself), and has made my life as a programmer easily 5x more productive. :) |
Edited by - Mordachai on Feb 11 2013 10:12:00 AM |
|
|
feline
Whole Tomato Software
United Kingdom
19014 Posts |
Posted - Feb 11 2013 : 11:55:17 AM
|
Are you doing something that VA's Rename command can help with? If you are doing this on symbols then Rename should be able to help, and you get a check box to say if you want to update comments or not.
One consideration for comments, what about commented out code? Its common to comment out bits of code while working, but you might still want these updated when doing a search and replace. |
zen is the art of being at one with the two'ness |
|
|
Mordachai
Tomato Guru
USA
224 Posts |
Posted - Feb 11 2013 : 1:52:57 PM
|
Unfortunately, none of the VA refactoring (rename, change signature, etc.) can help with these.
One example: surrounding all literals with _T() macro. Incredibly painful when the best regex I can come up with still apply themselves to comments. :(
Searches are far more common. Right now I'm updating code for C++11 make_shared and the soon-to-be-standard make_unique, and in those cases I need to find everywhere I'm essentially using a raw new operator. A lot of comments say something like // blah blah (new in 15.0) or some such.
---
As to commented out code... if there is a check-box for "include comments" then that becomes a minor issue. Right now I'd happily make that trade - i.e. commented out code is my responsibility if I don't check "include comments". It's another 80/20 solution. Commented out code is a very small fraction of my code - and I often use #ifdef USE_CONDITION_NAME .... #endif to comment out code - especially now that VS grays out branches which are not active.
Also - this is no different than VA's find references, or rename, or change signature, etc., etc. - commented out code is not code. |
Edited by - Mordachai on Feb 11 2013 1:53:38 PM |
|
|
feline
Whole Tomato Software
United Kingdom
19014 Posts |
Posted - Feb 11 2013 : 4:36:19 PM
|
If I understand, this is something of a one off project. As you obviously realise, its the multi line C style comment blocks that are the real issue here. Have you considered running the code files through a pre-processor to strip out all comment blocks, then you could do a find and replace, safe in the knowledge you were only checking code. Then get a diff "patch" file for the before and after on this modified code?
Its a convoluted process, but if it works it should be quite helpful.
As for the new operator, is something as simple and obvious as =:b*new:b+:i+:b*\\( going to help?
This is a VS2010 format regular expression. VS2012 regular expression format looks a bit different, but the idea is to check for white space, C++ identifier characters and a bracket. |
zen is the art of being at one with the two'ness |
|
|
Mordachai
Tomato Guru
USA
224 Posts |
Posted - Feb 12 2013 : 10:29:00 AM
|
If this were a one-off, I wouldn't post it here. :)
I find myself facing this over & over again. Having to sift through sometimes a few, and oftentimes many false positives in order to find the set of things I need to really double check of change in some way. And if I need to do a replace, then the false positives become a nightmare.
Your idea to strip out all that is comments is an interesting one. We're talking many hundreds of files, however... so I'm not sure how practical it is. Using Scooter Software's Beyond Compare might make it practicable, or it may simply be trading one type of tedious for another.
I'm surprised that more of your customers (and VS's customers) don't ask for this. I have to say, about every other search I do I wish for "don't look in comments" check-box.
But - ultimately, I should be posting this to VS. If you have a suggestion for where I might post a feature request to MS for VS I would be happy to do so.
Thanks for all of your help. |
|
|
feline
Whole Tomato Software
United Kingdom
19014 Posts |
Posted - Feb 12 2013 : 12:01:33 PM
|
Ah, not a one off then. I was not sure, and sometimes people do post what seem to be one off tasks here
I use Beyond Compare myself, and I know that version 3 pro version has an option for ignoring certain unimportant differences. I just have the standard version myself, but from my understanding it probably would not do what you want sadly.
I was thinking about some command line tools, a search and replace, diff then merge. This could work for an occasional run, but since it will be tricky to review all of the potential changes mid flow I am not sure how user friendly this will be. But you could review when you came to commit the changes into source control, and good command line tools would handle many files quite happily.
I was looking at command line diff recently, and the Windows "fc" program has a patch output format, which is what I was thinking of when I suggested this possible approach.
Doing this inside the IDE, VA would have to let the find finish, then post process the find results, filtering out all of the matches that were inside a comment block. It would work, but its a bit messy.
I don't think this idea has ever come up before, to be honest. I use Find in the IDE quite a bit myself, but don't tend to have many problems with comments getting in the way, obviously I am doing different types of searches.
You can submit a suggestion for Visual Studio here: https://connect.microsoft.com/VisualStudio/ |
zen is the art of being at one with the two'ness |
|
|
|
Topic |
|
|
|