Is there ever a good reason to use eval()?

后端 未结 10 1098
清歌不尽
清歌不尽 2020-12-03 20:51

It seems to me that eval() is treated with the same disdain that goto is. And by eval, I mean a function for executing a string as code, as seen in

10条回答
  •  清歌不尽
    2020-12-03 21:13

    For quick hacks, no problem because it's a handy quick-out.

    In production code, consider it a last resort—and even then, try something else—because eval is difficult to control and thus dangerous. For anything non-trivial, implement a sublanguage.

提交回复
热议问题