XOJO IDE: A way to clean project

Hi there,
Is there any way using Xojo IDE to remove redundant code (unusable variables etc) from the project?

do a project analyse (under the project menu)
then you have a list of all unused variables or parameters
is that what you want ?
the rest is kind of manual work.

Yes, thank you, Jean
I suppose i have to make the fixes manually, though…

Good luck…

Someone knows if this is worth the spent time ?

yes.

[quote=472731:@Emile Schwarz]Good luck…
Someone knows if this is worth the spent time ?[/quote]

i think it belongs how importantly the project is.

everybody should do a code review of methods after changes to reduce error-proneness & instability.
each method is part of the big gearbox.
and after enhancements the project analyse would only show new things.
my habit is to add a initials remark with date after i verified a method.

@Marcus

Yes, that is theory.

What is not theory is the how deep are the linker/compiler in squashing unused stuff (Methods, Functions, etc.).

What do not help is the way Xojo save projects / applications: it feeds the whole last block (or all blocks), so there is no small differences in projects / applications…
(Removing a Dim line, some bytes) usually makes no difference in term of disk footprint).

Fortunately, Comments are always stripped (if my memory is correct) from the final applications.

it seems this feature is missing (wondering)

i think save as xojo_project is the best way because it make a lot of single files.

It would be nice to have a feature that shows all unused methods and gives them inside the navigator a strike-trough

This is not a core feature in Xojo.
What about save as xml ?

The default project file is binary.

[quote=472755:@Emile Schwarz]What about save as xml ?
The default project file is binary.[/quote]
if something bad happened xml is better to fix than binary.
one file as binary i find critically because all the months of work is in this single file.
because the save is fast enough i used often the binary format.
i like the single files because there i no framing around.

[quote=472594:@Jean-Yves Pochez]do a project analyse (under the project menu)
then you have a list of all unused variables or parameters
is that what you want ?
the rest is kind of manual work.[/quote]

Do be careful if you use #If TargetWindows or #if TargetMacOS. Variables used within those can be considered unused when they are actually being used, just not on the platform you’re currently on. I’ve had this happen more than once, I’m running Xojo on my Mac, so variables declared outside of #If TargetWindows but used only inside #If TargetWindows are considered unused. This can easily happen if you declare the variables, then later section off part of the code to one platform, so the variable becomes orphaned.

So when you see Analyze says a variable is unused, do a search for it and see if that’s really true before deleting it.

[quote=472806:@John McKernon]Do be careful if you use #If TargetWindows or #if TargetMacOS. Variables used within those can be considered unused when they are actually being used, just not on the platform you’re currently on. I’ve had this happen more than once, I’m running Xojo on my Mac, so variables declared outside of #If TargetWindows but used only inside #If TargetWindows are considered unused. This can easily happen if you declare the variables, then later section off part of the code to one platform, so the variable becomes orphaned.

So when you see Analyze says a variable is unused, do a search for it and see if that’s really true before deleting it.[/quote]
Great advice John.

In John’s scenario, because I’m really obsessive-compulsive about these warning messages (because I like a clean Analysis report), I add #Pragma Unused <varNameHere> to the relevant #If Target code block, to keep these particular warnings from being flagged, depending on which OS I’m working in. Read more about #Pragma Directives here.

What a good project to achieve:

it will load the project,
export it as xml,
load the xml data,
and search for whatever stuff need to be cleared.

Then, display the list to the user (Variables names, Methodes, etc.) in a ListBox (for example).
A click in an entry will display the object contents (or two when duplicates), etc.

Maybe an Open Source project ? (less time, maximum ideas on how to achieve the goals, what to do and how, etc.), exposition to many differently write styles, etc.

“Only a Northern Idea.”

[quote=472806:@John McKernon]Do be careful if you use #If TargetWindows or #if TargetMacOS. Variables used within those can be considered unused when they are actually being used, just not on the platform you’re currently on. I’ve had this happen more than once, I’m running Xojo on my Mac, so variables declared outside of #If TargetWindows but used only inside #If TargetWindows are considered unused. This can easily happen if you declare the variables, then later section off part of the code to one platform, so the variable becomes orphaned.

So when you see Analyze says a variable is unused, do a search for it and see if that’s really true before deleting it.[/quote]

or move the ones you only use in #if TargetWindows inside the #if TargetWindows block so they are local to that code

Analyze is for the current platform you’re working on so those variable ARE unused on this target

Well, the menu item just reads “Analyse project”. When I use this, I expect the whole project to be analysed (even “#if false then” blocks).
With the current implementation, one would have to launch the IDE in Mac, Windows and Linux to analyse the project on these 3 IDE . If it was done the other way around (considering the whole code), you’d immediately know whether a variable is really unused (along with other issues).
I don’t understand the limitation of analysing only for the current platform.

As others have said, great advice. I’ve generally been careful to only declare platform-specific stuff in the right #If Target. However, when I recently added modGTK to my projects (thanks to all who have worked on this!!), I got a lot of “unused method parameters” when analyzing on my Mac, all in modGTK. It took just a moment to see that this was because all of the code was nested in #if TargetLinux", which of course makes perfect sense.

I’m a neat freak too, so I may just accordingly edit modGTK’s methods with some “#elses”, based on your tip :slight_smile:

[quote=472845:@Arnaud Nicolet]Well, the menu item just reads “Analyse project”. When I use this, I expect the whole project to be analysed (even “#if false then” blocks).
With the current implementation, one would have to launch the IDE in Mac, Windows and Linux to analyse the project on these 3 IDE . If it was done the other way around (considering the whole code), you’d immediately know whether a variable is really unused (along with other issues).
I don’t understand the limitation of analysing only for the current platform.[/quote]

Exactly. My app is Mac and Windows cross platform, but I write it only on Mac. So I can’t analyze it for Windows, and installing Xojo on Windows and keeping plugins, etc. updated on two separate computers is tough.

Analyze should analyze all platforms you have checked for building in the IDE.

analyze is basically a “run”
it just doesnt run the actual built app
hard to run windows app on a mac (etc)

at one time I submitted a case about this problem but I suspect it was internal and private

[quote=472972:@Norman Palardy]analyze is basically a “run”
it just doesnt run the actual built app
hard to run windows app on a mac (etc)

at one time I submitted a case about this problem but I suspect it was internal and private[/quote]
You’re right, it’s basically a “run”… but it doesn’t have to be in the first place.