CSC/ECE 517 Fall 2014/ch1a 4 lf

From Expertiza_Wiki
Revision as of 18:40, 14 September 2014 by Kmmehta (talk | contribs) (→‎Examples)
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

Scala

Scala stands for "Scalable Language". 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 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 is an Object-Functional programming and scripting language. 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.

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>Lift (web framework), Wikipedia</ref>. Lift is designed to make powerful techniques easily accessible, while keeping the overall framework simple and flexible.<ref> 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.

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

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 in Java that would look like:

public Opinion taste(Consumable food) {

   return evaluation(food);

} 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.

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)

Helpful Links

References

<references />