英文:
Coroutines or continuations for Web programming in Python and Ruby. Why not?
问题
问题是:为什么在Web编程中,Ruby中的continuations和Python中的coroutines没有被广泛使用?
服务器端的Web编程由于需要保留请求之间的状态而变得困难。两个优雅且相关的解决方案是continuations(在Scheme、Ruby和Smalltalk中)和coroutines(在Python和Go中)。
Bruce Tate在他的《超越Java》(O'Reilly,2005)一书中谈到了Ruby on Rails和Seaside作为Web编程中令人兴奋的新发展。对我来说,Seaside才是真正的突破:使用Smalltalk的continuations,Seaside使得编写复杂的请求/响应序列变得非常容易。
我知道Python中的coroutines被用于Tornado和Twisted以减少回调,但与编写一个单一coroutine来处理一系列HTTP请求以完成在线购买相比,那有点低级。
我想知道为什么这些在理论上看起来很好的想法在Python和Ruby中没有得到更广泛的应用。这只是一个文化问题吗?还是这些语言中实现的工具的限制?或者在Web开发的背景下,这些方法存在根本性的缺陷?
英文:
The question is: why aren't continuations (in Ruby) and coroutines (in Python) more widely used for Web programming?
Server-side web programming is made difficult by the problem of preserving state between requests. Two elegant, and related, solutions to this are continuations (as found in Scheme, Ruby and Smalltalk) and coroutines (as found in Python and Go).
Bruce Tate in his Beyond Java (O'Reilly, 2005) talked about Ruby on Rails and Seaside as exciting new developments in Web programming. To me, Seaside was the real breakthrough: using Smalltalk continuations, Seaside made it very easy to program complex request/response sequences.
I know about Python coroutines being used in Tornado and Twisted to reduce callbacks, but that is somewhat low-level, compared to writing a view/controller in a single coroutine to handle a sequence of HTTP requests to complete an online purchase, for example.
I wonder why these ideas that look so good on paper are not more widely deployed in Python and Ruby. Is it just a cultural matter? Limitations in the facilities as implemented in these languages? Or is there a fundamental flaw in these approaches in the context of Web development?
答案1
得分: 5
我使用过Seaside,而continuations是一种用于开发客户端服务器Web应用程序的美妙模型。它们简化了传统的客户端/服务器应用程序,我无法相信为什么没有其他语言在做这个。
但不幸的是,Web应用程序已经不再是过去的样子了。现在,通过ajax请求的不再只有一个页面,而是在不同的时间进行多个请求。这就是为什么continuations不像过去那样有用的原因。
即使是Seaside的原始作者Avi Bryant也说,在ajax下,使回调更容易(事件驱动编程)比continuations更重要。
请参考这个Quora讨论了解更多信息:
http://www.quora.com/Whats-the-best-continuation-based-web-framework
英文:
I've used Seaside and continuations are a beautiful model for developing client server webapps. They simplify traditional client/server applications that I couldn't believe
why no other langugage was doing it.
But unfortunately webapps aren't what they used to be.
Instead of the requesting only one page, now with ajax there are multiple requests at different times. That is why continuations aren't as useful as they used to be.
Even Avi Bryant (original author of Seaside) has said that under ajax making callbacks easier (event driven programming) is more important than continuations.
Take a look at this quora discussion for more:
http://www.quora.com/Whats-the-best-continuation-based-web-framework
答案2
得分: 1
你的应用程序应该使用continuation/coroutines框架编写,同时也要支持相关的库。这不是初学者容易理解的模型。
另外,还有更简单的框架,比如gevent,它提供了相同的功能来创建绿色线程,并且由于monkey patching的原因使用起来更容易。
英文:
You application should be written on continuation/coroutines framework, as well as support libraries too. It's not trivial model to understand by beginners.
Also there are much easier frameworks like gevent, which provides the same possibilities in making green threads, and easier to use because of monkey patching.
答案3
得分: 1
主要是因为非技术原因。了解Seaside甚至Smalltalk的人数很少,因此没有大量可以雇佣的廉价程序员。因此,了解如何安装和维护Seaside系统的服务提供商的数量也很少。
英文:
Mainly because of non-technical reasons. The number of people knowing Seaside or even Smalltalk is small, so there is no large pool of cheap programmers that can be hired. Because of this the number of service providers knowing how to install and maintain a Seaside system is also low.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论