Lift/J getting Seven Things working as All-Java

36 views
Skip to first unread message

David Pollak

unread,
Feb 7, 2011, 4:00:11 PM2/7/11
to liftweb
Folks (especially Torsten),

As a proof of concept for Lift/J, I'd like to port the Seven Things code base to Java.  Basically, this will make use of most of Lift's cooler APIs and will likely force a thinking about how to structure the APIs.

I've created a liftj branch in Seven Things where we can do the work.  I've mostly gotten Boot.java updated: https://github.com/lift/seventhings/blob/liftj/src/main/java/bootstrap/liftweb/Boot.java

The first pattern I've got (and would really like feedback on this) is the "J" Java companion to Scala singletons.

For example, to access LiftRules, you use LiftRulesJ.j() and you've got all the LiftRules methods available to you.

Internally, for each singleton, I've got a Scala class named xxxJBridge (e.g., LiftRulesJBridge) with has a single method that will return the singleton.

In Java-land, I've got the J companion with the static j() method on it.  I chose a method over a final static because all Lift singletons will be mockable in 2.3 (LiftRules and DB are the prime candidates, S and SHtml contain no state so they don't need to be mockable.)

What this means is:

LiftRules.addToPackages(...)

becomes:

LiftRulesJ.j().addToPackages(...)

I'm also creating Java Func0-FuncXX interfaces with a Func.lift() method that lifts the Java representations to a Scala representation.  I'm also considering sitting Lift on top of Functional Java and use all the stuff that the Functional Java guys have already built (with some helper methods in either util or common that will bridge the Functional Java stuff to Scala stuff.)  Any opinions on writing our own vs. using Functional Java?

So... thoughts?  Feedback?

Thanks,

David

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

localgod

unread,
Feb 8, 2011, 2:08:36 AM2/8/11
to lif...@googlegroups.com
IMHO Seven Things is wonderful and Lift/J should be a fantastic vehicle for pushing Lift so from that perspective a Lift/J Seven Things sounds brilliant!  Thank you. :)

Christopher Taylor

unread,
Feb 8, 2011, 2:36:34 AM2/8/11
to lif...@googlegroups.com
On 02/07/2011 10:00 PM, David Pollak wrote:
> As a proof of concept for Lift/J, I'd like to port the Seven Things
> code base to Java. Basically, this will make use of most of Lift's
> cooler APIs and will likely force a thinking about how to structure
> the APIs.
>
> I've created a liftj branch in Seven Things where we can do the work.
> I've mostly gotten Boot.java updated:
> https://github.com/lift/seventhings/blob/liftj/src/main/java/bootstrap/liftweb/Boot.java

Cool! While I must admit I'm still on the fence regarding Lift's
polyglottism, I think you're doing excellent work here :).

> The first pattern I've got (and would really like feedback on this) is
> the "J" Java companion to Scala singletons.
>
> For example, to access LiftRules, you use LiftRulesJ.j() and you've
> got all the LiftRules methods available to you.
>
> Internally, for each singleton, I've got a Scala class named
> xxxJBridge (e.g., LiftRulesJBridge) with has a single method that will
> return the singleton.
>
> In Java-land, I've got the J companion with the static j() method on
> it. I chose a method over a final static because all Lift singletons
> will be mockable in 2.3 (LiftRules and DB are the prime candidates, S
> and SHtml contain no state so they don't need to be mockable.)
>
> What this means is:
>
> LiftRules.addToPackages(...)
>
> becomes:
>
> LiftRulesJ.j().addToPackages(...)

Another alternative would be to keep the same class names but have the
Java stuff live in a different package (e.g. net.liftweb.java). We could
have similar packages for support code for other languages, such as the
JRuby stuff.

I'm not sure how Scala objects (as in "object MyObj {}", not "val foo =
MyClass()") map to Java classes, but I think the ideal solution would be
a Java class with the same name, but in its own package, with the
object's methods exposed as java static methods (though I guess that
would interfere with the mockability you mention above).

> I'm also creating Java Func0-FuncXX interfaces with a Func.lift()
> method that lifts the Java representations to a Scala representation.
> I'm also considering sitting Lift on top of Functional Java and use
> all the stuff that the Functional Java guys have already built (with
> some helper methods in either util or common that will bridge the
> Functional Java stuff to Scala stuff.) Any opinions on writing our
> own vs. using Functional Java?

from a lazyness and code/knowledge-reuse perspective, I'd prefer using
Functional Java. I think there are too many Function interfaces in
JVM-land already (essentially every JVM language that supports
first-class functions has their own implementation).


Hope that makes sense :),
--Chris

Sander Mak

unread,
Feb 8, 2011, 2:40:00 AM2/8/11
to lif...@googlegroups.com
On Tue, Feb 8, 2011 at 8:36 AM, Christopher Taylor <ccmt...@gmail.com> wrote:
>> LiftRules.addToPackages(...)
>>
>> becomes:
>>
>> LiftRulesJ.j().addToPackages(...)
>
> Another alternative would be to keep the same class names but have the Java
> stuff live in a different package (e.g. net.liftweb.java). We could have
> similar packages for support code for other languages, such as the JRuby
> stuff.

Yeah, that sounds good. Having the J suffix on classnames makes the
API feel like a second-class citizen IMO.

> from a lazyness and code/knowledge-reuse perspective, I'd prefer using
> Functional Java. I think there are too many Function interfaces in JVM-land
> already (essentially every JVM language that supports first-class functions
> has their own implementation).

+1

Torsten Uhlmann

unread,
Feb 8, 2011, 3:25:50 AM2/8/11
to Lift

On Feb 7, 10:00 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Folks (especially Torsten),
>
> As a proof of concept for Lift/J, I'd like to port the Seven Things code
> base to Java.  Basically, this will make use of most of Lift's cooler APIs
> and will likely force a thinking about how to structure the APIs.
>
> I've created a liftj branch in Seven Things where we can do the work.  I've
> mostly gotten Boot.java updated:https://github.com/lift/seventhings/blob/liftj/src/main/java/bootstra...

I'll get to work.

> The first pattern I've got (and would really like feedback on this) is the
> "J" Java companion to Scala singletons.
>
> For example, to access LiftRules, you use LiftRulesJ.j() and you've got all
> the LiftRules methods available to you.
>
> Internally, for each singleton, I've got a Scala class named xxxJBridge
> (e.g., LiftRulesJBridge) with has a single method that will return the
> singleton.
>
> In Java-land, I've got the J companion with the static j() method on it.  I
> chose a method over a final static because all Lift singletons will be
> mockable in 2.3 (LiftRules and DB are the prime candidates, S and SHtml
> contain no state so they don't need to be mockable.)
>
> What this means is:
>
> LiftRules.addToPackages(...)
>
> becomes:
>
> LiftRulesJ.j().addToPackages(...)

Right now I don't really have a strong opinion which is better. Maybe
after I tried to work with it...

Concerning the naming (LiftRules vs LiftRulesJ) I tend to think
LiftRulesJ is better. The api between LiftRules and LiftRulesJ will
(probably)
be slightly different. I think a class with the same name should
always have the same signature, otherwise it might get confusing.

>
> I'm also creating Java Func0-FuncXX interfaces with a Func.lift() method
> that lifts the Java representations to a Scala representation.  I'm also
> considering sitting Lift on top of Functional Java and use all the stuff
> that the Functional Java guys have already built (with some helper methods
> in either util or common that will bridge the Functional Java stuff to Scala
> stuff.)  Any opinions on writing our own vs. using Functional Java?

I have only shortly looked at Functional Java. From a very high level
standpoint it seems like a framework to enable functional programming
in Java, maybe a bit like Google Collections (not comparing the API
though, only the use case) in it's field.

What we try to do with LiftJ on the other hand is building a bridge
between Java and Lift (in Scala), so we have a very specific need.
If we use Functional Java in the LiftJ API then we might hit a wall
where the API they provide does not meet our needs.

But it's entirely possible I'm totally wrong :)

Torsten.

>
> So... thoughts?  Feedback?
>
> Thanks,
>
> David
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890

Richard Dallaway

unread,
Feb 8, 2011, 4:00:48 AM2/8/11
to lif...@googlegroups.com

Regarding LiftRulesJ....

On Tue, Feb 8, 2011 at 7:36 AM, Christopher Taylor <ccmt...@gmail.com> wrote:
Another alternative would be to keep the same class names but have the Java stuff live in a different package (e.g. net.liftweb.java). We could have similar packages for support code for other languages, such as the JRuby stuff.

Sub-packaging might also help from an IDE point of view.  I.e., if you're doing code completion on the net.liftweb package, you're going to see a lot of classes that aren't relevant to the Java code you're writing (I assume, possibly incorrectly).   

Richard

Richard Dallaway

unread,
Feb 8, 2011, 4:12:01 AM2/8/11
to lif...@googlegroups.com
On Mon, Feb 7, 2011 at 9:00 PM, David Pollak <feeder.of...@gmail.com> wrote:
The first pattern I've got (and would really like feedback on this) is the "J" Java companion to Scala singletons.

For example, to access LiftRules, you use LiftRulesJ.j() and you've got all the LiftRules methods available to you.

A more standard name for the .j() call would be LiftRulesJ.getInstance() [Effective Java, 2nd ed, p.10], but it does look long-winded now.

Another approach would be to have it annotated and injected (hey, don't shoot the messenger! I'm just sayin'...)

@LiftRules
private LiftRulesJ rules;

Richard
Reply all
Reply to author
Forward
0 new messages