quick questions

4 views
Skip to first unread message

Harshad

unread,
Dec 28, 2008, 1:32:05 PM12/28/08
to SweetScala
Hi,

I was just evaluating the Sweet framework.

It looks interesting and the documentation is very helpful. Thanks!

Some questions:
1. Is freemarker really required? Given that scala supports XML
directly, couldn't we build a template system directly inside scala?
This would probably have two issues:
a. People who write templates may now need to understand Scala a
bit. (But then they don't need to learn another language like
freemarker)
b. Controller will need to be protected from the viewer using
separate packages.

2. A lot of places where there are maps from String -> _ could be
probably converted to Symbol -> _ to make things faster? For example,
"main" -> MainController could become `main -> MainController

Thanks in advance for your answers.

cheers,
Harshad

David Pollak

unread,
Dec 28, 2008, 1:59:12 PM12/28/08
to sweet...@googlegroups.com
Harshad,

Just as a note, String operations are much faster than Symbol operations.  Scala does not intern symbols and the JVM is tuned to optimize String operations.

Thanks,

David
--
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

thebug...@gmail.com

unread,
Dec 28, 2008, 2:14:28 PM12/28/08
to SweetScala
Hi Harshad,

Thanks for looking into Sweet codes. See my comments below...

On Dec 28, 1:32 pm, Harshad <harshad...@gmail.com> wrote:
> Hi,
>
> I was just evaluating the Sweet framework.
>
> It looks interesting and the documentation is very helpful. Thanks!
>
> Some questions:
> 1. Is freemarker really required? Given that scala supports XML
> directly, couldn't we build a template system directly inside scala?
We can, but I don't find it any more elegant, (or more importantly
more efficiently) than using a template language like Freemarker.
There is nothing stopping us to to use JSP or just the Scala xml as
View layer. Based on my experience, I found the Freemarker is very
productive(like debugging/error message, reloading of the templates
etc), so I choose it as default. One can write a separate View class
implementation in Sweet and replace it to what u want.

> This would probably have two issues:
>   a. People who write templates may now need to understand Scala a
> bit. (But then they don't need to learn another language like
> freemarker)
Scala is needed to write the controller, and yes it would be nice to
reuse in template too, but I firmly believe the separation of codes
from views, and Freemarker is not 100% to this, but can get very
close. One would simply need to create a Map of data and the framework
will expose it's names to template systems. Learning the syntax to
access this map is really not difficult... as I strongly encourage
view should just do that... loop and access the data and no fancy
logic. using Scala & XML as template will temp you to add logic view
at every corner. Maintaining it will be harder.

If Scala XML is your sweet spot as view, I encourage you take a look
at Lift(liftweb.net) project, they use that extensively.

>   b. Controller will need to be protected from the viewer using
> separate packages.
>
Not sure what you mean here.

> 2. A lot of places where there are maps from String -> _  could be
> probably converted to Symbol -> _ to make things faster? For example,
> "main" -> MainController could become `main -> MainController
>
Hum... I am not aware of the speed gain when using the Symbol, but if
it is I will think about it. Using string will appear more easier to
understand and easier to the eye than that Symbol if speed is the only
reason. I generally found Scala is pretty fast compared to all other
JVM languages (other than the java itself of course), so it won't be
my main focus for the moment.

Harshad RJ

unread,
Dec 28, 2008, 10:44:06 PM12/28/08
to sweet...@googlegroups.com
Thanks David!

I take back my suggestion.
--
Harshad RJ
http://hrj.wikidot.com

Harshad RJ

unread,
Jan 6, 2009, 1:47:06 PM1/6/09
to sweet...@googlegroups.com
On Mon, Dec 29, 2008 at 12:44 AM, thebug...@gmail.com <thebug...@gmail.com> wrote:

Hi Harshad,

Thanks for looking into Sweet codes. See my comments below...

On Dec 28, 1:32 pm, Harshad <harshad...@gmail.com> wrote:
> Hi,
>
> I was just evaluating the Sweet framework.
>
> It looks interesting and the documentation is very helpful. Thanks!
>
> Some questions:
> 1. Is freemarker really required? Given that scala supports XML
> directly, couldn't we build a template system directly inside scala?
We can, but I don't find it any more elegant, (or more importantly
more efficiently) than using a template language like Freemarker.
There is nothing stopping us to to use JSP or just the Scala xml as
View layer. Based on my experience, I found the Freemarker is very
productive(like debugging/error message, reloading of the templates
etc), so I choose it as default. One can write a separate View class
implementation in Sweet and replace it to what u want.

Thanks for those words Mr Bugslayer. This was the impetus I was looking for. I finally dived into Sweet code (which btw, is very neatly organised), before starting to write my own library from scratch.

I have written a blog entry about it here:
http://hrj.wikidot.com/blog:14


> This would probably have two issues:
>   a. People who write templates may now need to understand Scala a
> bit. (But then they don't need to learn another language like
> freemarker)
Scala is needed to write the controller, and yes it would be nice to
reuse in template too, but I firmly believe the separation of codes
from views, and Freemarker is not 100% to this, but can get very
close. One would simply need to create a Map of data and the framework
will expose it's names to template systems. Learning the syntax to
access this map is really not difficult... as I strongly encourage
view should just do that... loop and access the data and no fancy
logic. using Scala & XML as template will temp you to add logic view
at every corner. Maintaining it will be harder.

Yes, I agree. I was thinking of only small projects, but for a larger project what you say makes sense.
 
If Scala XML is your sweet spot as view, I encourage you take a look
at Lift(liftweb.net) project, they use that extensively.

I did look at Lift before. But what I meant with Scala XML was directly using the Scala language for XML manipulation. Something like:

def myResponse = <html> Hello { getAdjective } world </html>

Lift comes close, using a Lift specific DSL inside the XML, which is parsed at run-time. It would have its advantages surely, but probably not what I had in mind.



>   b. Controller will need to be protected from the viewer using
> separate packages.
>
Not sure what you mean here.

This relates to the point you made in your reply about too much flexibility in the view layer. One improper use of this flexibility could be that view layer code could access model & controller data-structures/code direclty.The natural way to separate these concerns in most languages is to use scoping and modules/packages.



> 2. A lot of places where there are maps from String -> _  could be
> probably converted to Symbol -> _ to make things faster? For example,
> "main" -> MainController could become `main -> MainController
>
Hum... I am not aware of the speed gain when using the Symbol, but if
it is I will think about it. Using string will appear more easier to
understand and easier to the eye than that Symbol if speed is the only
reason. I generally found Scala is pretty fast compared to all other
JVM languages (other than the java itself of course), so it won't be
my main focus for the moment.

As I replied to David, I take back my suggestion. I should have done some homework before making it in the first place.

cheers,

Zemian Deng

unread,
Jan 6, 2009, 6:50:47 PM1/6/09
to sweet...@googlegroups.com
Harshad,
Very cool, and thanks for the write up!

Feel free to share any Scala related topics here if you wish. 
Happy Scala programming. :)

Zemian
Reply all
Reply to author
Forward
0 new messages