I'm sorry if I missed a Jungle tutorial somewhere, and I'm glad if I'm pointed to the right direction. (I've read this, this, and a few relevant posts here.)
tl;dr: I have two questions:
- when is it reasonable to use build exclusions for code over runtime checks?
- is there a qualifier for API levels, or should one "build" it manually in Jungle?
Thought process:
So the scenario I want to address currently is a simple and common one: use a certain thing in older API versions, and a newer in others. My exact case (and current version of the code):
if (Application.AppBase has :Properties) { clubId = self.Properties.getValue("club"); } else { clubId = self.getProperty("club"); } self.clubData = new ClubData(clubId);
This works fine, and I understand that this has the advantage of "switching" to the newer version under the hood if the API support is (FW) updated for a watch without reinstalling the app itself, as pointed out in this topic. (I'm not sure though, how often that happens.)
If I understand correctly, the other option is to use build exclusion feature of Jungles (that behaves like C macros if I understand correctly), so I can exclude the unnecessary code parts in compile time. However, I struggle to find, if there is a built-in annotation for API level, or one should manually build it. I have seen a (:newer) and (:older) in one of the examples, but I guess, these are custom things, which I have to "construct" myself. What is the proper way to do this? (Question 2) Also, if I understand this correctly, the "built" API version and the "real" API version can differ after a FW update, so this might even cause issues (if backward compatibility is not adhered).
A related question: can higher level of optimizations "optimize out" branches like the above? I'd assume not, as `AppBase has` can only be evaluated at runtime, and it would invalidate the mentioned benefit above.
I completely understand that in my current case the exclusion of this one unnecessary instruction call would be a way overkill in terms of optimization, and I'd even lose the aforementioned benefit.
So my main question (numero zwei) could be probably best phrased as this: what are the best practices for choosing between a dynamic has check, and a compile time Jungles build exclusion. (I assume, that similar compile time checks can be made for families as well.) What is the complexity/size of the code, when the latter becomes preferred over the former? Is there even a practical reason for this? I could argue, that in terms of size, the code itself is negligible compared to resources; and in terms of computation, a single conditional is probably also negligible compared to any background calculation or UI update. So should one use build exclusions at all for code? (I understand its role and importance for resources.)
These are my thoughts, but I barely spent a few dozen hours with MonkeyC so far, so I'd be glad to hear the experience and recommendation of experienced developers.