TI syntax

Post Reply
Dimix
Posts: 32
Joined: Fri Jan 15, 2016 2:53 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2013

TI syntax

Post by Dimix »

Hi all

Not sure if it makes a difference, but I’m still curious. Is there a ’correct’ way to enter syntax in TI? A very common way seems to be like below. No paces, no/limited indentations, etc.

Code: Select all

If(DimIx(pDim,pEle)=0);
 DimensionElementInsert(pDim,'',pEle,pEleType);
EndIf;
Maybe it’s just me, but I have a hard time reading this type of syntax, and I usually enter it like this. Function names in all caps, spaces after commas, spaces before and after parenthesis, etc. Much easier to read, or?

Code: Select all

IF ( DIMIX ( pDim, pEle ) = 0 );
		DIMENSIONELEMENTINSERT ( pDim, '', pEle, pEleType );
ENDIF;
‘My’ syntax works, but are there any drawbacks, e.g. performance, compared to the more common/correct(?) version?
User avatar
Alan Kirk
Site Admin
Posts: 6606
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: TI syntax

Post by Alan Kirk »

Dimix wrote: Not sure if it makes a difference, but I’m still curious. Is there a ’correct’ way to enter syntax in TI? A very common way seems to be like below. No paces, no/limited indentations, etc.

Code: Select all

If(DimIx(pDim,pEle)=0);
 DimensionElementInsert(pDim,'',pEle,pEleType);
EndIf;
Maybe it’s just me, but I have a hard time reading this type of syntax, and I usually enter it like this. Function names in all caps, spaces after commas, spaces before and after parenthesis, etc. Much easier to read, or?

Code: Select all

IF ( DIMIX ( pDim, pEle ) = 0 );
		DIMENSIONELEMENTINSERT ( pDim, '', pEle, pEleType );
ENDIF;
‘My’ syntax works, but are there any drawbacks, e.g. performance, compared to the more common/correct(?) version?
No; for this sort of thing TI ignores white space and is case insensitive so there is no performance difference between them.

Normally I space it out like yours, though I do use mixed case rather than ALL CAPS because I find it easier to read.

Most of the time when you see the syntax in the first instance it's because the default TI editor is a primordial pain in the @$$. It doesn't support indentation with tab keys, it certainly doesn't auto-indent in the way that pretty much any other IDE that has been written since the mid 90's does, it doesn't automatically space or adjust the capitalisation the way the Visual Basic IDE has since the last century, and so on. Find and replace or intellisense? Hah, you wish. (Though for all that I still prefer working through that than through the gently steaming pile of effluent that is Performance Muddler.)

The top example is usually the result of someone writing the code in the standard TI editor and not having the time or inclination to make it pretty. If someone is using an external editor like Notepad++ with the TM1 language the code is more likely to be spaced and indented.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
User avatar
qml
MVP
Posts: 1094
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: TI syntax

Post by qml »

Dimix wrote:Not sure if it makes a difference, but I’m still curious. Is there a ’correct’ way to enter syntax in TI? A very common way seems to be like below. No paces, no/limited indentations, etc.
Your question isn't about syntax, but about code formatting. It's easier to popularise coding standards if IDE tools enforce them, which, as Alan has eloquently explained, is not the case with any of the standard TM1 tools. There is quite a lot of TI code written by IBM (e.g. all the }tp_* processes) that could/should have set some standards, but didn't because that code itself didn't follow any standards consistently. The popularity of Bedrock seems to have had some standardising impact on people's code, but even that impact is quite limited.

Generally I think that those developers that tend to follow 'good' coding standards tend to be the ones that have experience with other programming languages and environments, which has taught them to recognise the benefits of good code structuring and formatting. But even among those developers there are some common themes as well as some clear disagreements, just like there are among software engineers in general. Just look at how many Indentation Battles (Spaces vs Tabs) have been fought on the Interwebz, something also exemplified by the length of this Wikipedia article: Indent Style.
Kamil Arendt
Post Reply