• Save
Devoxx 2009: The Lift Framework
Upcoming SlideShare
Loading in...5
×
 

Devoxx 2009: The Lift Framework

on

  • 5,713 views

Timothy Perrett's talk on the Scala Lift web framework from Devoxx 2009 in Antwerp, Belgium.

Timothy Perrett's talk on the Scala Lift web framework from Devoxx 2009 in Antwerp, Belgium.

Statistics

Views

Total Views
5,713
Views on SlideShare
5,683
Embed Views
30

Actions

Likes
20
Downloads
0
Comments
1

3 Embeds 30

http://www.slideshare.net 19
http://lanyrd.com 8
http://www.lmodules.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Good introduction to lift framework :)
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Devoxx 2009: The Lift Framework Devoxx 2009: The Lift Framework Presentation Transcript

  • Whistle-­‐stop  tour  of  the  Li#  web  framework  and   demonstra:ng  why  the  real-­‐:me  web     should  ma=er  to  you   www.devoxx.com  
  • Agenda   !  Overview  of  Scala   !  Li#’s  Ra:onale   !  The  real-­‐:me  web   !  Li#’s  awesome  feature  set   !  Why  Scala  makes  Li#  possible   www.devoxx.com  
  • About  Me   !  Project  commi=er  on  Li#   !  Manufacturing  and  marke:ng  automa:on  is   my  day-­‐job  (industrial  systems)   !  Whole  raH  of  experience  with  both  dynamic   and  sta:c  languages   !  Desktop  and  Web  applica:on  development   www.devoxx.com   !  Coding  Scala  and  LiH  since  end  of  2007  
  • What  is  Scala?  (10,000  foot  view!)   !  Scala  is  func:onal   !  Scala  is  object  orientated   !  Scala  is  mul:-­‐paradigm!  OO  and  FP  hybrid...   !  Designed  by  Mar:n  Odersky  (Java  generics)   !  Runs  as  fast  as  na:ve  Java  code   !  Fully  interoperable  with  exis:ng  Java  libraries   www.devoxx.com   !  More  type-­‐safe  than  Java  
  • Scala  in  the  wild?   www.devoxx.com  
  • Scala  in  breif….   !  What  follows  is  an  overview  of  core  Scala   language  features   www.devoxx.com  
  • Immutability   val example = “Devoxx” !  Immutable  values  are  assigned  with  the     “val”  keyword   !  Immutability  is  your  long-­‐lost  friend:   !    No  need  to  synchronise   !    Never  need  to  copy  vars  “just  in  case”   !    Great  for  hash  keys   www.devoxx.com   !  Be=er  for  garbage  collector  
  • Case  Classes   case class Foo(bar: String, baz: List[Int]) !  Func:onality  you  get  for  free:   !    “new”  keyword  is  redundant   !    bar  and  baz  proper:es  (immutable  by  default)   !    toString,  hashCode,  and  equals  et  al   !    Pa=ern  matching  with  parameter  extrac:on   www.devoxx.com  
  • Singletons   object ChatServer extends Actor !  ChatServer  is  a  singleton   !  One  instance  per  classloader   !  Can  be  passed  as  parameter…  it’s  an  instance   www.devoxx.com  
  • Composi:on  with  Traits   !  Finely-­‐grained  aggrega:on  of  func:onality   !  Mul:ple-­‐inheritance  without  diamond  problem[1]   !  Extensively  used  in  Li#   object sally extends Person(“Sally”) with Female with Runner def womansRun(who: Female with Runner) www.devoxx.com   //=> womansRun(sally) [1]  h=p://en.wikipedia.org/wiki/Diamond_problem  
  • Func:on  Passing   !  Encapsulates  logic  concisely   !  Wildcard  shorthand  keeps  things  simple   !  Func:ons  are  instances  that  can  be  passed   // make x a function that lower cases input val x: (String) => String = (str) => str.toLowerCase www.devoxx.com   // alter the request encoding LiftRules.early { _.setCharacterEncoding(“UTF-8”) }
  • Pa=ern  Matching   !  Match  against  case  classes   !    Parameter  extrac:on   !    Great  for  message  /  event  handling   !    Test  against  parameters:  case Person(name, 35) => !  Declara:ve  expression  of  logic   case Messages(m) => msgs = m www.devoxx.com   case s: String if s.length > 0 => msgs ::= s
  • XML  Literals     !  XML  is  first-­‐class   !  Ripe  for  templa:ng  abuse!   !  Very  handy  for  development  but  Li#  provides   strong  abstrac:ons  for  templates   val links = (“Link A”, http://…) :: (“Link B”, “http://…”) :: (“Link C”, https://…) :: Nil www.devoxx.com   val myLinkList = <ul>{ links.flatMap({case (name,url) => <li><a href={url}>{name}</a></li>}) } </ul>
  • Actors   !  Being  “real-­‐:me”  means  events   !  Lightweight  concurrency  model     !  With  very  nice  syntax   !  Implemented  as  a  library!   object DevoxxActor extends Actor { …… } case class Talk(name: String) www.devoxx.com   // asyncronusly send the talk message to the actor DevoxxActor ! Talk(“Lift web framework”)
  • What  is  LiH?   !  Web  framework  wri=en  in  Scala   !  3  years  old,  founded  by  David  Pollak   !  Leverages  the  best  of  Scala  language  features   !  Takes  the  best  ideas  from  other  frameworks   !  Makes  real-­‐:me  web  applica:ons  accessible   !  Massively  scalable   www.devoxx.com  
  • Why  another  framework?   !  Developers  needn't  be  plumbers   !  Unifies  the  best  of  other  framework  concepts   !    Granular  sessions  and  security  a  la  Seaside   !    Flash-­‐to-­‐bang  produc:vity  a  la  Rails   !    Designer  friendly  templates  a  la  Wicket   !  Advanced  features  like  comet  work  OOTB   www.devoxx.com   !  Tough  to  be  truly  real-­‐:me  with  exis:ng  tech  
  • Web  Beginnings   !  Very  person  -­‐>  machine  affair   !  Primary  uses:     !    Shopping   !    Banking   !    CRUD  opera:ons   !  56k  modems  (yikes!)   www.devoxx.com  
  • Web  2.0   !  Behaviour  shiH  -­‐>  more  social   !  Different  usage  models:   !    Person  -­‐>  Machine  -­‐>  Machine  (mashups)   !    Person  -­‐>  Person  (Facebook,  Twi=er)   !    Machine  -­‐>  Machine  -­‐>  Person  (micro-­‐formats)   !  Internet  becomes  society  cornerstone     www.devoxx.com  
  • Real  Time  Web   !  Users  demand  instant  gra:fica:on   !  Peer-­‐to-­‐peer  news  /  informa:on  streams   !  Business  informa:on  in  constant  flux   !  Online  interac:ve  games   !  Real  Time  Web  is  the  next  evolu2onary  step...   www.devoxx.com  
  • View  First   !  Its  not  MVC   !  Your  typical  page  has  more  than  a  single  piece   of  dynamic  content   !  Code  in  the  view  usually  means  some  “seep”   of  business  logic:  thus,  NO  code  in  the  view   !  Only  well-­‐formed  XHTML;  no  string   replacement  –  e.g.  {{myvar}}   www.devoxx.com   !  Designer  friendly  dynamic  content  markup  
  • Snippets   !  A  “snippet”  in  Li#  represents  a  collec:on  of   applica:on  logic   !  One  snippet  can  be  called  on  n  number  of   pages,  n  number  of  :mes   !  A  snippet  is  a  normal  Scala  class  or  object:   there  is  no  black  magic   www.devoxx.com   !  Lookup  via  reflec:on  or  manual  wiring  
  • What  a  bind…   class Example { def nameForm(xhtml: NodeSeq) = { var name = “” def doSubmit { println(“Submitted…”); } bind("f", xhtml, "name" -> SHtml.text(name, name = _), "submit" -> SHtml.submit(doSubmit _) ) } } <lift:example.name_form> <p><f:name /></p> www.devoxx.com   <p><f:submit /></p> </lift:example.name_form>
  • Security   !  Page  elements  have  session  specific  opaque   GUIDs  to  reference  server  components   (impossible  to  do  CSRF[1])   <input name=“F677071620957IFD” type=“text” /> !  Callback  func:ons  also  use  similar  GUIDs  so   that  sensi:ve  IDs  etc  are  not  exposed     www.devoxx.com   /somepath?F677071620979LIK=_ [1]  h=p://en.wikipedia.org/wiki/Cross-­‐site_request_forgery  
  • Site  Map   !    Declara:ve  and  granular  defini:on  of  page   and  UI  access  rules   !  Enforced  long  before  the  page  content  is   processed  or  rendered  –  its  very  fast.   !  Can  generate  site  menus  even  with  complex   rules  on  what  different  users  see   www.devoxx.com   !  Unified  access  control  model  
  • Persistence   !  Li#  includes  “Mapper”  which  is  a  lightweight   ORM  of  similar  design  to  Ac:veRecord  in  Rails   !  Use  any  backend  persistence  system  you   want  (Hibernate,  JPA  etc)   !  Write  custom  back-­‐ends  using  Li#  Record  –   provides  OOTB  valida:on  and  CRUD   seman:cs;  you  provide  the  implementa:on   www.devoxx.com  
  • REST  and  WebServices   !  REST  via  state(full/less)  dispatching   !  Declara:ve  rules  for  URI  -­‐>  handler  dispatch   !  LiH  has  awesome  support  for  JSON:   !    Slick  DSL  for  construc:on  /  parsing   !    ~300  :mes  faster  than  Scala  JSON  parser   !    Faster  deseriliza:on  than  Java   www.devoxx.com   !  Na:ve,  first-­‐class  XML  support  in  Scala  
  • Technology  Support   !  AMQP   !  Tex:le   !  XMPP   !  OpenID   !  JTA   !  PayPal   www.devoxx.com   !  …and  lots  more!  
  • Summary   !  Scala’s  object  model  is  a  superset  of  Java’s   !  Scala  traits:  powerful  and  granular  composi:on   !  Scala  is  syntac:cally  simpler  than  Java  or  Ruby   !  Scala’s  design  led  to  Li#’s  design   !  Li#  makes  the  real-­‐:me  web  simple   !  Li#  is  the  culmina:on  of  many  great  ideas   www.devoxx.com