Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: eval, feval, global
Date: Wed, 26 Mar 2008 20:54:02 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 39
Message-ID: <fsed5a$r5k$1@fred.mathworks.com>
References: <fsebf0$43u$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1206564842 27828 172.30.248.37 (26 Mar 2008 20:54:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 26 Mar 2008 20:54:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:459357


"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

I use eval, well almost never.

If you are using eval to create variable names,
especially sequences of variables, this is poor
coding style. Use an array instead. After all
Matlab is designed to work with arrays. Eval
is evil.

In terms of programming contests, I think I
recall that there were some potential hacking
issues with eval.

As for globals, again, I never use global
variables. I can't think of a use I've had
for them for many years. They can make
debugging an interesting task. And since
all they do is change how variables are
passed around, why bother with them?
Stuff your parameters into a structure that
gets passed around. Use nested functions.

Its like goto. Yes, you can use the construct,
but there are just too many good alternatives,
and the net result of gotos liberally spread
around your code is almost always bad. The
same logic applies to globals. They encourage
sloppy programming.

John