- I understand that using preprocessor directives is actively discouraged, with the sole exception of #region.
- I very much prefer to stay within supported guidelines.
- This post is to ask about best practices with the system the way it is (and not about arguing that the system should support the preprocessor)
My source has a fair bit of trace/debugging code, including a sizable presence in my GUI when compiled with debugging turned on. I don't want either the code or, especially, the GUI impact for non-debug builds. It seems to me that there are two separate questions: how to avoid the unwanted code and how to avoid the unwanted properties. I'd like to know what the supported best practices are for each.
Code -- can be excluded several ways. My understanding is that only the first of these is supported. (Am I correct that the [Conditional] attribute is not supported?)
- I believe the recommended way is to not get rid of the code, but to have a runtime check that avoids executing it. That is, in principle, doable. One could define a single const , which would not be a lot more work than depending on the compiler defining DEBUG.
- Where possible, I would prefer to use the [Conditional] attribute, which works for void methods. That stops all calls in a non-debug build, it seems cleaner and is very visible in the source. (Is this supported? I would guess not.)
- #if ... #endif would be needed where [Conditional] is not applicable -- any method returning a value. This is clearly not supported.
- None of these properties has the [NinjaScriptProperty] attribute so, as far as I know, the automatic code generation ignores them.
- I do not know how to eliminate them from a build without using #if ... #endif.
- What is the supported/recommended method of excluding such properties from a non-debug build?
- Use it to exclude code that I am having trouble compiling so I can get on with my work. I'll get back to that troublesome part later.
- This is a compile-time issue, not a runtime issue, so the recommended use of a runtime check is not relevant.
- Is there a supported way to deal with this?
- Use it to avoid deleting some code being ported from the source until I am certain that the new code I am replacing it with does the job.
- This may be just a few lines within a method rather than an entire method.
- This could be handled with a runtime check. That could work, unlike a couple of the other issues I have raised.
I guess the two biggest needs that I don't see a supported way to handle are excluding properties that affect the GUI and segregating code that will not yet compile. What are the best practices for these issues?
Thanks for your consideration.

Comment