# Improving the readability of formulas through the formula’s variables

4.49K views
3

If Subx team enter such an object as formula’s variables in the QM, then the formulas will become much easier to write and read. For example, it could be implemented like this.
The formula editor will allow an optional section with the definition of formula’s variables according to this scheme:
*
[‘ – the opening tag of the formula’s variables definition section;
Set Variables: \$a = definition of the variable ‘a‘ through the QM functions;
…………………..\$b = definition of the variable ‘b‘ using the QM function;
……………………………………………………………………………………….;
…………………..\$n = definition of the variable ‘n‘ through the QM functions;
]‘ – the closing tag of the formula’s variables definition section.
*
Now, let’s look at the imaginary application of the formula’s variables in the formula from this forum.

*

Pay attention to how much easier it became to read If() logic. Imagine that you need to slightly to change the parameters of Select() – you will only do this once.
*
It would be interesting to hear your feedback on this proposal, so please speak out.

1

That is a very good idea. But I am not sure if my customers (especially not advanced) would find it easier (or say intuitive) to write formulas when they first should set variables (it looks a bit like programming).

1

Tahir, the formula’s variables should be an optional feature, despite the fact that in the second picture it is written “AS IT SHOULD BE”. Who wants to and to whom it is convenient, he will use the formula’s variables. The QM’s formula editor just needs to get this optional feature, and it’s up to the Modeler how to use it. Important, this option will significantly reduce the editing time and debugging time of complex and very complex formulas. The simple formulas can be written traditionally.
*
**
***
**
*
1. // This is my realy working formula. Who can quickly understand its logic?
: =
ClearZero( -If( Sum( Select( InvBuying::Qty, InvBuying::ByNum, #BuyLst ), If( #SellLst > 1, SellLst[1] .. SellLst[~PREV], 0 ) ) <
*
**
***
**
*
So, Anyone who likes this possible option, vote it.
Good luck.

2

Addition. Here’s how you could write this complicated formula using the formula’s variables:
*

*
I suggest to everyone to evaluate.

1

You have my vote, Sau. Although syntactically I think putting the variable definitions near the front of the formula (after any “In … ” statement, but before the item name whose value is being set) makes more sense than after the “=”. Or maybe it should be put at the very front of the formula in comments, with a special syntax similar to the old javadoc comment syntax.

1

Jlin, it would be interesting to look at your version of a possible implementation. Make a picture with your version of the above formula, we all compare the pros and cons of the two sentences.

2

For the exhibition only. See how clear the logic of the formula using the formula’s variable is compared to the regular one.
*

*
Is there anyone having an opinion on the topic? Or your models don’t have complicated formulas?

1

Sau,
The image of your sample code – how are you getting Quantrix to display the formulas in this way (with dark background)? It’s very nice on the eyes!

1

jlin,
In November 2015 I had requested Subx by email an option to set the formulas background color for QM6… Now it is already released QM8… So, for the reporting purposes i’m using 3rd party app converts QM’s formulas to formatted text with syntax highlighting against a dark background.