assignin and eval functions
Show older comments
Hi everyone,
I have a question that really tangles my mind. The experienced contributors to the forum always emphasize avoiding usage of assignin and eval functions due to many reasons. I now know the reason for it thanks to Walter Roberson especially. Then why MATLAB does not stop their usage? I really need to be enlightened about this issue.
Accepted Answer
More Answers (1)
The actual question is:
why MATLAB does not stop their usage
The drawbacks of eval and assignin have been discussed exhaustively already and explanations of better solutions can be found in this forum and in the documentation of Matlab.
I think, MathWorks does not remove these functions from the toolboxes, because:
- this would break the backward compatibility of many codes. Although the usage is deprecated and the problems are known, some code does use them and they work - inefficient, hard to debug and maintain, but a kind of "successful". This applies e.g. to callbacks, which are defined as strings: They are evaluated in the base workspace, and I assume, this is performed by eval. Of course it is recommended for over 15 years now to use functions handles, but the string callbacks are still allowed.
- it is not the responsibility of MathWorks, if users write bad code. Even load and save can emulate an eval with all its drawbacks, or the automatic creation of an M-file as a script and the run command. There are many ways to drill a whole in your knee and it is impossible to create a programming language, which is powerful and 100% bulletproof at the same time. The users have to care for the reliability and efficiency of their codes. Therefore MathWorks can and should rely on the users to read the documentation and trust the suggestions of experienced users in the forum.
But this is my assumption only. As a member of this public forum I can speculate only - but you can do this by your own, because this speculation is rather obvious and trivial. If you want a real answer, you have to ask MathWorks, of course, not the users in the forum.
Categories
Find more on Parallel Computing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!