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

后端 未结 10 1071
清歌不尽
清歌不尽 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:15

    For debugging/testing an idea before implementing it the proper way.

    For instance, you're making a toy calculator, and you want to work on the gui first, so you just use eval to do the "back-end" work in the background. Later, you come back to the back-end, scratch eval, and write a proper expression parser.

提交回复
热议问题