Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Why does everyone hate 'eval'?
Date: Fri, 12 Dec 2008 10:57:43 -0500
Organization: The MathWorks, Inc.
Lines: 65
Message-ID: <ghu1ln$pn9$1@fred.mathworks.com>
References: <ghrlim$oqo$1@fred.mathworks.com> <ghromj$f8g$1@fred.mathworks.com> <ghrplu$4in$1@fred.mathworks.com> <ghs7k6$993$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1229097463 26345 144.212.105.187 (12 Dec 2008 15:57:43 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 12 Dec 2008 15:57:43 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:506599


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in 
message news:ghs7k6$993$1@fred.mathworks.com...
> "Johan Carlson" <Johan.E.Carlson@gmail.com> wrote in message 
> <ghrplu$4in$1@fred.mathworks.com>...
>> ........
>> Now, if everything could be done without eval, why is it still there?
>> ........
>
>  Johan, I agree with your original assertion in the beginning of this 
> thread: "I still see the occasional use of eval as highly motivated."
>
>  In many of these discussions about the advisability of using the eval 
> command, I notice a strong tendency on the part of at least a few people 
> to transform the undoubtedly correct statement, "the eval instruction is 
> rarely needed" to the stronger but undoubtedly incorrect statement, "the 
> eval instruction should never be used."

I'm pretty sure that I'm one of the people that you're thinking of who seem 
to perform that transformation, and your point is taken.

In my mind, EVAL is like a chainsaw.  Its use should, IMO, be an "advanced 
maneuver".  It's a useful tool for certain situations, but can be very 
dangerous when used in a situation where it's not needed.  My goal in 
directing people to solutions other than EVAL is to discourage people from 
getting in the habit of using the chainsaw when a pair of scissors would do 
the job just fine.

>  The Mathworks' Product Support article 1103 states that "The EVAL 
> function is one of the most powerful, flexible, and potentially dangerous 
> functions in MATLAB."  It also says "There are two major drawbacks to the 
> EVAL function; the former can be avoided if you use EVAL carefully," the 
> former referring to "EVAL can be used to alter arbitrary variables."
>
>  It is important to note that they are definitely not saying to never use 
> eval, but to use it only in cases where it may really be needed in spite 
> of any drawbacks as to efficiency, ease of debugging, etc.  Such cases do 
> exist!

True.

>  That distinction between 'rarely' and 'never' is very important.  To say 
> 'never' would be to advise its complete removal and in my opinion that 
> would be a serious mistake.  It would be tantamount to Mathworks saying 
> that they can anticipate every conceivable task that their users could 
> ever possibly face and in none of these would eval ever be advisable.  I 
> don't think Mathworks wishes to put themselves in the position of making 
> such a decision for their users.

No, but ideally you should know how and when to use the scissors and the 
Swiss Army knife, and know that they can't solve the situation, before you 
pull out the chainsaw.

>  Final question.  Have I myself ever used eval?  Answer: yes.  Could I 
> have avoided its use in these cases?  Answer: yes, in many of them; no, in 
> others.  Would I like being deprived of ever using it?  Definitely not!

And no one is suggesting its removal, for several reasons [backwards 
compatibility and the cases where it's necessary, to name two.]

-- 
Steve Lord
slord@mathworks.com