What is better option than using 'global' ?

66 次查看(过去 30 天)
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.

回答(2 个)

Stephen23
Stephen23 2016-3-3
编辑:Stephen23 2016-3-3

jmgoldba
jmgoldba 2023-7-7
"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 个评论
jmgoldba
jmgoldba 2023-7-9
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
Walter Roberson 2023-7-10
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Software Development Tools 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by