Checking for unused variables

jamesmc

Member
Hi all,

I have recently decided to go through a huge lump of old source code and begin to both tidy it up and bring it into the realms of version 8 (from the dark depths of version 6!). Some of the changes will include removing work files and incorporating temp tables and things like that but there is one problem that I seem to be seeing a lot, that is variables that are declared but never used.

My question is, is there a way of checking code for variables that are declared but never used? Currently I am cutting the declaration of the variable out and seeing if it will recompile. It it complains then I paste it back in again (I only do this with standard variables and shared variables, not with new shared variables).

I am using Progress 8.3b in both GUI on Windows 95 and character on an IBM AIX unix system.

I am very doubtful about a quick solution for this, I have pretty much resigned myself to the way that I am doing it now. The only possible solution I can think of is to develop something in Delphi (which, by the way, tells you that you have declared a variable that never gets used at compile time!) and just process each file individually that way.

Anyway, I live in hope that someone can help me out here cos I have got a hell of a lot of code to work through here!!

Thanks,

James.
 

Chris Kelleher

Administrator
Staff member
Ahhh the joys of cleaning up old legacy code! :D

I usually do pretty much the same thing... but a little bit differently. I will organize the variables and put the ones I know are being used at top. Then I'll comment-out all of the variables at the top of the program that I'm not sure are used or not, and syntax-check the program. Then I move the variables out of the comments section one-by-one as the compiler says they are needed until the program compiles ok.

Yes anyway you look at it, it's a pain! (And yes a compiler warning about un-used variables would be very nice!)
 
Hi,

You could use the compiler cross reference for the most part. This shows shared variables directly and you can see whether the shared variable is accessed within the procedure.

The problem is with local variables. They appear only as STRING types within the compiler listing, and there's no record of whether they are accessed or not.

It wouldn't be easy, but you could probably write something in the 4GL based on the x-ref, that traps 99% of unused data storage. You would probably also need a comment stripper.

Or maybe you could automate the old method - e.g. write a program to systematically remove each variable in turn, and see if the procedure still compiles!
 
Top