本文介绍了比较 Haskell 的 Snap 和 Yesod Web 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近新闻中的两个 Haskell Web 框架是 Yesod(0.8 版本)和 Snap(0.4 版).

The two Haskell web frameworks in the news recently are Yesod (at 0.8) and Snap (at 0.4).

很明显,Yesod 目前支持的功能比 Snap 多得多.但是,我无法忍受 Yesod 用于其 HTML、CSS 和 Javascript 的语法.

It's quite obvious that Yesod currently supports a lot more features than Snap. However, I can't stand the syntax Yesod uses for its HTML, CSS and Javascript.

所以,我想了解如果我改用 Snap,我会错过什么.例如,看起来没有数据库支持.会议怎么样?其他功能?

So, I'd like to understand what I'd be missing if I went with Snap instead. For example, doesn't look like database support is there. How about sessions? Other features?

推荐答案

完全披露:我是 Snap 的主要开发人员之一.

Full disclosure: I'm one of the lead developers of Snap.

首先,让我们谈谈什么是 Snap.目前,Snap 团队维护着五个不同的 hackage 项目:snap-core、snap-server、heist、snap 和 xmlhtml.snap-server 是一个 Web 服务器,它公开了 snap-core 定义的 API.heist 是一个模板系统.xmlhtml 是 heist 使用的 XML/HTML 解析和渲染库.snap 是一个伞形项目,将它们粘合在一起,并提供强大的 snaplets API,使网络应用程序可组合和模块化.

First of all, let's talk about what Snap is. Right now the Snap team maintains five different projects on hackage: snap-core, snap-server, heist, snap, and xmlhtml. snap-server is a web server that exposes the API defined by snap-core. heist is a templating system. xmlhtml is an XML/HTML parsing and rendering library used by heist. snap is an umbrella project that glues them all together and provides the powerful snaplets API that makes web apps composable and modular.

Yesod 有许多关于 hackage 的项目.其中大部分(全部?)都列在 Yesod 类别中.其中一些值得注意的是 yesod-core、warp、persistent 和 hamlet.

Yesod has a host of projects on hackage. Most (all?) of them are listed in the Yesod category. Some of the notable ones are yesod-core, warp, persistent, and hamlet.

Haskell Web 开发的现实是,它不像人们认为的那样是一种排他性或选择.一般来说,这些项目非常松散耦合并且可以互换.您可以使用 warp(Yesod 团队的 Web 服务器)、heist(Snap 团队的模板系统)和 acid-state(Happstack 项目的持久性系统)构建网站.您还可以将 snap-server 与 hamlet 或persistent 结合使用.

The reality of Haskell web development is that it's much less of an exclusive-or choice than seems to be perceived. In general the projects are very loosely coupled and fairly interchangeable. You could build a website using warp (the Yesod team's web server), heist (the Snap team's template system), and acid-state (the Happstack project's persistence system). You could also use snap-server with hamlet or persistent.

也就是说,这两个项目肯定存在一些差异.我可以客观指出的最大区别是 Yesod 项目通常大量使用 Template Haskell 和 quasiquoting 来创建简洁的 DSL,而 Snap 项目坚持构建有利于可组合性的组合器库.几乎我能想到的任何其他差异都会主观上偏向于 Snap.以这两个项目命名的伞包显然是要对上面提到的组件做出具体的选择,而这些选择会体现在项目依赖中.但这仍然并不意味着你不能引入不同的东西并使用它.

That said, the two projects definitely have some differences. The biggest difference I can point out objectively is that Yesod projects typically make heavy use of Template Haskell and quasiquoting to create concise DSLs, while Snap projects stick to building combinator libraries that favor composability. Just about any other differences I can think of will be subjectively biased towards Snap. The umbrella packages named after both projects are obviously going to make specific choices for the above mentioned components, and these choices will be reflected in the project dependencies. But that still doesn't mean that you can't pull in something different and use it as well.

Snap 确实有会话和身份验证、多个数据库的接口以及良好的表单处理(这里此处) 使用 digestive-functors,其中包括对任意嵌套的动态大小列表的预打包支持.这些只是不断增长的可插拔snaplets生态系统的一部分.会话和身份验证 snaplet 的编写方式与后端无关.因此,通过少量的胶水代码,您应该能够将它与您能想到的任何持久性系统一起使用.未来,Snap 将尽可能坚持这一政策.

Snap does have sessions and authentication, interfaces to several databases, and nice form handling (here and here) using digestive-functors that includes prepackaged support for arbitrarily nested dynamically sizable lists. These are just some of the growing ecosystem of pluggable snaplets. The sessions and authentication snaplets are written in a way that is back-end agnostic. So with a small amount of glue code you should be able to use it with just about any persistence system you can think of. In the future, Snap will stick with this policy as often as possible.

在大多数情况下,我认为选择 Snap、Yesod 还是 Happstack 与其说是功能问题,不如说是个人品味问题.每当有人说其中一个框架没有另一个框架拥有的东西时,大多数情况下,通过导入必要的包,可以很容易地从另一个框架中提取缺失的功能.

For the most part I think the choice of Snap vs Yesod vs Happstack is less an issue of features and more one of personal taste. Whenever someone says that one of the frameworks doesn't have something that another one has, most of the time it will be pretty easy to pull in the missing functionality from the other framework by importing the necessary package.

有关三大 Haskell Web 框架的更详细比较,请查看我最近的 博客文章.要使用一些更广泛的概括进行更粗略(但可能更有用)的比较,请参阅我的 Haskell Web Framework比较矩阵

For a more detailed comparison of the big three Haskell web frameworks check out my recent blog post. For a rougher (but possibly more useful) comparison using some broader generalizations, see my Haskell Web Framework Comparison Matrix

这篇关于比较 Haskell 的 Snap 和 Yesod Web 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:31