Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Why does everyone hate 'eval'?
Date: Thu, 11 Dec 2008 22:08:02 +0000 (UTC)
Organization: Oxford University
Lines: 23
Message-ID: <ghs302$qm8$1@fred.mathworks.com>
References: <ghrlim$oqo$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1229033282 27336 172.30.248.35 (11 Dec 2008 22:08:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 11 Dec 2008 22:08:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1073021
Xref: news.mathworks.com comp.soft-sys.matlab:506435


"Johan Carlson" <Johan.E.Carlson@gmail.com> wrote in message <ghrlim$oqo$1@fred.mathworks.com>...
> Hey guys!
> 
> I've been running into comments like "NO, NO, NO, WHATEVER YOU DO,  DO NOT USE EVAL!!!!' in various posts during the past few weeks.
> 
> OK, I can see that over-use of eval would create, cool-looking, but totally unreadable and inefficient code.
> 
> But, are there any other reasons to hate eval this much? 
> 
> Good coding style on the one hand, I still see the occasional use of eval as highly motivated.
> 
> Comments?
> 
> /JC

I use eval to append the current solution of an iterative program to a mat file.
E.g.
varname = ['A' num2str(iter)];
eval([varname ' = A;']);
save('progress.mat', '-append', varname);
clear(varname);

Obviously A is sufficiently large that I don't want to store lots of variations of it in memory. I don't see any way of achieving the above without eval - I'd rather not have a profusion of mat files, though clearly this is an alternative solution. That is the only time I use eval.