What Pragmas do you use? and why?

  #If Not DebugBuild
    #pragma DisableBackgroundTasks
    #pragma DisableBoundsChecking
    #pragma DisableAutoWaitCursor
    #pragma StackOverflowchecking False
    #pragma NilObjectChecking False
  #EndIf

I have gotten in the habit of slapping this at the start of any processor intensive method… but to be honest… I’m not sure if I am making the best use of them or not.

And I “assume” these stay in scope for each method… and there is not a way to apply them once (or a less number of times) and get the maximum benefit?

Also are there others that would be beneficial (or determental)?

Yes, and they apply only to that method, not any method calls performed from the method where the pragma is issued.

I only use BackgroundTasks and BoundsChecking, when I use them at all. These will kill the UI, so I only use them in small helper functions to maximize their performance when called from the master method. If something is going to take a really long time, I either use a thread or a timer that works as a pseudo-thread.

The one I use all the time has nothing to do with performance:

#pragma unused varName

Another that helps remind me of unfinished code:

#pragma warning “FINISH THIS!”

(Although that last one doesn’t seem to work on Xojo.)

[quote=19500:@Kem Tekinay]
#pragma warning “FINISH THIS!”
(Although that last one doesn’t seem to work on Xojo.)[/quote]

Works for me.

Like Kem Tekinay I rarely use any #pragmas other than Unused and Warning, though I sometimes also use Error and BreakOnExceptions.

[quote=19509:@Andrew Lambert] Kem Tekinay: #pragma warning “FINISH THIS!” (Although that last one doesn’t seem to work on Xojo.)

Works for me.[/quote]

Does not work for me. I force errors like:

??? Check this tomorrow

I’ll have to test “warning” again, but I wasn’t seeing the message in the compiler.

I think DisableAutoWaitCursor makes code slower as some things are done to avoid the auto wait cursor.
Also I think bounds check, stack check and nil object checks are important and should not be disabled.
DisableBackgroundTasks can speed up loops a lot and make the app less responsive.

I use a fake #error pragma like

#if Not DebugBuild #error Don't ship with this code! #endif
to be sure to remind myself to do something with the code before it goes out the door.

[quote=19519:@Thom McGrath]I use a fake #error pragma like

#if Not DebugBuild #error Don't ship with this code! #endif
to be sure to remind myself to do something with the code before it goes out the door.[/quote]

There is an actual pragma for errors, which is a bit better than getting “unknown pragma”:

#pragma error "message"

[quote=19532:@Joe Ranieri]There is an actual pragma for errors, which is a bit better than getting “unknown pragma”:

#pragma error "message"

I should have known…

Regardless, my snippet is largely useless in most situations. DebugBuild is a useless constant to wrap it in. A custom constant is where such a pragma proves useful.

@Thom McGrath - Thanks for that pragma!..great tip - always wrestling with that won’t be used in build but required in debug