4
|
Willis Blackburn · 技术社区 · 15 年前 |
![]() |
1
2
I think the main reason is for tooling support. It is easier to support tooling when part of the project is strictly XML (the template files). It is far trickier (though not impossible), to manipulate code from a design tool. Also, in most production environments, the abstraction of business logic from the "view" (using whatever paradigm you like best, MVC, MVP, etc..) is critical. Any project large enough would likely be too unwieldy to go without it. Remember that in production environments, there are often more than one programmer, and sometimes new programmers join the team or existing ones move, so it's not really optional. Most of the efforts of web framework designers are invested in this use case, so functionality which breaks this abstraction is less of a priority. However, I could see where an internal scala DSL for web development might be useful for small projects. It would certainly not be unwise to invest your time in creating a light-weight framework for such use, if you would find it useful. Chances are, if you created it and found it useful, others might too. 建议资源: |
![]() |
2
2
简短的回答是:两者都是。 You don't "have" to use templates even with Lift - you can write views directly in code. Little-documented, but possible. 但是,如果您尝试,您将很快发现视图代码在布局和样式方面变得越来越难看。如果你想尝尝,可以尝试复制,比如说,原始scala;中的facebook首页。 If more than 2-3 people are working on a project, separation of responsibilities naturally arises. 模型视图控制器之所以流行,并不是因为Web是它的一个很好的例子(它是它的一个真正的例子),但是因为它是这样一种职责分离的最佳逼近——HTML/CSS/JavaScript通常不是PHP/Java/Scala人,并且这两种类型都需要能够独立地生产。 In short, if you wish to write your views in Scala, may I advise figuring out how to do it in Lift - you get generous amounts of other tasty booty for taking the time to learn it. Once you've written perhaps an app or two that way, ask yourself if it was an experience you 'd wish to repeat. :) |
![]() |
3
1
Your argument with the powerful XML support works both ways, I think. Because of the powerful XML support, it is possible to define your own tags in the template not only to bind variables but also to do some XML transformations inside your template. For example, you can define a wrapper tag which takes all inner table nodes and adds odd and even classes to each of the rows. (见 this 当然,您也可以在listify(或tabulify)方法中进行此操作,但这样会失去更多的纯度。
For simple applications with just a few controllers, I think it is possible to do without templates as is shown by the already quoted
step framework
. You just say âprint that listâ and are done. For larger frameworks however, your logic obviously gets more and more complicated. There needs to be a way to tell the application when and where each controller needs to be called. Youâre likely to define that in a single XML document â and there it is again, your XML template you wanted to get rid of.
Now, the lift XML templates are decidedly non-scala-esque, so there is no direct way to insert scala-logic. Other frameworks might have chosen a different route. But also in lift, I think, you could just create a custom XML tag for your HTML body and then have a function where you deliberately mix scala code with XML stuff to produce your output. |