I know that Lisp and Scheme programmers usually say that eval should be avoided unless strictly necessary. I’ve seen the same recommendation for several programming languages, but I’ve not yet seen a list of clear arguments against the use of eval. Where can I find an account of the potential problems of using eval?
For example, I know the problems of GOTO in procedural programming (makes programs unreadable and hard to maintain, makes security problems hard to find, etc), but I’ve never seen the arguments against eval.
Interestingly, the same arguments against GOTO should be valid against continuations, but I see that Schemers, for example, won’t say that continuations are "evil" -- you should just be careful when using them. They’re much more likely to frown upon code using eval than upon code using continuations (as far as I can see -- I could be wrong).
Edit: WOW, that was fast! Three answers in less than five minutes! So, the answers so far are:
- Not validating input from users and sending to eval is evil
- Using eval I may end up with interpreted code instead of compiled
- Eval could make code unreadable (although I think one can write unreadable code without any "powerful" features, so this is not much of an issue)
- Beginners may be confused mixing compile-time and evaluation-time when mixing eval and macros (but I think it's not an issue once you get a firm grasp of how your language works -- be it Lisp or other)
So far, it seems that if I generate code (and not directly use anything from user input directly); if I know what environment eval will be run; and if I'm not expecting super-fast code, then eval is OK.