It was probably during 2010-2011 that I was first introduced to this technology. Coming from object-oriented programming background initially I found it difficult to grasp the detail, but I could imagine what wonders this technology can do. If you are coming from pure functional programming background, Arena Data Flow Language (ADFL) must look familiar. Today everything around Front Arena is centred around ADFL.
What is ADFL?
It is a declarative and expression-oriented programming language. There are no functions! So, you cannot group statements together. Instead, whole program is made up of individual expressions. Also, since there are no functions, there are no separate global and local namespaces. Every name resides in a global namespace.
Problem with Imperative languages
Let’s try to understand problem with imperative languages with an example so that you understand what ADFL is trying to solve.
Consider this python function which takes four integer arguments and returns their sum.
def add_four_numbers(n1, n2, n3, n4):
return n1 + n2 + n3 + n4
If I call this function passing following arguments (1, 2, 3, 4), this is what happens:
Step 1 => add 1 and 2 and store result (3) in a temporary memory location t1
Step 2 => add 3 and 3 and store result (6) in a temporary memory location t2
Step 3 => add 6 and 4 and store result (10) in a temporary memory location t3
Step 4 => return 10
All good so far.
Now I want to add another set of four numbers (1, 2, 3, 6). You see only the last number differs compared to earlier set. When add_four_numbers is called, Python is going to repeat all four steps even though steps 1 and 2 are same in both calls. This is not only a waste of computing resources, but it also consumes more time and delay in returning result.
Imagine a complex calculation that takes 2 seconds to execute, and I am getting an update to last number every second. In such a scenario, our function is going to choke up.
ADFL is the solution
Unlike Python, ADFL only recalculates part of the expression that has been updated. When calling ADFL with (1, 2, 3, 6), result of step 1 and step 2 are retained and only Step 3 is re-evaluated. Let me show you how that is done.
Consider this ADFL equivalent of above Python function:
result = n1 + n2 + n3 + n4
ADFL parser and executer creates a tree structure of this expression with each node representing either a variable or an intermediate result. Above expression will result into a tree structure shown below.
Calling this expression with (1,2,3,4) and then with (1,2,3,6) invalidates and re-evaluates only step 3.
ADFL unique features
Apart from performance improvement mentioned above, ADFL has some unique features:
- You can visually see the tree for an expression in Valuation Viewer application. It helps a lot when debugging.
- You can change node values to simulate and perform “what-if” analysis.
ADFL drawbacks
- If you are coming from objected oriented programming paradigm, you will find it hard to get used to ADFL.
- Front Arena extension editor is quite primitive compared to other commercial or free code editors.
- At times ADFL syntax can be quite overwhelming and hard to understand.
- Only way to see result of your ADFL code is to have a column in Trading Manager. Every time you make a change, you must reopen Trading Manager to check the result.
- ADFL documentation isn’t that great and quite hard to apply to any unique cases that you will encounter while working. You cannot find any help on the internet either.
ADFL pitfalls
- Since ADFL creates and retains all nodes involved in evaluating an expression and computation of goal value, this tree can quickly grow in size consuming excessive memory and can considerably degrade performance.
Conclusion
Even after all the drawbacks, ADFL is still a great technology and does its job quite well. Usage of ADFL in Front Arena will only increase in coming times.
0 Comments