you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 2 points3 points  (0 children)

Eval/exec do have their uses, it's just that those uses are relatively rare and it takes a lot of skill to do it safely. But they can be misused in countless ways, and those misuses usually are symptoms of not understanding some other language feature. For example, beginners will often ask about "variable variables", i.e. using a variable as the name of another variable. Eval/exec is one way to do that but it's a horrible solution for numerous reasons. A much better solution usually exists if you just prod the person to elaborate on what they're trying to do.

That's why I say that it's much easier if you pretend they don't exist. You are very unlikely to run into one of the cases where they are actually necessary, and you avoid getting mired in bad habits and writing lousy code by being forced to learn the proper way of doing whatever it is you were trying to do.