What is better option than using 'global' ?

조회 수: 60 (최근 30일)
yogesh jain
yogesh jain 2016년 3월 3일
댓글: Walter Roberson 2023년 7월 10일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by