Lift on Leopard

January 25, 2008

Until Steve Yegge's Code's Worst Enemy rant, I hadn't even heard of the language Scala. Although Steve made no mention of Scala in his article, there were plenty of people in the comments suggesting he check out Scala. Not surprisingly, it's getting a lot of love in the blogosphere now. I've read through some of the online documentation and next I wanted to see some code and the web framework for Scala seems to be Lift. I tried get the examples running on my Macbook Pro, which is running Leopard, and I ran into this error:

java.lang.IllegalStateException: The PluginDescriptor for the plugin 
Plugin [org.scala-tools:maven-scala-plugin] was not found.

Luckily I found this thread on the lift google group, which states that the problem is that the maven that comes installed on Leopard is 2.0.6, which doesn't work with Left. I installed 2.0.8 by putting maven at /usr/local/maven and adding /usr/local/maven/bin to my PATH. That got it working and after what seemed like a hour of downloading maven packages, Lift was up an running.

At first glance, I say the Lift Scala code looks just as verbose as Java code. Take this for example:

package com.hellolift.model

import net.liftweb.mapper._
import net.liftweb.util._
import net.liftweb.sitemap._
import net.liftweb.sitemap.Loc._

import com.hellolift.controller.BlogCache
import com.hellolift.controller.BlogCache._
import com.hellolift.controller.AddEntry

object Entry extends Entry with KeyedMetaMapper[Long, Entry] {
  override def dbTableName = "entries"
  // sitemap entry
  val sitemap = List(Menu(Loc("CreateEntry", "/entry", "Create An Entry", 
                     If(User.loggedIn_? _, "Please login"))), 
             Menu(Loc("ViewEntry", "/view", "View An Entry", Hidden)), 
             Menu(Loc("ViewBlog", "/blog", "View Blog")))

  // Once the transaction is committed, fill in the blog cache with this entry.
  override def afterCommit = 
    ((entry: Entry) => {BlogCache.cache ! AddEntry(entry, entry.author.is)}) :: Nil
}

class Entry extends KeyedMapper[Long, Entry] {
  def getSingleton = Entry // what's the "meta" server
  def primaryKeyField = id

  // Fields
  object id extends MappedLongIndex(this)
  object author extends MappedLongForeignKey(this, User) {
    override def dbDisplay_? = false
  }
  object title extends MappedString(this, 128)
  object body extends MappedTextarea(this, 20000) { // Lift Note: 7
    override def setFilter = notNull _  :: trim _ :: crop _ :: super.setFilter
  }
}

Maybe I'm just spoiled by the succinctness of Ruby, but that code doesn't strike me as immediately readable. There's what looks to be routing (URL Mapping) code in here, which strikes me as odd. The model doesn't seem like a very good place for routing code.

Posted in Technology | Tags Scala, Liftweb

Comments Disabled