I use the Echo[] function in order to help debug my code. However, I don't always want to execute an Echo[x] where x might be a variable (or expression) of interest. With that goal in mind, I created the function
If[flag == True,
myEcho[x_] := If[myEchoFlag, Echo[x]],
myEcho[x_] := Nothing;
];
So that if I want to see an output, I set the flag variable to True, otherwise I set it to False. My understanding is that in the case that flag is False, all the myEcho[x] calls would disappear. Often, the argument x is the result of a Plot command which can take time. At first, I thought that by using the
myEcho[x_] := Nothing;
version, this would skip the time-consuming execution of the x expression. That is not the case and after thinking about it I could understand how the expression x has to be evaluated first (therefore consuming time) before the interpreter figures out that the argument matches the pattern of being a match and thing assigning Nothing to the result.
On the other hand, as a programmer in more traditional languages (C,C++,C#), I was thinking that a compiler or interpreter would see that myEcho[anyPattern}] is Nothing and therefore would NOT EVEN compute the value of x, since no matter what comes out of the expression, the myEcho[x] should be Nothing.
Can anyone provide me with an alternative so that I have version of myEcho[x] which in one case of the flag variable simply calls the Echo[x], and in the other case is a "do nothing" expression that does not even compute the argument? I am pretty sure that there is a way, but would want to see what the experts say.
Thank you.