#Pragma Unused

I always ignore the warnings for unused method parameters and unused event parameters.
My biggest project has many hundreds of these warnings.

Is it useful to use #Pragma Unused ?
If yes, what are the benefits? Less memory used? Faster? …

it seems like ti compiles and analyzes a little faster when the are all added.
And you loose the warnings, which may be useful for refactoring purposes etc.

Not sure about speed, maybe the comiler strips it out?

I would think the compiler strips it out anyway, even when you do not use #Pragma Unused
But I was just thinking what the ‘real’ benefits are.

1 Like

Well that’s a good question that maybe someone at Xojo can let us know.

From the docs:

Controls whether Analyze Project will test for the passed unused variable. VariableName can be a local variable, method parameter, or event parameter. You must pass the variable or parameter you do not want to test. The pragma can be used only after the variable has been declared. Also, you cannot pass a list of variables. Use a separate #pragma statement for each variable. You can also turn off checking within the Issues pane by clicking the Type Filter button In the Issues toolbar and deselecting the checks for unknown local variable, method parameter, or event parameter.

So the compile speed difference could be one thing (if you have lots of them).

If nothing else, it will help you distinguish cases where you didn’t need to use a parameter from cases where you should have.

3 Likes

It’s definitely helped me catch mistakes. Let’s say you add an event parameter. You’ll now get a warning for every implementation of that event, since the new parameter will be unused. You then go through each and either use the new parameter, or mark it unused.

At least a few times it has helped me realize I used the wrong variable, or just forgot to implement something. Your goal should be zero warnings, so that when something new pops up, you can recognize it quickly.

5 Likes

I use it to point out to the compiler that I really don’t intend to use a parameter, so it won’t emit a warning calling my attention, avoiding my project accumulate warnings (could become hundreds with the time) and that I check if I’m not really missing something. :slightly_smiling_face:

Compiling is between 10 and 20% faster when you add the pragma unused everywhere. It helps me catch things I haven’t finished.

3 Likes