Scala 是“延续”吗?只是定义和使用回调函数的时髦语法?
我的意思是,在同样的意义上,C/Java for
只是 while
循环的一种时髦语法。
我仍然记得当第一次学习 C 中的 for 循环时,必须花很大的脑力去理解三个控制表达式相对于循环语句的执行顺序。在我看来,必须付出同样的努力来理解 Continuations(在 Scala 中,我想可能还有其他语言)。
然后是明显的后续问题......如果是这样,那么有什么意义呢?似乎经历了很多痛苦(语言复杂性、程序员错误、不可读的程序等)却没有任何收获。
And I mean that in the same sense that a C/Java for
is just a funky syntax for a while
loop.
I still remember when first learning about the for
loop in C, the mental effort that had to go into understanding the execution sequence of the three control expressions relative to the loop statement. Seems to me the same sort of effort has to be applied to understand Continuations (in Scala and I guess probably other languages).
And then there's the obvious follow-up question... if so, then what's the point? It seems like a lot of pain (language complexity, programmer errors, unreadable programs, etc) for no gain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从某种意义上说,是的,延续是使用回调的时髦语法。您可以在代码上手动执行非常复杂的全局转换(所谓的延续传递式转换),并且您将在没有直接语言支持的情况下获得延续。
但是,转换整个代码库可能不太实用,而且生成的代码很难阅读,因此让编译器在幕后为您完成此操作要好得多。
In some sense, yes, continuations are funky syntax for using callbacks. You can manually perform a very complex global transformation on your code (the so called continuation-passing-style transformation), and you will get continuations on your hands without direct language support.
However, transforming your entire codebase is probably not very practical, and the resulting code is hard to read, so having the compiler do it for you behind the scenes is MUCH better.