What is better option than using 'global' ?
61 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello all, In GUI, I am using plenty of global variables from which the performance gets influenced . I want to know what are the other alternatives of that and how to implement those programmatically ??
Thank you.
0 Kommentare
Antworten (2)
jmgoldba
am 7 Jul. 2023
"Globals are an unreliable way to pass values, and should be avoided."
Yeah, no. As the wiki link states: "Using globals is perfectly okay ... as long as you are careful about where, why, and how you use them." What's annoying is that Matab lint (or whatever it's called) flags the use of globals regardless.
I use globals as Matlab environment variables as opposed to getenv type, aka operating system environment variables which I limit to instances where the environment variable is useful across programming languages. As such, the globals I use are defined at Matlab startup and accessed as read-only. If Matlab lint wants to flag globals, it should only do so if their value is being set in a function.
13 Kommentare
jmgoldba
am 9 Jul. 2023
I know it's not going to happen, but I just wanted to complain. Following your fine analogy, my point is that I'm getting the "Driving" warning. Every. Time. Even when I'm in the parking lot loading groceries. And you guys are telling me it's never, ever safe to open the trunk (throw the groceries in the back seat :)
Mlint warnings have been helpful. They've led to solutions for otherwise hard to debug issues, they even got me off using cvsread and switching to tables. I just don't think they should be used for finger wagging, merely for using a statement provided by language.
Walter Roberson
am 10 Jul. 2023
Open an enhancement request with Support. There is a non-zero chance that you will get some sympathy from Support; you certainly are not likely to get any sympathy from the long-time professional programmers who volunteer here.
The long time volunteers here, the people who have helped hundreds or thousands of people, find that the great majority of users do need fingers wagged in their direction about globals -- that globals cause so many problems that they should only be used with reluctance.
Siehe auch
Kategorien
Mehr zu Software Development Tools finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!