|
"Husam Aldahiyat" <numandina@gmail.com> wrote in message <geek8i$8am$1@fred.mathworks.com>...
> Why? I know how to use it and have done so while creating cool pieces of code. The problem is that it seems "too easy" or too good to be true.
The problem is, you know how to MISUSE it.
Use of eval is one thing that is likely to create
difficult to find bugs in your code.
Eval is SLOW, at least relatively so. Code that
uses eval cannot be optimized by the parser
for efficiency.
The uses for eval that novices seem to find
are almost all things that can be done better,
faster, more easily, etc., using the existing
utilities in matlab. But, eval is the lazy way
out. Why learn to use the language as it can
be used when eval is there?
A good example of the evil eval is the user
who creates thousands of variables, named
something like x1, x2, x3, x4, x5, ...
Yes, this can be done using eval. Yes, it is
insane, since either a cell array, a structure,
or perhaps a higher dimensional array are all
better options, depending on the problem.
So, avoid eval, unless there is absolutely no
other option. And even then, look an extra
time for the other options. Those other
options are there, and they are better choices
than eval.
John
|