CSC/ECE 517 Fall 2014/ch1a 4 lf

From Expertiza_Wiki
Revision as of 19:03, 14 September 2014 by Sjshah (talk | contribs)
Jump to navigation Jump to search

Lift is a web application framework designed for Scala Programming Language. It was designed by David Polka who was dissatisfied with Ruby on Rails. It was launched on February 26, in 2007 as an Open Source framework under the Apache 2.0 License.

Background

Lift

Lift is an expressive framework for building web applications using Scala. It borrows concept from Grails, Ruby on Rails, Seaside, Wicket and Django<ref name = "LiftWiki">Lift (web framework), Wikipedia</ref>. Lift is designed to make powerful techniques easily accessible, while keeping the overall framework simple and flexible.<ref name = "Book"> Derek Chen-Beccker et al. The Definitive Guide to Lift </ref>

Just like Rails, it favors convention over configuration: it decreases the number of decisions that developers need to make. But, unlike Rails, it does not follow the Model-View-Controller concept. It rather follows the "View First" approach, i.e., it focuses on what to display on the page rather than focusing on the programming of the objects and the logic that builds the page. The creators of Lift have cherry-picked the best ideas from a number of other frameworks, while adding some ideas on their own. Lift is intended to work out of the box and to make creating web pages as efficient and productive as possible<ref name="Book" />

As Lift is a framework for Scala and Scala is very compatible with Java, any and all of the java libraries and web containers can be used in running Lift applications.

Dynamic web content is authored into the web pages via templates using the standard HTML5 or XHTML editors. It also provides native support for advanced web development techniques such as Comet and Ajax.

The main characteristics of the Lift framework are:

  • Resistant to common vulnerabilities
  • Fast to build, concise and easy to maintain
  • High performance and scale in the real world to handle big traffic levels
  • Interactive like a desktop application


Scala

Scala stands for "Scalable Language". Scala is a relatively new language developed by Martin Odersky and his programming language research group at EPFL in Switzerland. The Scala programming language can be used for making general software application, or for web development. Scala is a pure-bred object-oriented language: Every value is an object, and every operation is a method call. The language is quite similar to Ruby.

The biggest difference between Ruby and Scala is that, Scala compiles to Java bytecode and runs on the Java Virtual Machine. Thus, it is possible to mix up Java and Scala. Both the languages can be used together for a single project; Scala code can refer the Java code and Java code can refer Scala code without any errors turning up. Scala introduces some very powerful features designed to make the developer more productive. Some of the features are :

  • Extremely rich type system
  • A powerful type inference
  • Native XML processing
  • Full support for closures and functions as objects
  • Extensive high-level library

Scala is called "the statically typed dynamic language"<ref name = "Book"/>. It is possible to write code as quickly as with dynamically typed languages like Python, Ruby etc, but the language offers compile-time type safety like Java.

Scala is a also a hybrid functional and object-oriented language, which means one can get the power of the higher-level functional programming languages while retaining the modularity and reusability of OO components. The language uses very strong static type system and the compiler deciphers the types of the variables used. Just like Ruby, programs written in Scala can be very concise and thus, are smaller in size than in most languages.


Examples

Basic Scala

Skip this if you know Scala and how to use Lift.

Scala is an extremely flexible and feature-ful language, but you don't need to know much about it to get started with Lift. Read more about Scala some time, but here is all I think you need to know to get started if you already know Java or a similar language.

A Scala function definition looks like this:

def [function-name] ([parameter-name]: [parameter-type]) : [return-type] = [function-body]

so

def taste (food: Consumable) : Opinion = evaluate(food)

defines a function called taste that takes a Consumable as a parameter (food) and returns an Opinion calls evaluate and returns the result, which must be an Opinion
The function body starts after the equals sign (=) and often starts on the same line The last value is returned - no explicit return is required, but since the language is strongly typed there is protection against accidentally returning meaningless values of the wrong type Now you can read Scala.

Java VS Scala

When building class definitions, it’s common to have to build so-called getter and setter methods in order to set the values of that instance. This typically creates a lot of noise in the implementation (as seen in the Java example that follows). Scala combats this by using the case modifier to automatically provision standard functionality into the class definition. Given an instance of the Person case class, calling person.name would return the name value.

JAVA SCALA
public class Person {

private int _age;
private String _name;
public Person(String n, int a){
_age = a;
_name = n;
}
String name(){ return _name; }
int age(){ return _age; }
}

case class Person(

name: String, age: Int)

More Information

Lift

Features

Scala

Introduction

Features

Helpful Links

Lift Tutorials links

1. http://simply.liftweb.net/ 2. http://www.liftweb.net/ 3.

Helpful Links for Lift resources

Resource Description Link
Main Lift site First and foremost is the main Lift homepage. Here you’ll find the latest

news about Lift, regularly updated as time goes by. This page also has links to the source code, the issue tracker, and the wiki.

http://liftweb.net
Assembla Lift moved to the Assembla platform for its wiki and bug-tracking requirements

some time ago, and since then it has accumulated a fair amount of community-created articles.

https://www.assembla.com/wiki/show/liftweb
Mailing list The Google group is the official support channel for Lift. If you have a

question, you can come to the mailing list and find a friendly, responsive community that will be more than happy to answer your questions.

http://groups.google.com/group/liftweb
IRC channel IRC isn’t as popular as it once was, but you’ll still find some of the Lift

team hanging out in IRC from time to time.

https://www.freenode.net

References

<references />