In my monkey.jungle I set either annotation foo or no_foo for each device.
In my code I have:
(:foo) const FOO = true;
(:no_foo) const FOO = false;
And I use it extensively like:
if (FOO) {
// do stuff I only need when foo is enabled
}
This works nice with SDK 7+ because it eliminates the whole code block when building for devices with foo disabled.
However there are still a couple of situations when this doesn't work or not as nice. For example if I have a function:
class Example {
(:foo) function fooOnly() as Void {...}
function other() as Void {
if (FOO) {
fooOnly();
}
}
}
This gives a compile time error: Undefined symbol ':fooOnly' detected.
There is a not too nice work around: declaring fooOnly() as an empty function.
(:no_foo) function fooOnly() as Void {}
but I don't like this, because this does increase the code size for the devices that have the least amount of memory (and thus I disable foo).
It can be even better if one uses Prettier Monkey C:
(:no_foo, :inline) function fooOnly() as Void {}
but I don't use Prettier optimizer in all my apps, so I'm looking for another ideas.
Another example is when a class variable is only needed for a certain feature:
class Example {
(:foo) var isFooActive as Boolean = false; // it's set to true somewhere in the class
function other() as Void {
if (FOO) {
if (isFooActive) {...}
}
}
}
This will also not compile, because the compiler doesn't know isFooActive, so I have to add a dummy variable:
(:no_foo) isFooActive = false;
Which kind of makes it useless to use the annotation :)
Also for bigger objects, like Fields in a fit contributor, it does help a bit, but I still need a dummy nullable version:
class Example {
(:foo) var fooField as Field;
(:no_foo) var fooField as Field?; // hack
function initialize() {
if (FOO) {
fooField = session.createField(...);
}
}
function compute() as Void {
if (FOO) {
var fooValue = computeFoo();
(fooField as Field).setData(fooValue);
}
}
}