Michel Juillard michel.juillard@mjui.fr writes:
I'm worried about the use of persistent variables in Dynare. In several instances, they are only re-initialized if the variable is empty, meaning the first time that the function is used at the beginning of a session or after "clear all"
This behavior is wrong if the function with persistent variables is used twice in different contexts in the same *.mod file (identification_analysis and estimation, for example, or two successive estimations). Also, it creates hard to understand errors when debugging with option noclearall
This problem has already been reported in ticket #83: https://www.dynare.org/trac/ticket/83
Note that I am personally very strongly against the use of persistent variables. They are essentially equivalent to global variables, and therefore create the same very-hard-to-track-down bugs. The core of the problem is that when you use persistent (or global) variables, there is no guarantee that calling two times the same function with the same input arguments will give the same output. This is the opposite of functional programming, which is for me the most natural paradigm, especially for people with a mathematical background.
I therefore think that we should set the goal of removing all persistent variables, as removing all global variables is also a goal. Of course, removing all of them is probably not possible because of various resource constraints, but we should at least avoid introducing new ones.
Best,