What steps should you take when your templates take longer than expected to execute? How do I manage the growing size of my template libraries?
Mo+ Solution Builder can create and maintain large, complex solutions utilizing spec and code templates written in the Mo+ model oriented programming language. Sometimes, as the set of templates grows to meet the needs for the solution, the templates may seem to be a bit hard to manage, being either too complex or inefficient. If you are creating a new template library, it's always good to start simple, generating simpler things, then adding complexity.
Here are some things to look out for in dealing with harder to manage template libraries:
- Inefficiency: If executing the templates for model or code generation takes longer than expected, operations done within the templates may be too complex, or complex operations may be called more times than necessary. For efficiency, you will want to reduce the number of complex operations, while still meeting your needs. One way to do this is to encapsulate a complex operation that is utilized over and over again into a separate template. This has 2 advantages:
- The encapsulated template can be used like any other property, making your templates easier to read and use.
- The Mo+ Solution Builder interpreter will often cache the template results per instance in the model, so the complex operation will be called fewer times. When you update the model or your solution, you can make note in the Output window of how many template calls were cached.
- Too Many Templates: A larger number of templates is generally good for encapsulation and efficiency (see above). But, the sheer number of templates may be hard to manage in terms of what they do and when to use them. Utilizing a naming convention for your templates, and a convention for using theCategory field of the templates will be a great help as the number of templates grows.
- Solution Design Not Ideally Oriented To Your Model: When creating a code, model, or document solution, it is best to start with good code samples that make use of your organization's or community best practices. If building the code templates to meet the code generation needs for your solution seems too complex, it is a good idea to review your solution design from time to time for any improvements that may make it easier to generate from your model. For example, common interfaces and methods that are understood by code classes for many model elements will often reduce code template complexity, while also reducing the amount of unnecessary generated code.
- Mo+ Feature Needs: It may turn out that you may need more information in the solution model structure to better meet your needs, or that there should be some additional features in the Mo+language or the Mo+ Solution Builder UI to do what you want to do in a simpler manner. Feedback of this nature is greatly appreciated for future improvements.
The sample template libraries may suffer from one or more of the above issues, and it is desired to improve and expand on the sample libraries for the community. Please provide any feedback on those samples!