Path: news.mathworks.com!not-for-mail
From: "Yuri Geshelin" <geshelin@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: eval, feval, global
Date: Sun, 30 Mar 2008 23:32:01 +0000 (UTC)
Organization: Bedford Institute of Oceanography
Lines: 53
Message-ID: <fsp7th$j9u$1@fred.mathworks.com>
References: <fsebf0$43u$1@fred.mathworks.com>
Reply-To: "Yuri Geshelin" <geshelin@hotmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1206919921 19774 172.30.248.35 (30 Mar 2008 23:32:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 30 Mar 2008 23:32:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1149396
Xref: news.mathworks.com comp.soft-sys.matlab:459973


"Yuri Geshelin" <geshelin@hotmail.com> wrote in message 
<fsebf0$43u$1@fred.mathworks.com>...
> 1) Why are eval, feval considered not elegant and banned 
in 
> programming contests? I often use eval, why should a good 
> programmer stay away from it?
> 
> 2) Same question about GLOBAL.
> 
> Yuri
> 

Sorry for bringing this up again. It's about the second 
issue: the use of GLOBAL. When John said that it "can make 
debugging an interesting task", I thought I had grasped the 
subject and agreed with him. But now I think I 
misunderstand something. 

Let me present you with a situation, which I ran across. It 
probably has to do with John&#8217;s remark. I was writing a GUI. 
It took me a while, I would put it off and get back to it 
in months. I was using dozens of GLOBAL variables. One day 
I realized that I needed to fix a bug in a button&#8217;s 
callback. I quickly wrote up a function, which takes care 
of the glitch. This should have been very simple, but I got 
an error message at the stage, when I least expected it. 
Here is what happened. I had global variable PROP and 
forgot about it, because I wasn&#8217;t working on my GUI for a 
month. Now, in order to accomplish the task at hand, I 
happened to use variable PROP again, but for a totally 
different purpose... And again, I declared it as global. No 
comments.....

This was what I recalled when John said that globals "can 
make debugging an interesting task". I do realize that this 
is a potential source of errors. But in terms of my 
example, please explain me how exactly I should follow 
these John&#8217;s recommendations:

"Stuff your parameters into a structure that gets passed 
around. Use nested functions."

I know how to use CLASS, if this is of any help. I just 
don't see how this would prevent me from making the same 
mistake.

Any comments on John D&#8217;Errico&#8217;s message of 26 March are 
appreciated.

Thanks,

Yuri