Imposing variable in script
Show older comments
Hello everybody,
I am currently working with a script that uses many functions and sub-functions. The issue is that I have a variable defined at the beginning of the script, but it is changed at some point in one of the functions. I work with maybe 50 or more subfunctions for each of the functions and I can't narrow down where the variable is changed.
Is there a way to impose that the variable at the beginning of the script can not change later, even if it is redifined somewhere ?
I spent many hours trying to see where it changes my variables by making step-by-step and ctrl + F as much as possible, but this is taking too long to cover everything..
Thanks you in advance !
5 Comments
darova
on 23 Apr 2020
Please show your script
John D'Errico
on 23 Apr 2020
It sounds like there are 50 or so scripts.
V.D-C
on 23 Apr 2020
John D'Errico
on 23 Apr 2020
Edited: John D'Errico
on 23 Apr 2020
Another level of Dante's programming hell is to inherit a lengthy code from someone, and then need to use and maintain it. Sadly, Dante the programmer has many levels of hell. What always seems to happen is the inherited code has no comments, and was written in spaghetti style, so it is impossible to understand. Or the programmer uses really meaningful variable names, like l0o1.
I once inherited a piece of code that had only one comment in the entire mess: "Create C matrix here". The author then proceeded to create a matrix called C. Gosh, thanks. I re-wrote the code from scratch.
Another time, I was given a complex piece of object oriented programming in MATLAB, but again, no documentation provided. We spent a few days trying to decypher what it did and how to use it by testing the various options, not all of which worked. Again, the answer was it took me less time to rewrite it from scratch than it would have taken to learn to use the code, all the while avoiding the various bugs.
Steven Lord
on 23 Apr 2020
Scripts have the benefit of accessing and/or changing any variable in the workspace from which they are called.
Scripts have the drawback of accessing and/or changing any variable in the workspace from which they are called.
As you've worked to understand the collection of scripts and how they interact, I recommend trying to convert some of them into functions that state exactly what they need to do their work (their input arguments) and exactly what they're allowed to change (their output arguments.) This isn't something that you'd need to do all at once; you could chip away the problem a script at a time.
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!