|Re: The quality of an xPand template [message #501248 is a reply to message #501159]
||Tue, 01 December 2009 16:26
|| Karsten Thoms
Registered: July 2009
Location: Dortmund, Germany
Xpand templates should be in first order easy understandable and well structured. To achieve this you can follow some guidelines:
1) Don't let template files get too large. Delegate to other files, split per artifact, create common template code etc.
2) Don't let DEFINEs get too large. Delegate to other definitions.
3) Don't use too much logic in Xpand.
- check model for consistency before Xpand execution. No need to handle special situations that come from inconsistent models in Xpand code (like "if feature something is not set then create special code, otherwise take information from the model").
- Use M2M transformation to autocomplete the model according to conventions (e.g. set the name of unnamed association ends)
- Use Xtend functions for non-trivial evaluations
4) Don't use LET, prefer Xtend functions.
5) Don't use PROTECT when the generation gap pattern can be applied
6) Use the Xpand profile (available from 0.8.0-M3) to identify performance bottlenecks. It can also be useful to identify unused templates and Xtend functions.
7) Optimize the template for readability of the template, not of the generated code. Use Code formatters as postprocessors when possible.
8) Set the file encoding as project-specific setting. Good choices are ISO-8859-1 or UTF-8.
9) Don't use too deep loops or conditions. Delegate to sub-templates.
10) Whenever some expression is used several times, create an Xtend function.
11) Don't use too many EXTENSION declarations in the template. Use a template specific Xtend file and reexport required extensions.
I hope this helps you a bit.
Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
[Updated on: Tue, 01 December 2009 16:26]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.02437 seconds