gtonkin wrote:@admins - please move to Tips and Tricks as I cannot post there directly.
This one is mildly interesting but thought some folks may find it saving them a few keystrokes here and there.
Instead of writing the following in
TI:
Code: Select all
IF(SUBST(vDim, 1, 1)@='}');
ITEMSKIP;
ENDIF;
You can simply write:
Code: Select all
IF(SUBST(vDim, 1, 1)@='}', ITEMSKIP, 0);
The "0" seems to be continue i.e. do nothing for the ELSE/FALSE part of the IF statement.
Not finding any documentation on this in the Dev or TI guide - IF is probably not the best keyword to use either.
Any comments on this or other little/unknown tips to save fingertips?
Essentially the difference is that the block version is the TI implementation of If, and the single line is the Rules implementation of If which, being a Rules function, is of course available to TI as well. You're correct in your assessment of what it does and how.
It's not one of the more esoteric pieces of coding knowledge, but it's probably true that a lot of people "know" it (in the sense that they know you can use most Rules functions in TI) but don't know that they know it (in the sense that they've never really bothered to try to apply the Rules If() function when TI has its own perfectly serviceable syntax.)
I saw the Rules version used in some early code (early 2000's) that I inherited (and indeed it was often used for ItemSkip), and I probably used it myself a few times back then, but I moved away from it toward the block command. Not because I think there's anything actually
wrong with using the Rules If() function, simply because I find the block If makes the code more obvious and self-documenting. Also there's the fact that the Rules If essentially only works if you need to execute a single command like Itemskip; for any multi-line blocks you would have to use the Rules If block anyway which, IMHO would make the coding style more inconsistent and harder for anyone who comes after you to read.
If the True condition is a single line I think this one is down to a question of personal taste. My taste runs to not using it, but that's not to say that I think it's "wrong" to do so.