Why do web development frameworks tend to work around the static features of languages?
Asked Answered
L

2

9

I was a little surprised when I started using Lift how heavily it uses reflection (or appears to), it was a little unexpected in a statically-typed functional language. My experience with JSP was similar.

I'm pretty new to web development, so I don't really know how these tools work, but I'm wondering,

  1. What aspects of web development encourage using reflection?

  2. Are there any tools (in statically typed languages) that handle (1) referring to code from a template page (2) object-relational mapping, in a way that does not use reflection?

Lutes answered 5/9, 2011 at 5:3 Comment(0)
B
2

Please see lift source. It doesn't use reflection for most of the code that I have studied. Almost everything is statically typed. If you are referring to lift views they are processed as Xml nodes, that too is not reflection.

Blacksmith answered 5/9, 2011 at 6:40 Comment(3)
What I was referring to was things like <lift:Foo.bar/> referring to bar: NodeSeq => NodeSeq in object Foo. How could it find that method if not for reflection? (also, if bar doesn't exist this is not found until the page is loaded, so even if it's not reflection it is not static).Lutes
Though I'm super-new at lift. If there's a way to get the same functionality as <lift:Foo.bar/> that is more static please tell me.Lutes
@Lutes - That's tricky, given that the file template containing the <lift:Foo.bar/> is basically just one big string, and inherently not very static. Having said that, I believe that there are ways to register snippets and not need reflection for the lookup though.Knuckle
T
2

Specifically referring to the <lift:Foo.bar/> issue:

When <lift:Foo.bar/> is encountered in the code, Lift makes a few guesses, how the original name should have been (different naming conventions) and then calls java.lang.Class.forName to get the class. (Relevant code in LiftSession.scala and ClassHelpers.scala.) It will only find classes registered with addToPackages during boot.

Note that it is also possible (and common) to register classes and methods manually. Convention is still that all transformations must be of the form NodeSeq => NodeSeq because that is the only thing which makes sense for an untyped HTML/XHTML output.

So, what you have is Lift‘s internal registry of node transformations on one side, and on the other side the implicit registry of the module. Both types use a simple string lookup to execute a method. I guess it is arguable if one is more reflection based than the other.

Terena answered 5/9, 2011 at 8:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.