Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Highlight unused variables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Paul
New Member

USA
9 Posts

Posted - Sep 13 2007 :  1:37:44 PM  Show Profile  Reply with Quote
It would be convenient if VAX could somehow highlight those variable declarations that have not yet been used.

Although most compilers can tell you which variables aren't being used in a block, it sometimes can be a nuisance to delete the correct ones (esp. if you've copied and pasted a bunch of code) -OR- (more so if you're compiler doesn't warn) when you've added variables in for a reason and then forget to implement the functionality.

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Sep 13 2007 :  5:25:58 PM  Show Profile  Reply with Quote
It is an interesting idea. My main concern is the amount of code scanning required for this to work. For a local variable in a 10 line function it is easy, but when you multiply this across all functions in all open files it becomes quite a bit more.

Plus there are the edge cases, what about external variables? Class member variables? Global variables?

Also I don't want to open the door to a lot of static code analysis requests.

zen is the art of being at one with the two'ness
Go to Top of Page

sl@sh
Tomato Guru

Switzerland
204 Posts

Posted - Sep 14 2007 :  08:10:33 AM  Show Profile  Reply with Quote
The request referred to blocks of code, and I'd say that's as far as such a functionality should reasonably go. No class members, no externals, no globals, no funny stuff that might be accessed from without the solution alltogether!

That said, I'd consider the purging of unused items a 'cleanup' step, applied only near the end of development cycles. So I don't really see the need to continuously mark unused stuff. Instead just provide the ability to quickly get rid of stuff during some cleanup phase.

To that end, maybe VA could provide a refactoring method to scan the current file (or just the current function) for unused symbols: basically it should work just like Find References, only not restricted to just one symbol, but a number of symbols within the current context (e. g. all variables of a function). Instead of showing all the references, VA could just indicate the number of references found, and highlight those symbols that are not being used (i. e. found only once at their declaration).
Go to Top of Page

tailsu
Senior Member

37 Posts

Posted - Sep 14 2007 :  08:35:20 AM  Show Profile  Reply with Quote
Is it really necessary? Most compilers can be made to issue a warning about unused local variables.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Sep 14 2007 :  09:54:37 AM  Show Profile  Reply with Quote
How useful this is will vary from person to person.

Having some form of refactoring operation that you trigger, which scans for and then lists unused variables is an interesting idea, and one that we are considering:

case=2335

Here the idea is that the refactoring operation will let you quickly and easily remove the variables as well.

The compiler does tend to warn about unused variables, but you still have to remove them by hand. Not a problem if you keep on top of them, but less helpful if you inherit a code base that is full of them.

zen is the art of being at one with the two'ness
Go to Top of Page

znakeeye
Tomato Guru

379 Posts

Posted - Sep 22 2007 :  08:05:51 AM  Show Profile  Reply with Quote
Most compilers do not warn when there are unused class members. I don't know how many times I've found multiple variable declarations in my header files, forgotten by VC++...
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Sep 26 2007 :  6:49:19 PM  Show Profile  Reply with Quote
Feline: this is a very interesting idea. For example, you may use VAX's find references on every variable in the block, and count the references... But usually when I add a new member variable to a class, I am initializing it, usually in the constructor (or in some init function). So, it will "used". But there is no real use. What do you think?

But this new refactoring still will be very useful without covering these edge cases... For example, in modern frameworks, where a parser will generate the save-load and init stuff, this feature will works perfectly, because VAX must not see these generated code if are separated in a header and not in project...

Finally, I have to say, current find references is already very useful in detecting unused variables :)

Find references is my favorite VAX feature ever

Edited by - accord on Sep 26 2007 6:51:14 PM
Go to Top of Page

sl@sh
Tomato Guru

Switzerland
204 Posts

Posted - Oct 01 2007 :  04:14:06 AM  Show Profile  Reply with Quote
quote:
Originally posted by accord

Feline: this is a very interesting idea. For example, you may use VAX's find references on every variable in the block, and count the references... But usually when I add a new member variable to a class, I am initializing it, usually in the constructor (or in some init function). So, it will "used". But there is no real use. What do you think?

Actually this can be solved: 'Find References' already marks it's entries showing where references are being read or written to. So all VA needs to do is check whether a variable has been read in any of the references it found.
Go to Top of Page

Sasa
Tomato Guru

272 Posts

Posted - Oct 01 2007 :  12:29:39 PM  Show Profile  Reply with Quote
That is yet another neat feature from Eclipse.

It detects un-used variables on the "fly". But then Java is a much simpler language to parse than Cpp.

Like sl@sh said, Eclipse detects whether a variable is being read, and if not, give you a warning and a "quick-fix" option.

C++
Visual Studio 2008 Pro
Windows 7 x64
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Oct 02 2007 :  2:45:12 PM  Show Profile  Reply with Quote
Thinking about this, I can often accumulate variables that are only ever assigned to when debugging / writing complex code. The variables are added in while debugging / logging, and left there when the debug code is removed. I leave them there for two reasons:

1) leaving them is less work than removing them
2) they will be useful next time I am passing through this code trying to work out why things are not working as I expected


Thinking a bit more deeply about this, how do you really define "read"? VA makes a good guess at this, but reference and pointer function parameters are a good way to generate edge cases.

None of this invalidates the idea, but it does suggest why we need to be a little careful.

zen is the art of being at one with the two'ness
Go to Top of Page

graham.reeds
Ketchup Master

United Kingdom
51 Posts

Posted - Oct 03 2007 :  05:37:30 AM  Show Profile  Reply with Quote
One thing I did when I inherited an ancient project which seemed to have 5 times the number of actual variables used (some were cut'n'paste jobs with the same comments on the line that the variable was declared but was renamed for whatever reason) was to comment out every variable and breakpoint the entrance to all the functions (setting ctrl+shift+/ was a god-send) and then simply recompile and uncomment the used variables and then when it finally did run see why the functions that were never entered weren't (again rotting code). Once they were cleaned I redid the variables (another batch removed) and finally then I group all the variables, corrected the docs, added doxygen tags and rechecked in the work. While this ate the best part of a week, I think it will pay off in time as working with the code is a lot more pleasant, I have better knowledge of what the code actually does and the commentary is currently correct.

That said a semi-autonomous tool would come in handy. VAX was very handy because the commenting out was invaluable, but I am less adept at other parts of VAX usage. I use ctrl+shift+c for creating an implementation and ctrl+shift+d for creating the skeleton of doxygen tags for documenting, but that is mainly it.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000