How to write easily understood Turbo Integrator code
As many of TM1 consultants know, reading TI code always has the possibility of being a tricky task – especially if it is someone else’s code. This is mostly due to TM1 Perspectives Turbo Integrator lacking Syntax Highlighting (See our Notepad++ highlighter) but in part it is due to poor variable naming, indenting, casing or things simply not developed consistently throughout the model.
My recommendations for writing turbo integrator code, which can easily be read and more importantly understood:
Variable names should start with a type indication letter then followed by logical name starting with a capital letter i.e. nTotalSales or cCubeName.
The following prefixes give you enough flexibility and are easy to remember:
- c for constants
- n for numeric variables
- s for string variables
- p for parameters
- b for bool/logic values
Constants are specified in Prolog/Epilog sections (common usage is cube or dimension name) and do not change during TI execution. It is extremely useful to set constants for all static things that TI refers to. This eliminates repeated manual entry and minimizes time to modify a TI.
Boolean or logic values are not necessary but can make one`s life easier.
I recommend reserved TM1 words like ELISANC or DIMIX to be spelled in capitals can help to avoid possible confusion with variables or constants.
Last but not least, indentation, which not many people know is actually a built-in function. The hotkey is Ctrl+I and it works like TAB in other text editors. The only thing that could upset TI editor is that an indent is treated as a special character and it does not act like space, so that ‘ TAB ’ and ‘ SPACES ‘ are treated differently: spaces are ignored while indents are not.