Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 825
Owen Avatar asked Sep 05 '11 05:09

Owen


2 Answers

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.

like image 153
Khurram Ijaz Avatar answered Sep 18 '22 15:09

Khurram Ijaz


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.

like image 28
Debilski Avatar answered Sep 17 '22 15:09

Debilski