Your SlideShare is downloading. ×
Whistle-­‐stop	
  tour	
  of	
  the	
  Li#	
  web	
  framework	
  and	
  
                           demonstra:ng	
  why	
...
Agenda	
  
                     !    Overview	
  of	
  Scala	
  
                     !     Li#’s	
  Ra:onale	
  
        ...
About	
  Me	
  
                     !  Project	
  commi=er	
  on	
  Li#	
  
                     !  Manufacturing	
  and	...
What	
  is	
  Scala?	
  (10,000	
  foot	
  view!)	
  
                     !    Scala	
  is	
  func:onal	
  
             ...
Scala	
  in	
  the	
  wild?	
  
www.devoxx.com	
  
Scala	
  in	
  breif….	
  
                     !  What	
  follows	
  is	
  an	
  overview	
  of	
  core	
  Scala	
  
    ...
Immutability	
  
                     val example = “Devoxx”	

                     !  Immutable	
  values	
  are	
  assig...
Case	
  Classes	
  
                     case class Foo(bar: String, baz: List[Int])	

                     !  Func:onalit...
Singletons	
  
                     object ChatServer extends Actor	

                     !  ChatServer	
  is	
  a	
  sin...
Composi:on	
  with	
  Traits	
  
                     !  Finely-­‐grained	
  aggrega:on	
  of	
  func:onality	
  
        ...
Func:on	
  Passing	
  
                     !  Encapsulates	
  logic	
  concisely	
  
                     !  Wildcard	
  ...
Pa=ern	
  Matching	
  
                     !  Match	
  against	
  case	
  classes	
  
                        !  	
  Para...
XML	
  Literals	
  	
  
                     !  XML	
  is	
  first-­‐class	
  
                     !  Ripe	
  for	
  templ...
Actors	
  
                     !    Being	
  “real-­‐:me”	
  means	
  events	
  
                     !     Lightweight	
...
What	
  is	
  LiH?	
  
                     !    Web	
  framework	
  wri=en	
  in	
  Scala	
  
                     !     ...
Why	
  another	
  framework?	
  
                     !  Developers	
  needn't	
  be	
  plumbers	
  
                     ...
Web	
  Beginnings	
  
                     !  Very	
  person	
  -­‐>	
  machine	
  affair	
  
                     !  Prima...
Web	
  2.0	
  
                     !  Behaviour	
  shiH	
  -­‐>	
  more	
  social	
  
                     !  Different	
 ...
Real	
  Time	
  Web	
  
                     !    Users	
  demand	
  instant	
  gra:fica:on	
  
                     !     ...
View	
  First	
  
                     !  Its	
  not	
  MVC	
  
                     !  Your	
  typical	
  page	
  has	
  ...
Snippets	
  
                     !  A	
  “snippet”	
  in	
  Li#	
  represents	
  a	
  collec:on	
  of	
  
               ...
What	
  a	
  bind…	
  
                     class Example {	
                        def nameForm(xhtml: NodeSeq) = {	
   ...
Security	
  
                     !  Page	
  elements	
  have	
  session	
  specific	
  opaque	
  
                       G...
Site	
  Map	
  
                     !  	
  Declara:ve	
  and	
  granular	
  defini:on	
  of	
  page	
  
                  ...
Persistence	
  
                     !  Li#	
  includes	
  “Mapper”	
  which	
  is	
  a	
  lightweight	
  
               ...
REST	
  and	
  WebServices	
  
                     !  REST	
  via	
  state(full/less)	
  dispatching	
  
                ...
Technology	
  Support	
  
                     !    AMQP	
  
                     !     Tex:le	
  
                     ! ...
Summary	
  
                     !    Scala’s	
  object	
  model	
  is	
  a	
  superset	
  of	
  Java’s	
  
              ...
Devoxx 2009: The Lift Framework
Devoxx 2009: The Lift Framework
Devoxx 2009: The Lift Framework
Upcoming SlideShare
Loading in...5
×

Devoxx 2009: The Lift Framework

4,042

Published on

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

Published in: Technology, Education
1 Comment
20 Likes
Statistics
Notes
  • Good introduction to lift framework :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
4,042
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
1
Likes
20
Embeds 0
No embeds

No notes for slide

Transcript of "Devoxx 2009: The Lift Framework"

  1. 1. Whistle-­‐stop  tour  of  the  Li#  web  framework  and   demonstra:ng  why  the  real-­‐:me  web     should  ma=er  to  you   www.devoxx.com  
  2. 2. 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  
  3. 3. 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  
  4. 4. 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  
  5. 5. Scala  in  the  wild?   www.devoxx.com  
  6. 6. Scala  in  breif….   !  What  follows  is  an  overview  of  core  Scala   language  features   www.devoxx.com  
  7. 7. 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  
  8. 8. 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  
  9. 9. 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  
  10. 10. 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  
  11. 11. 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”) }
  12. 12. 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
  13. 13. 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>
  14. 14. 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”)
  15. 15. 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  
  16. 16. 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  
  17. 17. Web  Beginnings   !  Very  person  -­‐>  machine  affair   !  Primary  uses:     !    Shopping   !    Banking   !    CRUD  opera:ons   !  56k  modems  (yikes!)   www.devoxx.com  
  18. 18. 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  
  19. 19. 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  
  20. 20. 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  
  21. 21. 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  
  22. 22. 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>
  23. 23. 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  
  24. 24. 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  
  25. 25. 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  
  26. 26. 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  
  27. 27. Technology  Support   !  AMQP   !  Tex:le   !  XMPP   !  OpenID   !  JTA   !  PayPal   www.devoxx.com   !  …and  lots  more!  
  28. 28. 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  

×