Snippet with no reflection an no massive case statement

6 views
Skip to first unread message

Hugo Palma

unread,
Feb 9, 2010, 11:54:27 AM2/9/10
to Lift
I just read http://wiki.github.com/dpp/liftweb/about-snippets and i
have the following question:

So is really the only way to avoid having a reflection call every time
you use a snippet to use a DispatchSnippet with a case statement for
every method ?
It's just that i don't really think that the case is a very clean way
of doing things. Can be ok for a couple of methods but it can be
really ugly with more than that.

So, is there any other way ?
Thanks.

Timothy Perrett

unread,
Feb 9, 2010, 12:01:39 PM2/9/10
to lif...@googlegroups.com
So you don't want to write any explicit mapping, and you don't want to use reflection??? How would you propose Lift know what your asking for?

Im afraid voodoo is not yet compatible with the JVM ;-)

Cheers, Tim

> --
> You received this message because you are subscribed to the Google Groups "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
>
>

David Pollak

unread,
Feb 9, 2010, 12:07:56 PM2/9/10
to lif...@googlegroups.com
Rather than complain about things, it would be helpful if you offered suggestions or alternatives.  You complained about Lift's use of Maven to bootstrap without offering alternatives.

On Tue, Feb 9, 2010 at 8:54 AM, Hugo Palma <hugo.m...@gmail.com> wrote:
I just read http://wiki.github.com/dpp/liftweb/about-snippets and i
have the following question:

So is really the only way to avoid having a reflection call every time
you use a snippet

What is your objection to using reflection?
 
to use a DispatchSnippet with a case statement for
every method ?

Keep in mind that a Map() in Scala is a partial function, so you can do the following:

class MySnippets extends DispatchSnippet {
  def dispatch = Map("hello" -> hello _, "bye" -> bye _)

  def hello(in: NodeSeq): NodeSeq = ...
  def bye(in: NodeSeq): NodeSeq = ...
}
 
It's just that i don't really think that the case is a very clean way
of doing things.

So, what's cleaner?  What web framework do you know of that doesn't use reflection, doesn't use XML configurations and doesn't do explicit mapping?
 
Can be ok for a couple of methods but it can be
really ugly with more than that.

So, is there any other way ?

There are numerous ways to associate snippets globally or with a particular page.  If you could talk about your goals or alternatively the way your favorite web framework does things, that would be a lot more helpful.

Thanks,

David
 
Thanks.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

Hugo Palma

unread,
Feb 9, 2010, 12:10:34 PM2/9/10
to Lift
Why doesn't Lift create the mapping at startup using reflection ?
It's not using reflection that's the problem, it's using reflection at
runtime for every single snippet usage.

I may be over simplifying things, but if at startup Lift would go
through all snippet classes and using reflection found all the methods
kept all the mappings somewhere in memory i think it could work.
Is this doable ?

On 9 Fev, 17:01, Timothy Perrett <timo...@getintheloop.eu> wrote:
> So you don't want to write any explicit mapping, and you don't want to use reflection??? How would you propose Lift know what your asking for?
>
> Im afraid voodoo is not yet compatible with the JVM ;-)
>
> Cheers, Tim
>
> On 9 Feb 2010, at 16:54, Hugo Palma wrote:
>
>
>

> > I just readhttp://wiki.github.com/dpp/liftweb/about-snippetsand i

David Pollak

unread,
Feb 9, 2010, 12:14:06 PM2/9/10
to lif...@googlegroups.com
On Tue, Feb 9, 2010 at 9:10 AM, Hugo Palma <hugo.m...@gmail.com> wrote:
Why doesn't Lift create the mapping at startup using reflection ?
It's not using reflection that's the problem, it's using reflection at
runtime for every single snippet usage.

Why do you care?  The cost of doing a method dispatch via reflection is about 5x the cost of a doing a method call on an interface with is about 2x more costly than doing a method call on a class.  The amount of time to do reflection on the 10 or 20 snippets you may have on a page is unmeasurably small compared to the cost of rendering the page.
 

I may be over simplifying things, but if at startup Lift would go
through all snippet classes and using reflection found all the methods
kept all the mappings somewhere in memory i think it could work.
Is this doable ?

No, it is not possible at start-up time to determine all the classes that might be snippets.
 

On 9 Fev, 17:01, Timothy Perrett <timo...@getintheloop.eu> wrote:
> So you don't want to write any explicit mapping, and you don't want to use reflection??? How would you propose Lift know what your asking for?
>
> Im afraid voodoo is not yet compatible with the JVM ;-)
>
> Cheers, Tim
>
> On 9 Feb 2010, at 16:54, Hugo Palma wrote:
>
>
>
> > I just readhttp://wiki.github.com/dpp/liftweb/about-snippetsand i
> > have the following question:
>
> > So is really the only way to avoid having a reflection call every time
> > you use a snippet to use a DispatchSnippet with a case statement for
> > every method ?
> > It's just that i don't really think that the case is a very clean way
> > of doing things. Can be ok for a couple of methods but it can be
> > really ugly with more than that.
>
> > So, is there any other way ?
> > Thanks.
>
> > --
> > You received this message because you are subscribed to the Google Groups "Lift" group.
> > To post to this group, send email to lif...@googlegroups.com.
> > To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/liftweb?hl=en.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

Hugo Palma

unread,
Feb 9, 2010, 12:23:31 PM2/9/10
to Lift
I just started using Lift so i'm trying to understand the "Lift way"
of doing things.
I offer suggestions whenever i think it's a valid one and i'm not just
saying something that doesn't bring any value to the discussion.
Hopefully that will happen more in the future as i learn more about
the framework.

Thanks for you help.

Hugo Palma

unread,
Feb 9, 2010, 12:24:43 PM2/9/10
to Lift
I care because in the wiki it says this about reflection snippets:

"works perfectly for development / low volume deployment"

which isn't the case for the application i'm building.

On 9 Fev, 17:14, David Pollak <feeder.of.the.be...@gmail.com> wrote:

> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com >


> > .
> > > > For more options, visit this group athttp://
> > groups.google.com/group/liftweb?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Lift" group.
> > To post to this group, send email to lif...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com >


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net

> Beginning Scalahttp://www.apress.com/book/view/1430219890

Naftoli Gugenheim

unread,
Feb 10, 2010, 1:56:01 AM2/10/10
to lif...@googlegroups.com
Besides, would it even help? Is the time in obtaining a Method instance rather than invoking it?

-------------------------------------
David Pollak<feeder.of...@gmail.com> wrote:


--

Lift, the simply functional web framework http://liftweb.net

Beginning Scala http://www.apress.com/book/view/1430219890


Follow me: http://twitter.com/dpp
Surf the harmonics

--

You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.

To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.

Hugo Palma

unread,
Feb 10, 2010, 5:53:13 AM2/10/10
to lif...@googlegroups.com
Again,
the only reason i raised this question it's because i was alarmed by what the wiki page about reflection snippets says:

"works perfectly for development / low volume deployment, however when your site starts to scale this method of snippet modeling may become undesirable."

All i would like is some clarification if this statement is in fact true, if not i will go on with my project happily using reflection snippets. If it is true i then would be looking for a better alternative.

David Pollak

unread,
Feb 10, 2010, 11:16:12 AM2/10/10
to lif...@googlegroups.com
On Wed, Feb 10, 2010 at 2:53 AM, Hugo Palma <hugo.m...@gmail.com> wrote:
Again,
the only reason i raised this question it's because i was alarmed by what the wiki page about reflection snippets says:

"works perfectly for development / low volume deployment, however when your site starts to scale this method of snippet modeling may become undesirable."

All i would like is some clarification if this statement is in fact true, if not i will go on with my project happily using reflection snippets. If it is true i then would be looking for a better alternative.

It is much better practice in my opinion to use an explicit dispatch.  But you do whatever you want.  If it becomes a performance problem for you and you're on a production site, then we'll look at it.

More broadly, we like to help newbies and folks with live production sites.  But, we also expect that newbies will bring us real issues that they themselves are facing, not premature optimizations.  We have limited time to help people and wasting (and this thread has crossed seriously into time-wasting land) time with stuff that doesn't really impact you means that (1) you will get a lot less attention in the future (think the boy who cried wolf) and (2) it lowers the quality of discussion for the rest of the folks on the list.

Net-net: if you like using snippets by reflection, then go right ahead.  If you want features in Lift, don't take a dogmatic approach, but look at what's there already.
 

Adam Warski

unread,
Feb 10, 2010, 11:57:46 AM2/10/10
to lif...@googlegroups.com
>
> All i would like is some clarification if this statement is in fact true, if not i will go on with my project happily using reflection snippets. If it is true i then would be looking for a better alternative.
>
> It is much better practice in my opinion to use an explicit dispatch. But you do whatever you want. If it becomes a performance problem for you and you're on a production site, then we'll look at it.
>
> More broadly, we like to help newbies and folks with live production sites. But, we also expect that newbies will bring us real issues that they themselves are facing, not premature optimizations. We have limited time to help people and wasting (and this thread has crossed seriously into time-wasting land) time with stuff that doesn't really impact you means that (1) you will get a lot less attention in the future (think the boy who cried wolf) and (2) it lowers the quality of discussion for the rest of the folks on the list.

I really don't get your response, as Hugo just asked about a statement on the wikipage, which very clearly says that using reflection snippets brings a performance hit and is discouraged to be used in production. Now, it may very well be that this statement shouldn't be there as it's not true - which is your opinion I think.

Maybe it would be better to write something like:
"If you are experiencing performance problems because of too many reflection calls, the cause may be using reflection snippets. Consider using dispatch snippets".

But why do you say to new users who just ask about statements from the wiki that their posts are time-wasting and that they can get less attention in the future I really don't understand.

Peace :)

--
Adam Warski
http://www.warski.org
http://www.softwaremill.eu


David Pollak

unread,
Feb 10, 2010, 12:08:36 PM2/10/10
to lif...@googlegroups.com
On Wed, Feb 10, 2010 at 8:57 AM, Adam Warski <ad...@warski.org> wrote:
>
> All i would like is some clarification if this statement is in fact true, if not i will go on with my project happily using reflection snippets. If it is true i then would be looking for a better alternative.
>
> It is much better practice in my opinion to use an explicit dispatch.  But you do whatever you want.  If it becomes a performance problem for you and you're on a production site, then we'll look at it.
>
> More broadly, we like to help newbies and folks with live production sites.  But, we also expect that newbies will bring us real issues that they themselves are facing, not premature optimizations.  We have limited time to help people and wasting (and this thread has crossed seriously into time-wasting land) time with stuff that doesn't really impact you means that (1) you will get a lot less attention in the future (think the boy who cried wolf) and (2) it lowers the quality of discussion for the rest of the folks on the list.

I really don't get your response, as Hugo just asked about a statement on the wikipage, which very clearly says that using reflection snippets brings a performance hit and is discouraged to be used in production. Now, it may very well be that this statement shouldn't be there as it's not true - which is your opinion I think.

My "opinion" is that using dispatch snippets is the best practice because it's clearer to other team members what's going on.
 

Maybe it would be better to write something like:
"If you are experiencing performance problems because of too many reflection calls, the cause may be using reflection snippets. Consider using dispatch snippets".

I did not write the wiki entry.  I rarely post to the wiki.  You can write whatever you want.
 

But why do you say to new users who just ask about statements from the wiki that their posts are time-wasting and that they can get less attention in the future I really don't understand.

Please read the entire thread and the other threads that Hugo has started.  Hugo is pushing on this issue (without any real basis, measurement, problems, statistics) and not letting it go.  I've answered his question a number of times (using dispatch snippets is best practices [more from a code readability standpoint, but also there is a minor performance penalty]) and he keeps harping on the issue.

If you repeat the same question over and over *after Tim and I have answered it* it is a waste of time.

David
 




--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

Adam Warski

unread,
Feb 10, 2010, 12:23:28 PM2/10/10
to lif...@googlegroups.com

> Please read the entire thread and the other threads that Hugo has started. Hugo is pushing on this issue (without any real basis, measurement, problems, statistics) and not letting it go. I've answered his question a number of times (using dispatch snippets is best practices [more from a code readability standpoint, but also there is a minor performance penalty]) and he keeps harping on the issue.

I think that the statement on the wiki may sound too authoritative and that may be the source of misunderstanding - I'll edit the wiki to clear this up. I remember I've also wondered about this sentence when I was starting to get to know lift.

Hugo Palma

unread,
Feb 10, 2010, 1:02:23 PM2/10/10
to lif...@googlegroups.com
I don't understand why people are being so aggressive on this list, i'm just looking to understand how Lift works and i think it's normal to have questions that many people here maybe will find that don't really make sense. Still, i think i've been able to structure my questions fairly well and i've been getting a really nor friendly replies. 
Yes i've insisted on the questions more than once, but that's because i found that none of the answers were explanatory.

IMHO you guys should really appreciate more the questions and opinions from newcomers because sometimes they can provide a fresh look on things, even thought sometimes them may seem "stupid".

Anyway, i'll drop this subject and i'm sorry if i was too pushy on this thread. My intentions were the best.
Thanks.
Reply all
Reply to author
Forward
0 new messages