Agenda	
•  Apparel	
  Cloud	
  
    –  Cloud	
  pla.orm	
  for	
  apparel	
  industry	
  
•  Scala	
  
    –  Scala	
  in	
  model-­‐driven	
  development	
  
    –  Scala	
  in	
  cloud	
  pla.orm	
  architecture	
  
    –  Scala	
  features	
  in	
  real	
  system	
  development	
  




                                                                      2
Vision	
  for	
  EverforthPla.orm	

                          Web	
                          •  UX,	
  IA(InformaEon	
  
                             Architecture)	
                          •  Document	
  DB	

                                Everforth	
  
                               Framework	
    Enterprise	
                               Computer	
  
    •  OOAD,	
  Data	
                         Science	
       Modeling,	
  Business	
                 •  FP,	
  Logic	
       Modeling,	
  SOA	
                      •  Concurrent,	
  
    •  OLTP,	
  OLAP	
                            Parallel,	
  Distributed	
    •  RDBMS	
                                 •  Columnar	
  DB	



                                                                               3
ApplicaEon	
  Building	




                           4
Scala	



          5
My	
  Scala	
  Products	
•  Goldenport	
  
    –  ApplicaEon	
  Framework	
  
    –  hRps://github.com/asami/goldenport	
  
•  SmartDox	
  
    –  Document	
  processing	
  system	
  
    –  hRps://github.com/asami/smartdoxprocessor	
  
•  SimpleModeler	
  
    –  Model	
  compiler	
  
    –  hRps://github.com/asami/simplemodeler	
  
•  g3	
  (experimental)	
  
    –  Server-­‐side	
  applicaEon	
  framework	
  
    –  hRp://code.google.com/p/goldenport3/	
  


                                                       6
Everforth	
  Scala	
  Products	
•  EverforthModeler	
  
   –  Model	
  Compiler	
  for	
  EverforthFramework	
  and	
  Web	
  
      UI	
  Framework	
  
   –  Based	
  on	
  SimpleModeler	
  
•  EverforthFramework	
  
   –  Cloud	
  Service	
  Framework	
  
   –  Derived	
  from	
  g3	
  experience	
  
•  Web	
  UI	
  framework	
  
   –  JavaScript	
  &	
  Scala	
  (Server	
  side)	
  

                                                                         7
Develop	
  Environment	
•    IDE:	
  Emacs	
  +	
  ensime	
  
•    Scala	
  2.9.1	
  
•    sbt	
  0.11.3	
  
•    Scalatest	
  1.6.1	
  
•    Play	
  2.0.4	
  (JSON,	
  Anorm)	
  
      –  play20.auth	
  0.5	
  
•    Scalaz	
  6.0.4	
  
•    Scala	
  IO	
  0.4.0	
  
•    Squeryl	
  0.9.5-­‐2	
  
•    Scalaj-­‐Eme	
  0.6	
  
•    Google	
  guava	
  14.0-­‐rc3	
  (Java)	
  
      –  Concurrent	
  weak/sof	
  reference	
  cache	
  
•  Typesafe	
  Config	
  1.0.0	
  (Java)	
  


                                                            8
Scala	
  is	
  not	
  'beRer	
  Java'	
•    Trait	
  
•    Case	
  class	
  
•    Monad	
  
•    Type	
  class	
  
•    DSL	
  
      –  embedded	
  DSL	
  and	
  external	
  DSL	
  
•  Actor	
  (concurrent)	
  
•  Future	
  Monad	
  (concurrent/parallel)	
  

                                                         9
OOP	
  vs.	
  FP	
•  Our	
  approach:	
  
     –  OOP	
  is	
  dominant	
  paradigm	
  in	
  our	
  development	
  
            •  Large	
  scale	
  sofware	
  development,	
  
            •  CollaboraEon	
  with	
  business	
  modeling	
  in	
  OOAD	
  
     –  OOP	
  over	
  FP	
  
•  Even	
  though	
  	
  FP	
  is	
  very	
  comfortable	
  in	
  coding	
  for	
  	
  
model	
  compiler	
  and	
  server	
  side	
  frameworks.	
  
     –    Tree/graph	
  structure	
  transformaEon	
  
     –    Parser	
  combinator	
  for	
  external	
  DSL	
  
     –    FP	
  over	
  ImperaEve	
  programming	
  
     –    Using	
  FP	
  in	
  OO	
  Paradigm	
  
•  OOP	
  &	
  FP	
  (and	
  syntax	
  sugers)	
  strongly	
  supports	
  Embedded	
  
   DSL	
  	
  

                                                                                          10
Trait	
•  Trait!	
  Trait!	
  Trait!	
  	
  
•  trait	
  vs.	
  abstract	
  class	
  
    –  Now,	
  abstract	
  class	
  is	
  not	
  used	
  so	
  much	
  to	
  me.	
  
•  Cake	
  paRern	
  
    –  (Type-­‐safe)	
  Dependency	
  InjecEon	
  




                                                                                       11
Case	
  class	
•  (almost)	
  algebraic	
  data	
  structure	
  
•  Nevertheless,	
  case	
  class	
  can	
  be	
  used	
  with	
  OOP's	
  
   polymorphism	
  (very	
  very	
  comfortable)	
  
•  Coding	
  strategy:	
  case	
  class	
  should	
  be	
  immutable	
  
   object	
  
•  Useful	
  features	
  with	
  DSL	
  
    –  Default	
  parameter	
  
    –  copy	
  constructor	
  
    –  Implicit	
  parameter	
  
•  PaRern	
  Matching!	
  	
  

                                                                              12
Try	
•  Big	
  enhancement	
  in	
  2.10	
  
•  Monad!	
  (i.e.	
  flatMap	
  method)	
  
•  "Try"	
  everywhere	
  (instead	
  of	
  Either	
  or	
  
   scalaz.ValidaEon)	
  
•  required	
  feature	
  in	
  actor	
  programming	
  to	
  
   convey	
  error	
  state	
  




                                                                 13
Monadic	
  programming	
•  Scala	
  Standard	
  
    –  Functor	
  
    –  Monad	
  
•  Scalaz	
  
    –  Monoid	
  
    –  ApplicaEve	
  Functor	
  
    –  Traverse	
  

•  Handling	
  excepEon	
  state	
  as	
  Try	
  monad	
  instead	
  of	
  throwing	
  
   ExcepEon.	
  
•  Monadic	
  programming	
  features	
  like	
  ApplicaEve	
  Functor,	
  
   Traverse	
  are	
  very	
  useful.	
  


                                                                                          14
Concurrent/Parallel	
•  Features	
  
    –    Actor/Akka	
  
    –    Scalaz	
  Promise	
  
    –    Scala	
  2.10	
  Future	
  and	
  Promise	
  
    –    Scala	
  2.10	
  Try	
  
    –    Parallel	
  CollecEon	
  
•  Techniques	
  
    –  Algebraic	
  datatype	
  
           •  case	
  class	
  
    –  Persistent	
  data	
  structure	
  
           •  List,	
  Vector	
  
           •  Scalaz	
  Tree	
  
    –  ConEnuous	
  passing	
  style	
  


                                                         15
Conclusion	
•  Scala	
  is	
  a	
  suitable	
  language	
  for	
  
    –  Model-­‐Driven	
  development	
  
    –  Building	
  cloud	
  pla.orm	
  frameworks	




                                                         16
End	
        17

Scala in Model-Driven development for Apparel Cloud Platform

  • 2.
    Agenda •  Apparel  Cloud   –  Cloud  pla.orm  for  apparel  industry   •  Scala   –  Scala  in  model-­‐driven  development   –  Scala  in  cloud  pla.orm  architecture   –  Scala  features  in  real  system  development   2
  • 3.
    Vision  for  EverforthPla.orm Web •  UX,  IA(InformaEon   Architecture) •  Document  DB Everforth   Framework Enterprise Computer   •  OOAD,  Data   Science Modeling,  Business   •  FP,  Logic Modeling,  SOA •  Concurrent,   •  OLTP,  OLAP Parallel,  Distributed •  RDBMS •  Columnar  DB 3
  • 4.
  • 5.
  • 6.
    My  Scala  Products • Goldenport   –  ApplicaEon  Framework   –  hRps://github.com/asami/goldenport   •  SmartDox   –  Document  processing  system   –  hRps://github.com/asami/smartdoxprocessor   •  SimpleModeler   –  Model  compiler   –  hRps://github.com/asami/simplemodeler   •  g3  (experimental)   –  Server-­‐side  applicaEon  framework   –  hRp://code.google.com/p/goldenport3/   6
  • 7.
    Everforth  Scala  Products • EverforthModeler   –  Model  Compiler  for  EverforthFramework  and  Web   UI  Framework   –  Based  on  SimpleModeler   •  EverforthFramework   –  Cloud  Service  Framework   –  Derived  from  g3  experience   •  Web  UI  framework   –  JavaScript  &  Scala  (Server  side)   7
  • 8.
    Develop  Environment •  IDE:  Emacs  +  ensime   •  Scala  2.9.1   •  sbt  0.11.3   •  Scalatest  1.6.1   •  Play  2.0.4  (JSON,  Anorm)   –  play20.auth  0.5   •  Scalaz  6.0.4   •  Scala  IO  0.4.0   •  Squeryl  0.9.5-­‐2   •  Scalaj-­‐Eme  0.6   •  Google  guava  14.0-­‐rc3  (Java)   –  Concurrent  weak/sof  reference  cache   •  Typesafe  Config  1.0.0  (Java)   8
  • 9.
    Scala  is  not  'beRer  Java' •  Trait   •  Case  class   •  Monad   •  Type  class   •  DSL   –  embedded  DSL  and  external  DSL   •  Actor  (concurrent)   •  Future  Monad  (concurrent/parallel)   9
  • 10.
    OOP  vs.  FP • Our  approach:   –  OOP  is  dominant  paradigm  in  our  development   •  Large  scale  sofware  development,   •  CollaboraEon  with  business  modeling  in  OOAD   –  OOP  over  FP   •  Even  though    FP  is  very  comfortable  in  coding  for     model  compiler  and  server  side  frameworks.   –  Tree/graph  structure  transformaEon   –  Parser  combinator  for  external  DSL   –  FP  over  ImperaEve  programming   –  Using  FP  in  OO  Paradigm   •  OOP  &  FP  (and  syntax  sugers)  strongly  supports  Embedded   DSL     10
  • 11.
    Trait •  Trait!  Trait!  Trait!     •  trait  vs.  abstract  class   –  Now,  abstract  class  is  not  used  so  much  to  me.   •  Cake  paRern   –  (Type-­‐safe)  Dependency  InjecEon   11
  • 12.
    Case  class •  (almost)  algebraic  data  structure   •  Nevertheless,  case  class  can  be  used  with  OOP's   polymorphism  (very  very  comfortable)   •  Coding  strategy:  case  class  should  be  immutable   object   •  Useful  features  with  DSL   –  Default  parameter   –  copy  constructor   –  Implicit  parameter   •  PaRern  Matching!     12
  • 13.
    Try •  Big  enhancement  in  2.10   •  Monad!  (i.e.  flatMap  method)   •  "Try"  everywhere  (instead  of  Either  or   scalaz.ValidaEon)   •  required  feature  in  actor  programming  to   convey  error  state   13
  • 14.
    Monadic  programming •  Scala  Standard   –  Functor   –  Monad   •  Scalaz   –  Monoid   –  ApplicaEve  Functor   –  Traverse   •  Handling  excepEon  state  as  Try  monad  instead  of  throwing   ExcepEon.   •  Monadic  programming  features  like  ApplicaEve  Functor,   Traverse  are  very  useful.   14
  • 15.
    Concurrent/Parallel •  Features   –  Actor/Akka   –  Scalaz  Promise   –  Scala  2.10  Future  and  Promise   –  Scala  2.10  Try   –  Parallel  CollecEon   •  Techniques   –  Algebraic  datatype   •  case  class   –  Persistent  data  structure   •  List,  Vector   •  Scalaz  Tree   –  ConEnuous  passing  style   15
  • 16.
    Conclusion •  Scala  is  a  suitable  language  for   –  Model-­‐Driven  development   –  Building  cloud  pla.orm  frameworks 16
  • 17.
    End 17