SlideShare a Scribd company logo
PHP.next:	
  Traits	
  

Horizontal	
  Reuse	
  of	
  Behavior	
  



                   Stefan	
  Marr	
  
            AFUP,	
  La	
  Can@ne,	
  Paris	
  
             15th	
  December	
  2010	
  
Ques@ons	
  at	
  any	
  @me	
  
Traits	
  for	
  PHP	
  Started	
  December	
  2007	
  




15/12/10	
                                         3	
  
Today:	
  Virtual	
  Machines	
  for	
  the	
  Manycore	
  Era	
  




                              hOp://soR.vub.ac.be/~smarr/research/	
  
                              hOp://github.com/smarr/RoarVM	
  




15/12/10	
                                                      4	
  
Who	
  are	
  you?	
  
•  PHP	
  Programmer:	
  Job	
  or	
  Hobby?	
  

•  C	
  Programmer?	
  (PHP	
  core/extensions?)	
  

•  Contribu@on	
  to	
  Open	
  Source	
  projects?	
  




15/12/10	
                                                5	
  
Off-­‐Topic…	
  
               Anyone	
  using:	
  
               •  COCOMO,	
  COCOMO	
  II	
  
               •  Func@on	
  points	
  
               •  User	
  Story	
  Points	
  




15/12/10	
                                      6	
  
Ques@ons	
  at	
  any	
  @me	
  
Agenda	
  
•    Why	
  Traits?	
  
•    The	
  Language	
  Design	
  
•    Traits	
  Applied	
  
•    Implementa@on	
  inside	
  the	
  Zend	
  Engine	
  




15/12/10	
                                                  8	
  
Reuse	
  in	
  Programming	
  Languages	
  

    WHY	
  TRAITS?	
  


15/12/10	
                         Stefan	
  Marr	
  –	
  PHP.next:	
  Traits	
     9	
  
Single	
  Inheritance	
  
                                                                             Vertebrates
•  Simple	
  but	
  not	
  	
  
   expressive	
  enough	
  

•  Leads	
  to	
                                           Dinosaurs                       Mammal

    •  Code	
  duplica@on	
  
    •  Inappropriate	
  	
  
       hierarchies	
                                     Archaeoptrix                          Bat


                                                        fly()                          fly()



15/12/10	
             Approaches	
  for	
  ComposiIon	
  and	
  their	
  Limits	
                   10	
  
Mul@ple	
  Inheritance	
  
                  Animal                                         •  Very	
  expressive	
  
                +move()

                                                                 •  But	
  
         Bird
                            Swimmer                                  •  Diamond	
  problem	
  
  +move()
                           +move()
                                                                     •  Fragile	
  hierarchies	
  
  +getLegs()



                  Penguin                                    class Penguin {
                                                               function move() {
                +move()                                          Swimmer::move();
                                                               }
                                                             }



15/12/10	
                    Approaches	
  for	
  ComposiIon	
  and	
  their	
  Limits	
     11	
  
Mixins	
  
                                                Animal




                                           WingAnimal
                                                                          <<mixin>> (1)   Bat
                  <<mixin>> (1)
                                       bones = light
                                       extremity = wings
        Penguin                        move()

                  <<mixin>> (2)            SwimAnimal
                                       extremity = fins
                                       move()




15/12/10	
              Approaches	
  for	
  ComposiIon	
  and	
  their	
  Limits	
             12	
  
Mixins	
  
                                                Animal




                                           WingAnimal
                                                                          <<mixin>> (1)    Bat
                  <<mixin>> (1)
                                       bones = light
                                       extremity = wings
        Penguin                        move()

                  <<mixin>> (2)            SwimAnimal
                                       extremity = fins                      •  Lack	
  of	
  composi@on	
  
                                       move()                                   control	
  
                                                                             •  Fragile	
  hierarchies	
  

15/12/10	
              Approaches	
  for	
  ComposiIon	
  and	
  their	
  Limits	
              13	
  
Limita@ons	
  
•    Code	
  duplica@on	
  
•    Inappropriate	
  hierarchies	
  
•    Diamond	
  problem	
  
•    Fragile	
  hierarchies	
  
•    Lack	
  of	
  composi@on	
  control	
  




15/12/10	
           Approaches	
  for	
  ComposiIon	
  and	
  their	
  Limits	
     14	
  
Traits	
  for	
  PHP	
  

    THE	
  LANGUAGE	
  DESIGN	
  


15/12/10	
                     Stefan	
  Marr	
  –	
  PHP.next:	
  Traits	
     15	
  
                                                      	
  
Traits	
  
•    Set	
  of	
  methods	
  
•    Possibly	
  composed	
  of	
  other	
  Traits	
  
•    Composi@on	
  is	
  unordered	
                                TFoo

•    Composi@on	
  opera@ons	
              TTrait
                                                               foo()

                                                                       TBar
       –  Sum	
                                  m1()
                                                 m2()          bar()
                          MyClass
       –  Exclusion	
                              TConflict
       –  Aliasing	
                             m2()

•  Can	
  be	
  flaOened	
  away	
  
15/12/10	
                          Traits	
                       16	
  
Traits	
  in	
  Ac@on	
  




15/12/10	
               Traits	
          17	
  
Method	
  in	
  Class	
  Overrides	
  Trait	
  
                              Base	
  
                         foo()	
  
                                                                   class	
  Base	
  {	
  
Code	
  




                                                                   	
  	
  function	
  foo()	
  {	
  echo	
  'B';}}	
  
                                 A	
                T	
            	
  
                         foo()	
            foo()	
                trait	
  T	
  {	
  
                                                                   	
  	
  function	
  foo()	
  {	
  echo	
  'T';}}	
  
                              Base	
                               	
  
Compiled	
  Result	
  




                         foo()	
                                   class	
  A	
  extends	
  Base	
  {	
  
                                                                   	
  	
  use	
  T;	
  
                                                                   	
  	
  function	
  foo()	
  {	
  echo	
  'A';}}	
  
                                 A	
  
                         foo()	
         echo	
  'A';	
  

                  15/12/10	
                                Traits	
                                    18	
  
Conflicts	
  are	
  Explicit	
  
                              Base	
  
                                                                                  class	
  Base	
  {	
  
                         foo()	
                                                  	
  	
  function	
  foo()	
  {	
  echo	
  'B';}}	
  
                                                         T1	
  
                                                                                  	
  
Code	
  




                                                  foo()	
                         trait	
  T1	
  {	
  
                                 A	
                                              	
  	
  function	
  foo()	
  {echo	
  'T1';}}	
  
                                                         T2	
                     	
  
                                                  foo()	
                         trait	
  T2	
  {	
  
                              Base	
                                              	
  	
  function	
  foo()	
  {echo	
  'T2';}}	
  
Compiled	
  Result	
  




                         foo()	
                                                  	
  
                                                                                  class	
  A	
  extends	
  Base	
  {	
  
                                                                                  	
  	
  use	
  T1,	
  T2;	
  
                                 A	
     >>	
  Fatal	
  error:	
  	
              }	
  
                                         	
  	
  	
  collision	
  on	
  foo	
  

                  15/12/10	
                                              Traits	
                                     19	
  
                                                                            	
  
Solving	
  Conflicts	
  
                              Base	
  
                                                                           class	
  Base	
  {	
  
                         foo()	
                                           	
  	
  function	
  foo()	
  {	
  echo	
  'B';}}	
  
                                                           T1	
  
                                                                           trait	
  T1	
  {	
  
Code	
  




                                                    foo()	
                	
  	
  function	
  foo()	
  {echo	
  'T1';}}	
  
                                 A	
                                       trait	
  T2	
  {	
  
                                                           T2	
            	
  	
  function	
  foo()	
  {echo	
  'T2';}}	
  
                                         !foo	
  
                                                    foo()	
                	
  
                              Base	
                                       class	
  A	
  extends	
  Base	
  {	
  
Compiled	
  Result	
  




                         foo()	
                                           	
  	
  use	
  T1,	
  T2	
  {	
  
                                                                           	
  	
  	
  	
  T1::foo	
  insteadof	
  T2;	
  
                                                                           	
  	
  }	
  
                                 A	
                                       }	
  
                         foo()	
         >>	
  echo	
  'T1';	
  


                  15/12/10	
                                        Traits	
                                    20	
  
                                                                      	
  
Aliasing	
  
                              Base	
  
                                                                               class	
  Base	
  {	
  
                         foo()	
                                               	
  	
  function	
  foo()	
  {	
  echo	
  'B';}}	
  
                                                               T1	
  
                                                                               trait	
  T1	
  {	
  
Code	
  




                                                        foo()	
                	
  	
  function	
  foo()	
  {echo	
  'T1';}}	
  
                                 A	
                                           trait	
  T2	
  {	
  
                                         !foo	
                T2	
            	
  	
  function	
  foo()	
  {echo	
  'T2';}}	
  
                                         +foo2	
  
                                                        foo()	
                	
  
                              Base	
                                           class	
  A	
  extends	
  Base	
  {	
  
Compiled	
  Result	
  




                         foo()	
                                               	
  	
  use	
  T1,	
  T2	
  {	
  
                                                                               	
  	
  	
  	
  T1::foo	
  insteadof	
  T2;	
  
                                                                               	
  	
  	
  	
  T2::foo	
  as	
  fooT2;	
  
                              A	
  
                         foo()	
         >>	
  echo	
  'T1';	
  
                                                                               	
  	
  }	
  
                         foo2()	
        >>	
  echo	
  'T2';	
                 }	
  

                  15/12/10	
                                            Traits	
                                    21	
  
                                                                          	
  
Aliasing	
  IS	
  NOT	
  Renaming	
  
trait	
  T1	
  {	
                            class	
  A	
  {	
  
	
  	
  function	
  bar()	
  {	
  
	
  	
  	
  	
  echo	
  'T1::bar';	
  
                                              	
  	
  use	
  T1,	
  T2	
  {	
  
	
  	
  }	
                                   	
  	
  	
  	
  T2::bar	
  insteadof	
  T1;	
  
	
  	
  function	
  foo()	
  {	
              	
  	
  	
  	
  T1::bar	
  as	
  bar2;	
  
	
  	
  	
  	
  $this-­‐>bar();	
  
                                              	
  	
  }	
  
	
  	
  }	
  
}	
                                           }	
  
trait	
  T2	
  {	
                            	
  
	
  	
  function	
  bar()	
  {	
  
                                              $a	
  =	
  new	
  A;	
  
	
  	
  	
  	
  echo	
  'T2::bar’;	
  
	
  	
  }	
                                   $a-­‐>foo();	
  //	
  echo	
  ??	
  
}	
  

15/12/10	
                               Traits	
                               22	
  
                                           	
  
Late	
  Binding	
  for	
  Composability	
  
trait	
  MovingAnimal	
  {	
                            class	
  Penguin	
  {	
  
	
  	
  function	
  move()	
  {	
                       	
  	
  use	
  WingAnimal,	
  SwimAnimal	
  {	
  
	
  	
  	
  	
  $this-­‐>extremities()-­‐>use();	
      	
  	
  	
  	
  WingAnimal::extremities	
  
	
  	
  }}	
                                            	
  	
  	
  	
  	
  	
  insteadof	
  SwimAnimal;	
  
trait	
  WingAnimal	
  {	
                              	
  	
  }	
  
	
  	
  use	
  MovingAnimal;	
                          }	
  
	
  	
  function	
  extremities()	
  {	
                	
  
	
  	
  	
  	
  return	
  $this-­‐>wings;	
             $skipper	
  =	
  new	
  Penguin;	
  
	
  	
  }}	
                                            $skipper-­‐>move();	
  //	
  will	
  use	
  
trait	
  SwimAnimal	
  {	
                              	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  his	
  wings	
  
	
  	
  use	
  MovingAnimal;	
  
	
  	
  function	
  extremities()	
  {	
  
	
  	
  	
  	
  return	
  $this-­‐>fins;	
  
	
  	
  }}	
  

 15/12/10	
                                      Traits	
                                                                               23	
  
                                                   	
  
Traits	
  and	
  State	
  
trait	
  Counter	
  {	
  
	
  	
  abstract	
  function	
  &getValueVar();	
  
	
  	
  function	
  inc($inc	
  =	
  1)	
  {	
  
	
  	
  	
  	
  $var	
  =	
  &$this-­‐>getValueVar();	
  
	
  	
  	
  	
  $var	
  =	
  $var	
  +	
  $inc;	
  
	
  	
  }}	
  
class	
  PageWithCounter	
  {	
  
	
  	
  use	
  Counter;	
  
	
  	
  public	
  $counter	
  =	
  1;	
  
	
  	
  function	
  &getValueVar()	
  {	
  return	
  $this-­‐>counter;	
  }	
  
}	
  
$page	
  =	
  new	
  PageWithCounter;	
  $page-­‐>inc();	
  
var_dump($page-­‐>counter);	
  


 15/12/10	
                                   Traits	
                            24	
  
                                                	
  
Case	
  Studies	
  Illustra@ng	
  Benefits	
  of	
  Traits	
  

    TRAITS	
  APPLIED	
  


15/12/10	
                              Stefan	
  Marr	
  –	
  PHP.next:	
  Traits	
     25	
  
                                                               	
  
Use	
  Case	
  for	
  Traits	
  
•  ezcReflec@on	
  enhances	
  PHP	
  Reflec@on	
  API	
  
       –  Adds	
  XDoclet	
  like	
  annota@ons	
  for	
  PHP	
  
       –  Enhances	
  type	
  hin@ng	
  using	
  PHPDoc	
  type	
  
          annota@ons	
  
•  Illustrates	
  solu@on	
  for	
  code	
  duplica@on	
  
   problems	
                                  «interface»
                                                Reflector




           ReflectionProperty   ReflectionClass             ReflectionFunction   ReflectionParameter


                                ReflectionObject             ReflectionMethod



15/12/10	
                                   Traits	
  Applied	
                                26	
  
Refactoring	
  ezcReflec@on	
  with	
  Traits	
  




15/12/10	
              Traits	
  Applied	
     27	
  
Refactoring	
  ezcReflec@on	
  with	
  Traits	
  




15/12/10	
              Traits	
  Applied	
     28	
  
Implementa@on	
  details:	
  
           Not	
  to	
  be	
  confused	
  with	
  language	
  seman@cs!	
  




    The	
  Traits	
  Implementa@on	
  

    INSIDE	
  THE	
  ZEND	
  ENGINE	
  


15/12/10	
                         Stefan	
  Marr	
  –	
  PHP.next:	
  Traits	
     29	
  
                                                          	
  
Zend	
  Engine	
  Overview	
  
                                    PHP	
  +	
  Zend	
  Engine	
  

                 YACC	
                    Opcodes	
  
 Script	
        Parser	
                 Structures	
  

                                                                             Opcode	
  
                                                                           Interpreter	
         Result	
  

 Input	
                      Input	
  




15/12/10	
                       Traits	
  inside	
  the	
  Zend	
  Engine	
                 30	
  
YACC	
  
                                  Parser	
                                          Parser	
  



•  Added	
  keywords	
  
       –  trait	
  
       –  insteadof	
  


•  Grammar	
  rules	
  based	
  on	
  class	
  	
  




15/12/10	
                 Traits	
  inside	
  the	
  Zend	
  Engine	
     31	
  
                                                	
  
PHP	
  +	
  Zend	
  
                                                                                   Engine	
  
                               Zend	
  Engine	
  
•  Trait	
  internally	
  a	
  class	
  with	
  ZEND_ACC_TRAIT	
  
       –  New	
  data	
  structures	
  
               •  zend_trait_method_reference	
  
               •  zend_trait_precedence	
  
               •  zend_trait_alias	
  
       –  Class	
  members	
  added	
  to	
  zend_class_entry	
  
               •    zend_class_entry	
  **traits;	
  
               •    zend_uint	
  num_traits;	
  
               •    zend_trait_alias	
  **trait_aliases;	
  
               •    zend_trait_precedence	
  **trait_precedences;	
  
•  Support	
  in	
  Reflec@on	
  API	
  
15/12/10	
                       Traits	
  inside	
  the	
  Zend	
  Engine	
       32	
  
                                                      	
  
Opcode	
  
                                         Interpreter	
                                       Interpreter	
  



•  Added	
  Opcodes	
  
       –  ZEND_ADD_TRAIT	
  
               •  similar	
  to	
  ZEND_ADD_INTERFACE	
  
               •  Only	
  adds	
  info,	
  no	
  composi@on	
  done	
  
       –  ZEND_BIND_TRAITS	
  
               •  emiOed	
  in	
  zend_do_end_class_declara@on	
  
               •  will	
  ini@ate	
  trait	
  composi@on	
  at	
  run@me	
  
                    –  Only	
  once,	
  part	
  of	
  class	
  defini@on	
  process	
  	
  
                    –  (no	
  run@me	
  overhead)	
  


15/12/10	
                                 Traits	
  inside	
  the	
  Zend	
  Engine	
        33	
  
                                                                	
  
PHP	
  +	
  Zend	
  
                                                                                  Engine	
  
                   Composi@on	
  Process	
  
•  Implemented	
  in	
  zend_do_bind_traits	
  
1.  Init	
  traits	
  data	
  structures	
  (resolve	
  classes)	
  
2.  For	
  all	
  used	
  traits	
  
      –  Compile	
  method	
  table	
  of	
  all	
  used	
  methods	
  
      –  Respect	
  exclusion	
  and	
  aliases	
  
3.  Merge	
  resul@ng	
  tables	
  
4.  Add	
  methods	
  to	
  class	
  
      –  Handle	
  abstract	
  methods,	
  inheritance	
  
      –  duplicate	
  func@on	
  (like	
  copy/paste,	
  enables	
  static)	
  

15/12/10	
                      Traits	
  inside	
  the	
  Zend	
  Engine	
       34	
  
                                                     	
  
ROUNDUP	
  AND	
  CONCLUSION	
  


15/12/10	
       Stefan	
  Marr	
  –	
  PHP.next:	
  Traits	
     35	
  
                                        	
  
References	
  for	
  Traits	
  in	
  PHP	
  
RFC:	
  Horizontal	
  Reuse	
  in	
  PHP	
  
       Version	
  2.0.1,	
  last	
  update	
  2010-­‐11-­‐18	
  
       hOp://wiki.php.net/rfc/horizontalreuse	
  
	
  
Interes@ng	
  Blog	
  Posts	
  
       –  Simas	
  Toleikis:	
  Overview,	
  similar	
  to	
  RFC	
  
               •  hOp://simas.posterous.com/new-­‐to-­‐php-­‐54-­‐traits	
  
       –  Sebas@an	
  Deutsch:	
  Ac@veRecord	
  with	
  Traits	
  
               •  hOp://9elements.com/io/?p=28	
  

15/12/10	
                         Roundup	
  and	
  Conclusion	
         36	
  
                                                	
  
Conclusion	
  
•  Traits	
  are	
  mechanism	
  for	
  reuse	
  of	
  behavior	
  
•  Avoid	
  limita@ons	
  of	
  other	
  approaches	
  
       –  Avoid	
  code	
  duplica@on	
  
       –  Enhance	
  class	
  composi@on	
  capabili@es	
  
•  “Compiler	
  assisted	
  copy’n’paste”	
  
       –  FlaOened	
  into	
  class	
  
       –  No	
  run@me	
  overhead	
  


15/12/10	
                     Roundup	
  and	
  Conclusion	
     37	
  
                                            	
  
Basic	
  Literature	
  on	
  Traits	
  
Main	
  ArIcle	
  about	
  Traits	
  	
  
[3] 	
  S.	
  DUCASSE,	
  O.	
  NIERSTRASZ,	
  N.	
  SCHÄRLI,	
  R.	
  WUYTS,	
  AND	
  A.	
  P.	
  
        BLACK,	
  Traits:	
  A	
  Mechanism	
  for	
  Fine-­‐Grained	
  Reuse,	
  ACM	
  
        Trans.	
  Program.	
  Lang.	
  Syst.,	
  28	
  (2006),	
  pp.	
  331–388.	
  
	
  
Traits	
  Extensions	
  
[1]       	
  A.	
  BERGEL,	
  S.	
  DUCASSE,	
  O.	
  NIERSTRASZ,	
  AND	
  R.	
  WUYTS,	
  Stateful	
  Traits	
  and	
  their	
  
              Formaliza;on,	
  Journal	
  of	
  Computer	
  Languages,	
  Systems	
  and	
  Structures,	
  34	
  
              (2007),	
  pp.	
  83–108.	
  
[4]       	
  S.	
  DUCASSE,	
  R.	
  WUYTS,	
  A.	
  BERGEL,	
  AND	
  O.	
  NIERSTRASZ,	
  User-­‐Changeable	
  Visibility:	
  
              Resolving	
  Unan;cipated	
  Name	
  Clashes	
  in	
  Traits,	
  SIGPLAN	
  Not.,	
  42	
  (2007),	
  
              pp.	
  171–190.	
  

	
  
	
  
15/12/10	
                                        Roundup	
  and	
  Conclusion	
  
                                                               	
  
                                                                                                                         38	
  
Traits	
  Literature	
  
[1]A.	
  BERGEL,	
  S.	
  DUCASSE,	
  O.	
  NIERSTRASZ,	
  AND	
  R.	
  WUYTS,	
  Stateful	
  Traits	
  and	
  their	
  
  	
  
     Formaliza;on,	
  Journal	
  of	
  Computer	
  Languages,	
  Systems	
  and	
  Structures,	
  34	
  (2007),	
  
     pp.	
  83–108.	
  
[2]S.	
  DENIER,	
  Traits	
  Programming	
  with	
  AspectJ,	
  RSTI	
  -­‐	
  L'objet,	
  11	
  (2005),	
  pp.	
  69–86.	
  
  	
  
[3]S.	
  DUCASSE,	
  O.	
  NIERSTRASZ,	
  N.	
  SCHÄRLI,	
  R.	
  WUYTS,	
  AND	
  A.	
  P.	
  BLACK,	
  Traits:	
  A	
  Mechanism	
  
  	
  
     for	
  Fine-­‐Grained	
  Reuse,	
  ACM	
  Trans.	
  Program.	
  Lang.	
  Syst.,	
  28	
  (2006),	
  pp.	
  331–388.	
  
[4]S.	
  DUCASSE,	
  R.	
  WUYTS,	
  A.	
  BERGEL,	
  AND	
  O.	
  NIERSTRASZ,	
  User-­‐Changeable	
  Visibility:	
  
  	
  
     Resolving	
  Unan;cipated	
  Name	
  Clashes	
  in	
  Traits,	
  SIGPLAN	
  Not.,	
  42	
  (2007),	
  pp.	
  171–
     190.	
  
[5]S.	
  MARR	
  AND	
  F.	
  MENGE,	
  ezcReflec;on,	
  SVN	
  Repository,	
  eZ	
  Components,	
  January	
  
  	
  
     2008.	
  hOp://svn.ez.no/svn/ezcomponents/experimental/Reflec@on.	
  
[6]E.	
  R.	
  MURPHY-­‐HILL,	
  P.	
  J.	
  QUITSLUND,	
  AND	
  A.	
  P.	
  BLACK,	
  Removing	
  Duplica;on	
  from	
  
  	
  
     java.io:	
  a	
  Case	
  Study	
  using	
  Traits,	
  in	
  OOPSLA	
  '05:	
  Companion	
  to	
  the	
  20th	
  annual	
  
     ACM	
  SIGPLAN	
  conference	
  on	
  Object-­‐oriented	
  programming,	
  systems,	
  languages,	
  
     and	
  applica@ons,	
  New	
  York,	
  NY,	
  USA,	
  2005,	
  ACM,	
  pp.	
  282–291.	
  




15/12/10	
                                         Roundup	
  and	
  Conclusion	
                                         39	
  
Traits	
  Literature	
  
[7] 	
  PROGRAMMING	
  METHODS	
  LABORATORY,	
  Traits	
  for	
  Scala,	
  Programming	
  
        Language,	
  Ecole	
  Polytechnique	
  Fédérale	
  de	
  Lausanne,	
  2006.	
  hOp://
        www.scala-­‐lang.org/intro/traits.html.	
  
[8] 	
  P.	
  J.	
  QUITSLUND,	
  E.	
  R.	
  MURPHY-­‐HILL,	
  AND	
  A.	
  P.	
  BLACK,	
  Suppor;ng	
  Java	
  traits	
  in	
  
        Eclipse,	
  in	
  eclipse	
  '04:	
  Proceedings	
  of	
  the	
  2004	
  OOPSLA	
  workshop	
  on	
  
        eclipse	
  technology	
  eXchange,	
  New	
  York,	
  NY,	
  USA,	
  2004,	
  ACM,	
  pp.	
  37–41.	
  
[9] 	
  S.	
  REICHHART,	
  Traits	
  in	
  C#.	
  Video	
  of	
  Talk	
  at	
  MicrosoR	
  Research,	
  September	
  
        2005.	
  
[10]	
  N.	
  SCHÄRLI,	
  Traits	
  —	
  Composing	
  Classes	
  from	
  Behavioral	
  Building	
  Blocks,	
  
        PhD	
  thesis,	
  University	
  of	
  Berne,	
  Feb.	
  2005.	
  
[11]	
  SOFTWARE	
  COMPOSITION	
  GROUP,	
  Traits	
  for	
  Squeak,	
  Smalltalk	
  VM,	
  University	
  
        of	
  Berne,	
  December	
  2006.	
  hOp://www.iam.unibe.ch/	
  scg/Research/
        Traits/index.html.	
  
[12]	
  L.	
  WALL,	
  Apocalypse	
  12:	
  Class	
  Composi;on	
  with	
  Roles,	
  tech.	
  report,	
  The	
  
        Perl	
  Founda@on,	
  2004.	
  hOp://www.perl.com/pub/a/2004/04/16/
        a12.html?page=11.	
  


15/12/10	
                                       Roundup	
  and	
  Conclusion	
                                     40	
  
Ad

More Related Content

Viewers also liked (9)

DIL E Governance by neha.gangal, has 3 slides with 480 views.Data Infosys Limited is an ISO 9001 certified IT solutions company established in 1999 and headquartered in Jaipur, India. It provides a wide range of services including e-governance projects, software development, and call center services. It has expertise in sectors such as energy, transportation, banking, and telecom. The company has over 500 employees and partnerships with major tech companies. It offers end-to-end solutions from infrastructure to applications to business processes.
DIL E GovernanceDIL E Governance
DIL E Governance
neha.gangal
3 slides480 views
Manua de educacion fisica by MINEDU, has 88 slides with 597 views.This guide provides policymakers with practical guidance for developing inclusive physical education policy and practice. It outlines key considerations for building a supportive policy framework, implementing inclusive approaches, and ensuring gender equality, disability inclusion, and engagement of minority groups. The guide also offers indicators, checklists, and examples of best practices to help policymakers strengthen the delivery of quality physical education.
Manua de educacion fisicaManua de educacion fisica
Manua de educacion fisica
MINEDU
88 slides597 views
PresentacióN by guest0eb543, has 11 slides with 261 views.Los estudiantes elaboran mazapán siguiendo los pasos de mezclar cuidadosamente los ingredientes, moldear y pintar la masa con huevo antes de hornear, con la ayuda de su profesora para que queden bonitos.
PresentacióNPresentacióN
PresentacióN
guest0eb543
11 slides261 views
Final ds record by Ganisius Ganish, has 78 slides with 1026 views.The program implements operations on a stack using an array. It includes functions for push(), pop(), and display(). Push inserts an element into the stack if not full. Pop removes an element if not empty. Display prints the stack elements using a for loop. The main() uses a switch case to call the functions based on user input until exit is chosen.
Final ds recordFinal ds record
Final ds record
Ganisius Ganish
78 slides1K views
Phing101 or How to staff a build orchestra by raphaelstolt, has 39 slides with 2355 views.This document discusses Phing, an open source build tool for PHP projects. It provides an agenda for a Phing session and covers topics like installing Phing, writing Phing build files, customizing Phing with tasks and listeners, best practices, and alternatives. The document is intended to teach attendees how to automate and orchestrate builds with Phing.
Phing101 or How to staff a build orchestraPhing101 or How to staff a build orchestra
Phing101 or How to staff a build orchestra
raphaelstolt
39 slides2.4K views
Gestalt2010 2 by melikian, has 3 slides with 175 views.This document outlines key aspects of an enterprise including objectives and deliverables, systems, stakeholders, computing infrastructure, IT delivery, and systems lifecycle management. It discusses collaboration, communication, and consensus among stakeholders. It also references security, compliance, performance metrics, budgets, projects, vision, guidance, policy, profitability, risk, and the balance of value-add and non-value add activities.
Gestalt2010 2Gestalt2010 2
Gestalt2010 2
melikian
3 slides175 views
Data Infosys Limited, Jaipur by neha.gangal, has 11 slides with 3432 views.Know more about Data Infosys Limited situated at Jaipur. Data Infosys is one of the most repudiated firm in the field to Information technology and business sector.
Data Infosys Limited, JaipurData Infosys Limited, Jaipur
Data Infosys Limited, Jaipur
neha.gangal
11 slides3.4K views
Beyond Frameworks by Stuart Herbert, has 163 slides with 8164 views.The slides from my PHPUK 2011 conference talk on how to use an application framework without becoming a hostage to it.
Beyond FrameworksBeyond Frameworks
Beyond Frameworks
Stuart Herbert
163 slides8.2K views

More from Stefan Marr (20)

Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U... by Stefan Marr, has 62 slides with 65 views.This document discusses various techniques for optimizing metaprogramming and dynamic languages, including reflection, gradual typing, metaobject protocols, and dynamic optimizations like just-in-time compilation. It describes how techniques like polymorphic inline caches, hidden classes/shapes, and gradual typing checks can help optimize reflective operations and dynamic language features while preserving their flexibility. The document argues these "unoptimizable" features can achieve excellent performance through caching dynamically gathered type information and generating efficient machine code.
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Stefan Marr
62 slides65 views
Seminar on Parallel and Concurrent Programming by Stefan Marr, has 63 slides with 2441 views.This document outlines the agenda, tasks, deadlines, grading, and timeline for a seminar on parallel and concurrent programming. The agenda includes an introduction to concurrent programming models, an overview of selected seminar papers, and student presentations. Students must present on a selected paper, provide a summary and questions in advance, and submit a written report by the deadline. The report can focus on the theoretical treatment of a paper or practical reproduction of experiments. Attendance, the quality of the presentation and discussion, and the write-up determine grading. Consultations are available to prepare the presentation and agree on the report focus.
Seminar on Parallel and Concurrent ProgrammingSeminar on Parallel and Concurrent Programming
Seminar on Parallel and Concurrent Programming
Stefan Marr
63 slides2.4K views
Optimizing Communicating Event-Loop Languages with Truffle by Stefan Marr, has 27 slides with 1358 views.Communicating Event-Loop Languages similar to E and AmbientTalk are recently gaining more traction as a subset of actor languages. With the rise of JavaScript, E’s notion of vats and non-blocking communication based on promises entered the mainstream. For implementations, the combination of dynamic typing, asynchronous message sending, and promise resolution pose new optimization challenges. This paper discusses these challenges and presents initial experiments for a Newspeak implementation based on the Truffle framework. Our implementation is on average 1.65x slower than Java on a set of 14 benchmarks. Initial optimizations improve the performance of asynchronous messages and reduce the cost of encapsulation on microbenchmarks by about 2x. Parallel actor benchmarks further show that the system scales based on the workload characteristics. Thus, we conclude that Truffle is a promising platform also for communicating event-loop languages.
Optimizing Communicating Event-Loop Languages with TruffleOptimizing Communicating Event-Loop Languages with Truffle
Optimizing Communicating Event-Loop Languages with Truffle
Stefan Marr
27 slides1.4K views
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ... by Stefan Marr, has 19 slides with 1657 views.Tracing and partial evaluation have been proposed as meta-compilation techniques for interpreters to make just-in-time compilation language-independent. They promise that programs executing on simple interpreters can reach performance of the same order of magnitude as if they would be executed on state-of-the-art virtual machines with highly optimizing just-in-time compilers built for a specific language. Tracing and partial evaluation approach this meta-compilation from two ends of a spectrum, resulting in different sets of tradeoffs. This study investigates both approaches in the context of self-optimizing interpreters, a technique for building fast abstract-syntax-tree interpreters. Based on RPython for tracing and Truffle for partial evaluation, we assess the two approaches by comparing the impact of various optimizations on the performance of an interpreter for SOM, an object-oriented dynamically-typed language. The goal is to determine whether either approach yields clear performance or engineering benefits. We find that tracing and partial evaluation both reach roughly the same level of performance. SOM based on meta-tracing is on average 3x slower than Java, while SOM based on partial evaluation is on average 2.3x slower than Java. With respect to the engineering, tracing has however significant benefits, because it requires language implementers to apply fewer optimizations to reach the same level of performance.
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
Stefan Marr
19 slides1.7K views
Why Is Concurrent Programming Hard? And What Can We Do about It? by Stefan Marr, has 23 slides with 1916 views.In short, I think, it is hard because on the one hand there is not a single concurrency abstraction that fits all problems, and on the other hand the various different abstractions are rarely designed to be used in combination with each other.
Why Is Concurrent Programming Hard? And What Can We Do about It?Why Is Concurrent Programming Hard? And What Can We Do about It?
Why Is Concurrent Programming Hard? And What Can We Do about It?
Stefan Marr
23 slides1.9K views
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w... by Stefan Marr, has 28 slides with 3006 views.Runtime metaprogramming enables many useful applications and is often a convenient solution to solve problems in a generic way, which makes it widely used in frameworks, middleware, and domain-specific languages. However, powerful metaobject protocols are rarely supported and even common concepts such as reflective method invocation or dynamic proxies are not optimized. Solutions proposed in literature either restrict the metaprogramming capabilities or require application or library developers to apply performance improving techniques. For overhead-free runtime metaprogramming, we demonstrate that dispatch chains, a generalized form of polymorphic inline caches common to self-optimizing interpreters, are a simple optimization at the language-implementation level. Our evaluation with self-optimizing interpreters shows that unrestricted metaobject protocols can be realized for the first time without runtime overhead, and that this optimization is applicable for just-in-time compilation of interpreters based on meta-tracing as well as partial evaluation. In this context, we also demonstrate that optimizing common reflective operations can lead to significant performance improvements for existing applications.
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Stefan Marr
28 slides3K views
Building High-Performance Language Implementations With Low Effort by Stefan Marr, has 67 slides with 4063 views.This talk shows how languages can be implemented as self-optimizing interpreters, and how Truffle or RPython go about to just-in-time compile these interpreters to efficient native code. Programming languages are never perfect, so people start building domain-specific languages to be able to solve their problems more easily. However, custom languages are often slow, or take enormous amounts of effort to be made fast by building custom compilers or virtual machines. With the notion of self-optimizing interpreters, researchers proposed a way to implement languages easily and generate a JIT compiler from a simple interpreter. We explore the idea and experiment with it on top of RPython (of PyPy fame) with its meta-tracing JIT compiler, as well as Truffle, the JVM framework of Oracle Labs for self-optimizing interpreters. In this talk, we show how a simple interpreter can reach the same order of magnitude of performance as the highly optimizing JVM for Java. We discuss the implementation on top of RPython as well as on top of Java with Truffle so that you can start right away, independent of whether you prefer the Python or JVM ecosystem. While our own experiments focus on SOM, a little Smalltalk variant to keep things simple, other people have used this approach to improve peek performance of JRuby, or build languages such as JavaScript, R, and Python 3.
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
Stefan Marr
67 slides4.1K views
Cloud PARTE: Elastic Complex Event Processing based on Mobile Actors by Stefan Marr, has 22 slides with 2180 views.Traffic monitoring or crowd management systems produce large amounts of data in the form of events that need to be processed to detect relevant incidents. Rule-based pattern recognition is a promising approach for these applications, however, increasing amounts of data as well as large and complex rule sets demand for more and more processing power and memory. In order to scale such applications, a rule-based pattern detection system needs to be distributable over multiple machines. Today’s approaches are however focused on static distribution of rules or do not support reasoning over the full set of events. We propose Cloud PARTE, a complex event detection system that implements the Rete algorithm on top of mobile actors. These actors can migrate between machines to respond to changes in the work load distribution. Cloud PARTE is an extension of PARTE and offers the first rule engine specifically tailored for continuous complex event detection that is able to benefit from elastic systems as provided by cloud computing platforms. It supports fully automatic load balancing and supports online rules with access to the entire event pool.
Cloud PARTE: Elastic Complex Event Processing based on Mobile ActorsCloud PARTE: Elastic Complex Event Processing based on Mobile Actors
Cloud PARTE: Elastic Complex Event Processing based on Mobile Actors
Stefan Marr
22 slides2.2K views
Supporting Concurrency Abstractions in High-level Language Virtual Machines by Stefan Marr, has 60 slides with 673 views.The slides of my PhD defense, more information are available here: http://soft.vub.ac.be/~smarr/2013/01/supporting-concurrency-abstractions-in-high-level-language-virtual-machines/
Supporting Concurrency Abstractions in High-level Language Virtual MachinesSupporting Concurrency Abstractions in High-level Language Virtual Machines
Supporting Concurrency Abstractions in High-level Language Virtual Machines
Stefan Marr
60 slides673 views
Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra... by Stefan Marr, has 28 slides with 467 views.Supporting all known abstractions for concurrent and parallel programming in a virtual machines (VM) is a futile undertaking, but it is required to give programmers appropriate tools and performance. Instead of supporting all abstractions directly, VMs need a unifying mechanism similar to INVOKEDYNAMIC for JVMs. Our survey of parallel and concurrent programming concepts identifies concurrency abstractions as the ones benefiting most from support in a VM. Currently, their semantics is often weakened, reducing their engineering benefits. They require a mechanism to define flexible language guarantees. Based on this survey, we define an ownership-based meta-object protocol as candidate for VM support. We demonstrate its expressiveness by implementing actor semantics, software transactional memory, agents, CSP, and active objects. While the performance of our prototype confirms the need for VM support, it also shows that the chosen mechanism is appropriate to express a wide range of concurrency abstractions in a unified way.
Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...
Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...
Stefan Marr
28 slides467 views
Sly and the RoarVM: Parallel Programming with Smalltalk by Stefan Marr, has 18 slides with 2177 views.This document discusses the RoarVM and Sly programming language in the context of parallel and distributed programming for manycore architectures. It introduces the RoarVM, an enhanced Smalltalk virtual machine that supports parallelism. It also describes Sly, a programming language being developed as part of the Renaissance Project that aims to embrace nondeterminism in parallel programs by using ensembles, adverbs and gerunds. Examples of using Sly to model flocking behavior are provided. The document argues that Sly shows promise as a programming model for scalable applications on manycore systems.
Sly and the RoarVM: Parallel Programming with SmalltalkSly and the RoarVM: Parallel Programming with Smalltalk
Sly and the RoarVM: Parallel Programming with Smalltalk
Stefan Marr
18 slides2.2K views
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul... by Stefan Marr, has 20 slides with 503 views.While parallel programming for very regular problems has been used in the scientific community by non-computer-scientists successfully for a few decades now, concurrent programming and solving irregular problems remains hard. Furthermore, we shift from few expert system programmers mastering concurrency for a constrained set of problems to mainstream application developers being required to master concurrency for a wide variety of problems. Consequently, high-level language virtual machine (VM) research faces interesting questions. What are processor design changes that have an impact on the abstractions provided by VMs to provide platform independence? How can application programmers’ diverse needs be facilitated to solve concurrent programming problems? We argue that VMs will need to be ready for a wide range of different concurrency models that allow solving concurrency problems with appropriate abstractions. Furthermore, they need to abstract from heterogeneous processor architectures, varying performance characteristics, need to account for memory access cost and inter-core communication mechanisms but should only expose the minimal useful set of notions like locality, explicit communication, and adaptable scheduling to maintain their abstracting nature. Eventually, language designers need to be enabled to guarantee properties like encapsulation, scheduling guarantees, and immutability also when an interaction between different problem-specific concurrency abstractions is required.
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
Stefan Marr
20 slides503 views
Sly and the RoarVM: Exploring the Manycore Future of Programming by Stefan Marr, has 22 slides with 7627 views.The manycore future has several challenges ahead of us that suggest that fundamental assumptions of contemporary programming approaches do not apply anymore when scalability is required. Sly is a language prototype designed to experiment with the inherently nondeterministic properties of parallel systems. It is designed to enable programmers to embrace nondeterminism instead of guiding them to fight it. Nature shows that complex system can be built from independent entities that achieve a common goal without global synchronization/communication. Sly is design to enable the prototyping of algorithms that show such emerging behavior. It will be introduced in the first part of the talk. The second part of the talk will focus on the underlying problems of building virtual machines for the manycore future, which allow to harness the available computing power. The RoarVM was design to experiment on the Tilera TILE64 manycore processor architecture which provides 64 cores and characteristics that are distinctly different from today's commodity multicore processors. Memory bandwidth, caches and communication are the biggest challenges on such architectures and this talk will give a brief overview over the design choices of the RoarVM which tackle the characteristics of the TILE64 architecture. Acknowledgement: Sly and the RoarVM were designed and implemented by David Ungar and Sam Adams at IBM Research.
Sly and the RoarVM: Exploring the Manycore Future of ProgrammingSly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of Programming
Stefan Marr
22 slides7.6K views
The Price of the Free Lunch: Programming in the Multicore Era by Stefan Marr, has 20 slides with 785 views.The multicore era comes with new challenges for software engineers. The Software Languages Lab and its Parallel Programming Group does research on languages and language runtimes/virtual machines for the new era of multi- and manycore hardware. This talk gives a brief introduction to the problem and names our approaches to tackle the challenges. However, since this is presented as a Pecha Kucha, the talk is very abstract and focuses on conveying the theme instead of technical details.
The Price of the Free Lunch: Programming in the Multicore EraThe Price of the Free Lunch: Programming in the Multicore Era
The Price of the Free Lunch: Programming in the Multicore Era
Stefan Marr
20 slides785 views
Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan... by Stefan Marr, has 24 slides with 397 views.We propose to search for common abstractions for different concurrency models to enable high-level language virtual machines to support a wide range of different concurrency models. This would enable domain-specific solutions for the concurrency problem. Furthermore, advanced knowledge about concurrency in the VM model will most likely lead to better implementation opportunities on top of the different upcoming many-core architectures. The idea is to investigate the concepts of encapsulation and locality to this end. Thus, we are going to experiment with different language abstractions for concurrency on top of a virtual machine, which supports encapsulation and locality, to see how language designers could benefit, and how virtual machines could optimize programs using these concepts.
Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...
Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...
Stefan Marr
24 slides397 views
Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi... by Stefan Marr, has 39 slides with 337 views.This paper presents an algorithm and a data structure for scalable dynamic synchronization in fine-grained parallelism. The algorithm supports the full generality of phasers with dynamic, two-phase, and point-to-point synchronization. It retains the scalability of classical tree barriers, but provides unbounded dynamicity by employing a tailor-made insertion tree data structure. It is the first completely documented implementation strategy for a scalable phaser synchronization construct. Our evaluation shows that it can be used as a drop-in replacement for classic barriers without harming performance, despite its additional complexity and potential for performance optimizations. Furthermore, our approach overcomes performance and scalability limitations which have been present in other phaser proposals.
Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...
Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...
Stefan Marr
39 slides337 views
Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan... by Stefan Marr, has 10 slides with 355 views.The goal of my research is to investigate the notions of encapsulation and locality and evaluate how they could be used inside of a virtual machine to better support different concurrency models on top of it, and retain the potential for optimization on different many-core architectures.
Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...
Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...
Stefan Marr
10 slides355 views
Intermediate Language Design of High-level Language VMs: Towards Comprehensiv... by Stefan Marr, has 26 slides with 646 views.The document discusses intermediate language design for virtual machines to provide comprehensive concurrency support. It surveys 17 existing virtual machines to evaluate their concurrency support and models. Only 6 provided explicit concurrency support in the intermediate language. Support ranged from low-level instructions to high-level constructs in standard libraries. To enable new concurrency concepts, future virtual machines need intermediate languages that support both low-level and high-level concurrency features, with an open question around the tradeoffs of features in the intermediate language versus the standard library.
Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...
Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...
Stefan Marr
26 slides646 views
Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from... by Stefan Marr, has 13 slides with 663 views.The upcoming many-core architectures require software developers to exploit concurrency to utilize available computational power. We argue that today's virtual machines (VMs), which are a cornerstone of software development, do not provide sufficient abstraction for concurrency concepts. To overcome this shortcoming, we propose to integrate concurrency operations into VM instruction sets. Since there will always be VMs optimized for special purposes, our goal is to develop a methodology to design instruction sets with concurrency support. Therefore, we also propose a list of tradeoffs that have to be investigated to advise the design of such instruction sets. As a first experiment, we implemented one instruction set extension for shared memory and one for non-shared memory concurrency. From our experimental results, we derived a list of requirements for a full-grown experimental environment for further research.
Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...
Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...
Stefan Marr
13 slides663 views
VMADL: An Architecture Definition Language for Variability and Composition ... by Stefan Marr, has 26 slides with 659 views.High-level language virtual machines (VMs) can be used on a wide range of devices as a basic part of the deployed software stack. As the available devices differ to a large degree in their applications and their available resources, distinct implementation strategies have to be used for certain parts of a VM to meet the special requirements. This paper motivates the need for an architecture definition language for complex software systems like VM implementations. The basic concepts and language constructs of this language, which is called VMADL, are introduced. To motivate further discussions, the benefits of this approach are briefly discussed.
VMADL: An Architecture Definition Language  for Variability and Composition  ...VMADL: An Architecture Definition Language  for Variability and Composition  ...
VMADL: An Architecture Definition Language for Variability and Composition ...
Stefan Marr
26 slides659 views
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ... by Stefan Marr, has 19 slides with 1657 views.Tracing and partial evaluation have been proposed as meta-compilation techniques for interpreters to make just-in-time compilation language-independent. They promise that programs executing on simple interpreters can reach performance of the same order of magnitude as if they would be executed on state-of-the-art virtual machines with highly optimizing just-in-time compilers built for a specific language. Tracing and partial evaluation approach this meta-compilation from two ends of a spectrum, resulting in different sets of tradeoffs. This study investigates both approaches in the context of self-optimizing interpreters, a technique for building fast abstract-syntax-tree interpreters. Based on RPython for tracing and Truffle for partial evaluation, we assess the two approaches by comparing the impact of various optimizations on the performance of an interpreter for SOM, an object-oriented dynamically-typed language. The goal is to determine whether either approach yields clear performance or engineering benefits. We find that tracing and partial evaluation both reach roughly the same level of performance. SOM based on meta-tracing is on average 3x slower than Java, while SOM based on partial evaluation is on average 2.3x slower than Java. With respect to the engineering, tracing has however significant benefits, because it requires language implementers to apply fewer optimizations to reach the same level of performance.
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
Stefan Marr
19 slides1.7K views
Building High-Performance Language Implementations With Low Effort by Stefan Marr, has 67 slides with 4063 views.This talk shows how languages can be implemented as self-optimizing interpreters, and how Truffle or RPython go about to just-in-time compile these interpreters to efficient native code. Programming languages are never perfect, so people start building domain-specific languages to be able to solve their problems more easily. However, custom languages are often slow, or take enormous amounts of effort to be made fast by building custom compilers or virtual machines. With the notion of self-optimizing interpreters, researchers proposed a way to implement languages easily and generate a JIT compiler from a simple interpreter. We explore the idea and experiment with it on top of RPython (of PyPy fame) with its meta-tracing JIT compiler, as well as Truffle, the JVM framework of Oracle Labs for self-optimizing interpreters. In this talk, we show how a simple interpreter can reach the same order of magnitude of performance as the highly optimizing JVM for Java. We discuss the implementation on top of RPython as well as on top of Java with Truffle so that you can start right away, independent of whether you prefer the Python or JVM ecosystem. While our own experiments focus on SOM, a little Smalltalk variant to keep things simple, other people have used this approach to improve peek performance of JRuby, or build languages such as JavaScript, R, and Python 3.
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
Stefan Marr
67 slides4.1K views
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul... by Stefan Marr, has 20 slides with 503 views.While parallel programming for very regular problems has been used in the scientific community by non-computer-scientists successfully for a few decades now, concurrent programming and solving irregular problems remains hard. Furthermore, we shift from few expert system programmers mastering concurrency for a constrained set of problems to mainstream application developers being required to master concurrency for a wide variety of problems. Consequently, high-level language virtual machine (VM) research faces interesting questions. What are processor design changes that have an impact on the abstractions provided by VMs to provide platform independence? How can application programmers’ diverse needs be facilitated to solve concurrent programming problems? We argue that VMs will need to be ready for a wide range of different concurrency models that allow solving concurrency problems with appropriate abstractions. Furthermore, they need to abstract from heterogeneous processor architectures, varying performance characteristics, need to account for memory access cost and inter-core communication mechanisms but should only expose the minimal useful set of notions like locality, explicit communication, and adaptable scheduling to maintain their abstracting nature. Eventually, language designers need to be enabled to guarantee properties like encapsulation, scheduling guarantees, and immutability also when an interaction between different problem-specific concurrency abstractions is required.
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
Stefan Marr
20 slides503 views
Sly and the RoarVM: Exploring the Manycore Future of Programming by Stefan Marr, has 22 slides with 7627 views.The manycore future has several challenges ahead of us that suggest that fundamental assumptions of contemporary programming approaches do not apply anymore when scalability is required. Sly is a language prototype designed to experiment with the inherently nondeterministic properties of parallel systems. It is designed to enable programmers to embrace nondeterminism instead of guiding them to fight it. Nature shows that complex system can be built from independent entities that achieve a common goal without global synchronization/communication. Sly is design to enable the prototyping of algorithms that show such emerging behavior. It will be introduced in the first part of the talk. The second part of the talk will focus on the underlying problems of building virtual machines for the manycore future, which allow to harness the available computing power. The RoarVM was design to experiment on the Tilera TILE64 manycore processor architecture which provides 64 cores and characteristics that are distinctly different from today's commodity multicore processors. Memory bandwidth, caches and communication are the biggest challenges on such architectures and this talk will give a brief overview over the design choices of the RoarVM which tackle the characteristics of the TILE64 architecture. Acknowledgement: Sly and the RoarVM were designed and implemented by David Ungar and Sam Adams at IBM Research.
Sly and the RoarVM: Exploring the Manycore Future of ProgrammingSly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of Programming
Stefan Marr
22 slides7.6K views
Ad

Recently uploaded (20)

The Microsoft Excel Parts Presentation.pdf by YvonneRoseEranista, has 13 slides with 17 views.This is an overview of the different parts of the Microsoft Excel.
The Microsoft Excel Parts Presentation.pdfThe Microsoft Excel Parts Presentation.pdf
The Microsoft Excel Parts Presentation.pdf
YvonneRoseEranista
13 slides17 views
AI You Can Trust: The Critical Role of Governance and Quality.pdf by Precisely, has 16 slides with 26 views.
AI You Can Trust: The Critical Role of Governance and Quality.pdfAI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdf
Precisely
16 slides26 views
Heap, Types of Heap, Insertion and Deletion by Jaydeep Kale, has 7 slides with 154 views.This pdf will explain what is heap, its type, insertion and deletion in heap and Heap sort
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
7 slides154 views
Viam product demo_ Deploying and scaling AI with hardware.pdf by camilalamoratta, has 26 slides with 42 views.Building AI-powered products that interact with the physical world often means navigating complex integration challenges, especially on resource-constrained devices. You'll learn: - How Viam's platform bridges the gap between AI, data, and physical devices - A step-by-step walkthrough of computer vision running at the edge - Practical approaches to common integration hurdles - How teams are scaling hardware + software solutions together Whether you're a developer, engineering manager, or product builder, this demo will show you a faster path to creating intelligent machines and systems. Resources: - Documentation: https://on.viam.com/docs - Community: https://discord.com/invite/viam - Hands-on: https://on.viam.com/codelabs - Future Events: https://on.viam.com/updates-upcoming-events - Request personalized demo: https://on.viam.com/request-demo
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
26 slides42 views
TrsLabs Consultants - DeFi, WEb3, Token Listing by Trs Labs, has 7 slides with 48 views.Enter the world of web3 with experienced strategic partner. Open your business to new opportunities.
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
7 slides48 views
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025 by BookNet Canada, has 31 slides with 146 views.Book industry standards are evolving rapidly. In the first part of this session, we’ll share an overview of key developments from 2024 and the early months of 2025. Then, BookNet’s resident standards expert, Tom Richardson, and CEO, Lauren Stewart, have a forward-looking conversation about what’s next. Link to recording, transcript, and accompanying resource: https://bnctechforum.ca/sessions/standardsgoals-for-2025-standards-certification-roundup/ Presented by BookNet Canada on May 6, 2025 with support from the Department of Canadian Heritage.
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
31 slides146 views
MINDCTI revenue release Quarter 1 2025 PR by MIND CTI, has 27 slides with 165 views.MINDCTI revenue release Quarter 1 202
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
27 slides165 views
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève by UiPathCommunity, has 9 slides with 42 views.Nous vous convions à une nouvelle séance de la communauté UiPath en Suisse romande. Cette séance sera consacrée à un retour d'expérience de la part d'une organisation non gouvernementale basée à Genève. L'équipe en charge de la plateforme UiPath pour cette NGO nous présentera la variété des automatisations mis en oeuvre au fil des années : de la gestion des donations au support des équipes sur les terrains d'opération. Au délà des cas d'usage, cette session sera aussi l'opportunité de découvrir comment cette organisation a déployé UiPath Automation Suite et Document Understanding. Cette session a été diffusée en direct le 7 mai 2025 à 13h00 (CET). Découvrez toutes nos sessions passées et à venir de la communauté UiPath à l’adresse suivante : https://community.uipath.com/geneva/.
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
9 slides42 views
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster by All Things Open, has 50 slides with 108 views.Presented at All Things Open RTP Meetup Presented by Brent Laster - President & Lead Trainer, Tech Skills Transformations LLC Talk Title: AI 3-in-1: Agents, RAG, and Local Models Abstract: Learning and understanding AI concepts is satisfying and rewarding, but the fun part is learning how to work with AI yourself. In this presentation, author, trainer, and experienced technologist Brent Laster will help you do both! We’ll explain why and how to run AI models locally, the basic ideas of agents and RAG, and show how to assemble a simple AI agent in Python that leverages RAG and uses a local model through Ollama. No experience is needed on these technologies, although we do assume you do have a basic understanding of LLMs. This will be a fast-paced, engaging mixture of presentations interspersed with code explanations and demos building up to the finished product – something you’ll be able to replicate yourself after the session!
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
50 slides108 views
Financial Services Technology Summit 2025 by Ray Bugg, has 176 slides with 24 views.The FS Technology Summit Technology increasingly permeates every facet of the financial services sector, from personal banking to institutional investment to payments. ​ The conference will explore the transformative impact of technology on the modern FS enterprise, examining how it can be applied to drive practical business improvement and frontline customer impact. ​ The programme will contextualise the most prominent trends that are shaping the industry, from technical advancements in Cloud, AI, Blockchain and Payments, to the regulatory impact of Consumer Duty, SDR, DORA & NIS2. ​ The Summit will bring together senior leaders from across the sector, and is geared for shared learning, collaboration and high-level networking. The FS Technology Summit will be held as a sister event to our 12th annual Fintech Summit.
Financial Services Technology Summit 2025Financial Services Technology Summit 2025
Financial Services Technology Summit 2025
Ray Bugg
176 slides24 views
Transcript: Canadian book publishing: Insights from the latest salary survey ... by BookNet Canada, has 14 slides with 42 views.Join us for a presentation in partnership with the Association of Canadian Publishers (ACP) as they share results from the recently conducted Canadian Book Publishing Industry Salary Survey. This comprehensive survey provides key insights into average salaries across departments, roles, and demographic metrics. Members of ACP’s Diversity and Inclusion Committee will join us to unpack what the findings mean in the context of justice, equity, diversity, and inclusion in the industry. Results of the 2024 Canadian Book Publishing Industry Salary Survey: https://publishers.ca/wp-content/uploads/2025/04/ACP_Salary_Survey_FINAL-2.pdf Link to presentation slides and transcript: https://bnctechforum.ca/sessions/canadian-book-publishing-insights-from-the-latest-salary-survey/ Presented by BookNet Canada and the Association of Canadian Publishers on May 1, 2025 with support from the Department of Canadian Heritage.
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
14 slides42 views
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive by ScyllaDB, has 17 slides with 212 views.Want to learn practical tips for designing systems that can scale efficiently without compromising speed? Join us for a workshop where we’ll address these challenges head-on and explore how to architect low-latency systems using Rust. During this free interactive workshop oriented for developers, engineers, and architects, we’ll cover how Rust’s unique language features and the Tokio async runtime enable high-performance application development. As you explore key principles of designing low-latency systems with Rust, you will learn how to: - Create and compile a real-world app with Rust - Connect the application to ScyllaDB (NoSQL data store) - Negotiate tradeoffs related to data modeling and querying - Manage and monitor the database for consistently low latencies
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
17 slides212 views
Zilliz Cloud Monthly Technical Review: May 2025 by Zilliz , has 17 slides with 20 views.About this webinar Join our monthly demo for a technical overview of Zilliz Cloud, a highly scalable and performant vector database service for AI applications Topics covered - Zilliz Cloud's scalable architecture - Key features of the developer-friendly UI - Security best practices and data privacy - Highlights from recent product releases This webinar is an excellent opportunity for developers to learn about Zilliz Cloud's capabilities and how it can support their AI projects. Register now to join our community and stay up-to-date with the latest vector database technology.
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
17 slides20 views
Canadian book publishing: Insights from the latest salary survey - Tech Forum... by BookNet Canada, has 13 slides with 43 views.Join us for a presentation in partnership with the Association of Canadian Publishers (ACP) as they share results from the recently conducted Canadian Book Publishing Industry Salary Survey. This comprehensive survey provides key insights into average salaries across departments, roles, and demographic metrics. Members of ACP’s Diversity and Inclusion Committee will join us to unpack what the findings mean in the context of justice, equity, diversity, and inclusion in the industry. Results of the 2024 Canadian Book Publishing Industry Salary Survey: https://publishers.ca/wp-content/uploads/2025/04/ACP_Salary_Survey_FINAL-2.pdf Link to presentation recording and transcript: https://bnctechforum.ca/sessions/canadian-book-publishing-insights-from-the-latest-salary-survey/ Presented by BookNet Canada and the Association of Canadian Publishers on May 1, 2025 with support from the Department of Canadian Heritage.
Canadian book publishing: Insights from the latest salary survey - Tech Forum...Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
BookNet Canada
13 slides43 views
HCL Nomad Web – Best Practices and Managing Multiuser Environments by panagenda, has 35 slides with 103 views.Webinar Recording: https://www.panagenda.com/webinars/hcl-nomad-web-best-practices-and-managing-multiuser-environments/ HCL Nomad Web is heralded as the next generation of the HCL Notes client, offering numerous advantages such as eliminating the need for packaging, distribution, and installation. Nomad Web client upgrades will be installed “automatically” in the background. This significantly reduces the administrative footprint compared to traditional HCL Notes clients. However, troubleshooting issues in Nomad Web present unique challenges compared to the Notes client. Join Christoph and Marc as they demonstrate how to simplify the troubleshooting process in HCL Nomad Web, ensuring a smoother and more efficient user experience. In this webinar, we will explore effective strategies for diagnosing and resolving common problems in HCL Nomad Web, including - Accessing the console - Locating and interpreting log files - Accessing the data folder within the browser’s cache (using OPFS) - Understand the difference between single- and multi-user scenarios - Utilizing Client Clocking
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
35 slides103 views
How to Install & Activate ListGrabber - eGrabber by eGrabber, has 8 slides with 33 views.ListGrabber: Build Targeted Lists Online in Minutes
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
8 slides33 views
AI Agents at Work: UiPath, Maestro & the Future of Documents by UiPathCommunity, has 14 slides with 39 views.Do you find yourself whispering sweet nothings to OCR engines, praying they catch that one rogue VAT number? Well, it’s time to let automation do the heavy lifting – with brains and brawn. Join us for a high-energy UiPath Community session where we crack open the vault of Document Understanding and introduce you to the future’s favorite buzzword with actual bite: Agentic AI. This isn’t your average “drag-and-drop-and-hope-it-works” demo. We’re going deep into how intelligent automation can revolutionize the way you deal with invoices – turning chaos into clarity and PDFs into productivity. From real-world use cases to live demos, we’ll show you how to move from manually verifying line items to sipping your coffee while your digital coworkers do the grunt work: 📕 Agenda: 🤖 Bots with brains: how Agentic AI takes automation from reactive to proactive 🔍 How DU handles everything from pristine PDFs to coffee-stained scans (we’ve seen it all) 🧠 The magic of context-aware AI agents who actually know what they’re doing 💥 A live walkthrough that’s part tech, part magic trick (minus the smoke and mirrors) 🗣️ Honest lessons, best practices, and “don’t do this unless you enjoy crying” warnings from the field So whether you’re an automation veteran or you still think “AI” stands for “Another Invoice,” this session will leave you laughing, learning, and ready to level up your invoice game. Don’t miss your chance to see how UiPath, DU, and Agentic AI can team up to turn your invoice nightmares into automation dreams. This session streamed live on May 07, 2025, 13:00 GMT. Join us and check out all our past and upcoming UiPath Community sessions at: 👉 https://community.uipath.com/dublin-belfast/
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
14 slides39 views
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx by MSP360, has 11 slides with 55 views.Data loss can be devastating — especially when you discover it while trying to recover. All too often, it happens due to mistakes in your backup strategy. Whether you work for an MSP or within an organization, your company is susceptible to common backup mistakes that leave data vulnerable, productivity in question, and compliance at risk. Join 4-time Microsoft MVP Nick Cavalancia as he breaks down the top five backup mistakes businesses and MSPs make—and, more importantly, explains how to prevent them.
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
11 slides55 views
AI You Can Trust: The Critical Role of Governance and Quality.pdf by Precisely, has 16 slides with 26 views.
AI You Can Trust: The Critical Role of Governance and Quality.pdfAI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdf
Precisely
16 slides26 views
AI Agents at Work: UiPath, Maestro & the Future of Documents by UiPathCommunity, has 14 slides with 39 views.Do you find yourself whispering sweet nothings to OCR engines, praying they catch that one rogue VAT number? Well, it’s time to let automation do the heavy lifting – with brains and brawn. Join us for a high-energy UiPath Community session where we crack open the vault of Document Understanding and introduce you to the future’s favorite buzzword with actual bite: Agentic AI. This isn’t your average “drag-and-drop-and-hope-it-works” demo. We’re going deep into how intelligent automation can revolutionize the way you deal with invoices – turning chaos into clarity and PDFs into productivity. From real-world use cases to live demos, we’ll show you how to move from manually verifying line items to sipping your coffee while your digital coworkers do the grunt work: 📕 Agenda: 🤖 Bots with brains: how Agentic AI takes automation from reactive to proactive 🔍 How DU handles everything from pristine PDFs to coffee-stained scans (we’ve seen it all) 🧠 The magic of context-aware AI agents who actually know what they’re doing 💥 A live walkthrough that’s part tech, part magic trick (minus the smoke and mirrors) 🗣️ Honest lessons, best practices, and “don’t do this unless you enjoy crying” warnings from the field So whether you’re an automation veteran or you still think “AI” stands for “Another Invoice,” this session will leave you laughing, learning, and ready to level up your invoice game. Don’t miss your chance to see how UiPath, DU, and Agentic AI can team up to turn your invoice nightmares into automation dreams. This session streamed live on May 07, 2025, 13:00 GMT. Join us and check out all our past and upcoming UiPath Community sessions at: 👉 https://community.uipath.com/dublin-belfast/
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
14 slides39 views
Ad

PHP.next: Traits

  • 1. PHP.next:  Traits   Horizontal  Reuse  of  Behavior   Stefan  Marr   AFUP,  La  Can@ne,  Paris   15th  December  2010  
  • 2. Ques@ons  at  any  @me  
  • 3. Traits  for  PHP  Started  December  2007   15/12/10   3  
  • 4. Today:  Virtual  Machines  for  the  Manycore  Era   hOp://soR.vub.ac.be/~smarr/research/   hOp://github.com/smarr/RoarVM   15/12/10   4  
  • 5. Who  are  you?   •  PHP  Programmer:  Job  or  Hobby?   •  C  Programmer?  (PHP  core/extensions?)   •  Contribu@on  to  Open  Source  projects?   15/12/10   5  
  • 6. Off-­‐Topic…   Anyone  using:   •  COCOMO,  COCOMO  II   •  Func@on  points   •  User  Story  Points   15/12/10   6  
  • 7. Ques@ons  at  any  @me  
  • 8. Agenda   •  Why  Traits?   •  The  Language  Design   •  Traits  Applied   •  Implementa@on  inside  the  Zend  Engine   15/12/10   8  
  • 9. Reuse  in  Programming  Languages   WHY  TRAITS?   15/12/10   Stefan  Marr  –  PHP.next:  Traits   9  
  • 10. Single  Inheritance   Vertebrates •  Simple  but  not     expressive  enough   •  Leads  to   Dinosaurs Mammal •  Code  duplica@on   •  Inappropriate     hierarchies   Archaeoptrix Bat fly() fly() 15/12/10   Approaches  for  ComposiIon  and  their  Limits   10  
  • 11. Mul@ple  Inheritance   Animal •  Very  expressive   +move() •  But   Bird Swimmer •  Diamond  problem   +move() +move() •  Fragile  hierarchies   +getLegs() Penguin class Penguin { function move() { +move() Swimmer::move(); } } 15/12/10   Approaches  for  ComposiIon  and  their  Limits   11  
  • 12. Mixins   Animal WingAnimal <<mixin>> (1) Bat <<mixin>> (1) bones = light extremity = wings Penguin move() <<mixin>> (2) SwimAnimal extremity = fins move() 15/12/10   Approaches  for  ComposiIon  and  their  Limits   12  
  • 13. Mixins   Animal WingAnimal <<mixin>> (1) Bat <<mixin>> (1) bones = light extremity = wings Penguin move() <<mixin>> (2) SwimAnimal extremity = fins •  Lack  of  composi@on   move() control   •  Fragile  hierarchies   15/12/10   Approaches  for  ComposiIon  and  their  Limits   13  
  • 14. Limita@ons   •  Code  duplica@on   •  Inappropriate  hierarchies   •  Diamond  problem   •  Fragile  hierarchies   •  Lack  of  composi@on  control   15/12/10   Approaches  for  ComposiIon  and  their  Limits   14  
  • 15. Traits  for  PHP   THE  LANGUAGE  DESIGN   15/12/10   Stefan  Marr  –  PHP.next:  Traits   15    
  • 16. Traits   •  Set  of  methods   •  Possibly  composed  of  other  Traits   •  Composi@on  is  unordered   TFoo •  Composi@on  opera@ons   TTrait foo() TBar –  Sum   m1() m2() bar() MyClass –  Exclusion   TConflict –  Aliasing   m2() •  Can  be  flaOened  away   15/12/10   Traits   16  
  • 17. Traits  in  Ac@on   15/12/10   Traits   17  
  • 18. Method  in  Class  Overrides  Trait   Base   foo()   class  Base  {   Code      function  foo()  {  echo  'B';}}   A   T     foo()   foo()   trait  T  {      function  foo()  {  echo  'T';}}   Base     Compiled  Result   foo()   class  A  extends  Base  {      use  T;      function  foo()  {  echo  'A';}}   A   foo()   echo  'A';   15/12/10   Traits   18  
  • 19. Conflicts  are  Explicit   Base   class  Base  {   foo()      function  foo()  {  echo  'B';}}   T1     Code   foo()   trait  T1  {   A      function  foo()  {echo  'T1';}}   T2     foo()   trait  T2  {   Base      function  foo()  {echo  'T2';}}   Compiled  Result   foo()     class  A  extends  Base  {      use  T1,  T2;   A   >>  Fatal  error:     }        collision  on  foo   15/12/10   Traits   19    
  • 20. Solving  Conflicts   Base   class  Base  {   foo()      function  foo()  {  echo  'B';}}   T1   trait  T1  {   Code   foo()      function  foo()  {echo  'T1';}}   A   trait  T2  {   T2      function  foo()  {echo  'T2';}}   !foo   foo()     Base   class  A  extends  Base  {   Compiled  Result   foo()      use  T1,  T2  {          T1::foo  insteadof  T2;      }   A   }   foo()   >>  echo  'T1';   15/12/10   Traits   20    
  • 21. Aliasing   Base   class  Base  {   foo()      function  foo()  {  echo  'B';}}   T1   trait  T1  {   Code   foo()      function  foo()  {echo  'T1';}}   A   trait  T2  {   !foo   T2      function  foo()  {echo  'T2';}}   +foo2   foo()     Base   class  A  extends  Base  {   Compiled  Result   foo()      use  T1,  T2  {          T1::foo  insteadof  T2;          T2::foo  as  fooT2;   A   foo()   >>  echo  'T1';      }   foo2()   >>  echo  'T2';   }   15/12/10   Traits   21    
  • 22. Aliasing  IS  NOT  Renaming   trait  T1  {   class  A  {      function  bar()  {          echo  'T1::bar';      use  T1,  T2  {      }          T2::bar  insteadof  T1;      function  foo()  {          T1::bar  as  bar2;          $this-­‐>bar();      }      }   }   }   trait  T2  {        function  bar()  {   $a  =  new  A;          echo  'T2::bar’;      }   $a-­‐>foo();  //  echo  ??   }   15/12/10   Traits   22    
  • 23. Late  Binding  for  Composability   trait  MovingAnimal  {   class  Penguin  {      function  move()  {      use  WingAnimal,  SwimAnimal  {          $this-­‐>extremities()-­‐>use();          WingAnimal::extremities      }}              insteadof  SwimAnimal;   trait  WingAnimal  {      }      use  MovingAnimal;   }      function  extremities()  {            return  $this-­‐>wings;   $skipper  =  new  Penguin;      }}   $skipper-­‐>move();  //  will  use   trait  SwimAnimal  {                                            his  wings      use  MovingAnimal;      function  extremities()  {          return  $this-­‐>fins;      }}   15/12/10   Traits   23    
  • 24. Traits  and  State   trait  Counter  {      abstract  function  &getValueVar();      function  inc($inc  =  1)  {          $var  =  &$this-­‐>getValueVar();          $var  =  $var  +  $inc;      }}   class  PageWithCounter  {      use  Counter;      public  $counter  =  1;      function  &getValueVar()  {  return  $this-­‐>counter;  }   }   $page  =  new  PageWithCounter;  $page-­‐>inc();   var_dump($page-­‐>counter);   15/12/10   Traits   24    
  • 25. Case  Studies  Illustra@ng  Benefits  of  Traits   TRAITS  APPLIED   15/12/10   Stefan  Marr  –  PHP.next:  Traits   25    
  • 26. Use  Case  for  Traits   •  ezcReflec@on  enhances  PHP  Reflec@on  API   –  Adds  XDoclet  like  annota@ons  for  PHP   –  Enhances  type  hin@ng  using  PHPDoc  type   annota@ons   •  Illustrates  solu@on  for  code  duplica@on   problems   «interface» Reflector ReflectionProperty ReflectionClass ReflectionFunction ReflectionParameter ReflectionObject ReflectionMethod 15/12/10   Traits  Applied   26  
  • 27. Refactoring  ezcReflec@on  with  Traits   15/12/10   Traits  Applied   27  
  • 28. Refactoring  ezcReflec@on  with  Traits   15/12/10   Traits  Applied   28  
  • 29. Implementa@on  details:   Not  to  be  confused  with  language  seman@cs!   The  Traits  Implementa@on   INSIDE  THE  ZEND  ENGINE   15/12/10   Stefan  Marr  –  PHP.next:  Traits   29    
  • 30. Zend  Engine  Overview   PHP  +  Zend  Engine   YACC   Opcodes   Script   Parser   Structures   Opcode   Interpreter   Result   Input   Input   15/12/10   Traits  inside  the  Zend  Engine   30  
  • 31. YACC   Parser   Parser   •  Added  keywords   –  trait   –  insteadof   •  Grammar  rules  based  on  class     15/12/10   Traits  inside  the  Zend  Engine   31    
  • 32. PHP  +  Zend   Engine   Zend  Engine   •  Trait  internally  a  class  with  ZEND_ACC_TRAIT   –  New  data  structures   •  zend_trait_method_reference   •  zend_trait_precedence   •  zend_trait_alias   –  Class  members  added  to  zend_class_entry   •  zend_class_entry  **traits;   •  zend_uint  num_traits;   •  zend_trait_alias  **trait_aliases;   •  zend_trait_precedence  **trait_precedences;   •  Support  in  Reflec@on  API   15/12/10   Traits  inside  the  Zend  Engine   32    
  • 33. Opcode   Interpreter   Interpreter   •  Added  Opcodes   –  ZEND_ADD_TRAIT   •  similar  to  ZEND_ADD_INTERFACE   •  Only  adds  info,  no  composi@on  done   –  ZEND_BIND_TRAITS   •  emiOed  in  zend_do_end_class_declara@on   •  will  ini@ate  trait  composi@on  at  run@me   –  Only  once,  part  of  class  defini@on  process     –  (no  run@me  overhead)   15/12/10   Traits  inside  the  Zend  Engine   33    
  • 34. PHP  +  Zend   Engine   Composi@on  Process   •  Implemented  in  zend_do_bind_traits   1.  Init  traits  data  structures  (resolve  classes)   2.  For  all  used  traits   –  Compile  method  table  of  all  used  methods   –  Respect  exclusion  and  aliases   3.  Merge  resul@ng  tables   4.  Add  methods  to  class   –  Handle  abstract  methods,  inheritance   –  duplicate  func@on  (like  copy/paste,  enables  static)   15/12/10   Traits  inside  the  Zend  Engine   34    
  • 35. ROUNDUP  AND  CONCLUSION   15/12/10   Stefan  Marr  –  PHP.next:  Traits   35    
  • 36. References  for  Traits  in  PHP   RFC:  Horizontal  Reuse  in  PHP   Version  2.0.1,  last  update  2010-­‐11-­‐18   hOp://wiki.php.net/rfc/horizontalreuse     Interes@ng  Blog  Posts   –  Simas  Toleikis:  Overview,  similar  to  RFC   •  hOp://simas.posterous.com/new-­‐to-­‐php-­‐54-­‐traits   –  Sebas@an  Deutsch:  Ac@veRecord  with  Traits   •  hOp://9elements.com/io/?p=28   15/12/10   Roundup  and  Conclusion   36    
  • 37. Conclusion   •  Traits  are  mechanism  for  reuse  of  behavior   •  Avoid  limita@ons  of  other  approaches   –  Avoid  code  duplica@on   –  Enhance  class  composi@on  capabili@es   •  “Compiler  assisted  copy’n’paste”   –  FlaOened  into  class   –  No  run@me  overhead   15/12/10   Roundup  and  Conclusion   37    
  • 38. Basic  Literature  on  Traits   Main  ArIcle  about  Traits     [3]  S.  DUCASSE,  O.  NIERSTRASZ,  N.  SCHÄRLI,  R.  WUYTS,  AND  A.  P.   BLACK,  Traits:  A  Mechanism  for  Fine-­‐Grained  Reuse,  ACM   Trans.  Program.  Lang.  Syst.,  28  (2006),  pp.  331–388.     Traits  Extensions   [1]  A.  BERGEL,  S.  DUCASSE,  O.  NIERSTRASZ,  AND  R.  WUYTS,  Stateful  Traits  and  their   Formaliza;on,  Journal  of  Computer  Languages,  Systems  and  Structures,  34   (2007),  pp.  83–108.   [4]  S.  DUCASSE,  R.  WUYTS,  A.  BERGEL,  AND  O.  NIERSTRASZ,  User-­‐Changeable  Visibility:   Resolving  Unan;cipated  Name  Clashes  in  Traits,  SIGPLAN  Not.,  42  (2007),   pp.  171–190.       15/12/10   Roundup  and  Conclusion     38  
  • 39. Traits  Literature   [1]A.  BERGEL,  S.  DUCASSE,  O.  NIERSTRASZ,  AND  R.  WUYTS,  Stateful  Traits  and  their     Formaliza;on,  Journal  of  Computer  Languages,  Systems  and  Structures,  34  (2007),   pp.  83–108.   [2]S.  DENIER,  Traits  Programming  with  AspectJ,  RSTI  -­‐  L'objet,  11  (2005),  pp.  69–86.     [3]S.  DUCASSE,  O.  NIERSTRASZ,  N.  SCHÄRLI,  R.  WUYTS,  AND  A.  P.  BLACK,  Traits:  A  Mechanism     for  Fine-­‐Grained  Reuse,  ACM  Trans.  Program.  Lang.  Syst.,  28  (2006),  pp.  331–388.   [4]S.  DUCASSE,  R.  WUYTS,  A.  BERGEL,  AND  O.  NIERSTRASZ,  User-­‐Changeable  Visibility:     Resolving  Unan;cipated  Name  Clashes  in  Traits,  SIGPLAN  Not.,  42  (2007),  pp.  171– 190.   [5]S.  MARR  AND  F.  MENGE,  ezcReflec;on,  SVN  Repository,  eZ  Components,  January     2008.  hOp://svn.ez.no/svn/ezcomponents/experimental/Reflec@on.   [6]E.  R.  MURPHY-­‐HILL,  P.  J.  QUITSLUND,  AND  A.  P.  BLACK,  Removing  Duplica;on  from     java.io:  a  Case  Study  using  Traits,  in  OOPSLA  '05:  Companion  to  the  20th  annual   ACM  SIGPLAN  conference  on  Object-­‐oriented  programming,  systems,  languages,   and  applica@ons,  New  York,  NY,  USA,  2005,  ACM,  pp.  282–291.   15/12/10   Roundup  and  Conclusion   39  
  • 40. Traits  Literature   [7]  PROGRAMMING  METHODS  LABORATORY,  Traits  for  Scala,  Programming   Language,  Ecole  Polytechnique  Fédérale  de  Lausanne,  2006.  hOp:// www.scala-­‐lang.org/intro/traits.html.   [8]  P.  J.  QUITSLUND,  E.  R.  MURPHY-­‐HILL,  AND  A.  P.  BLACK,  Suppor;ng  Java  traits  in   Eclipse,  in  eclipse  '04:  Proceedings  of  the  2004  OOPSLA  workshop  on   eclipse  technology  eXchange,  New  York,  NY,  USA,  2004,  ACM,  pp.  37–41.   [9]  S.  REICHHART,  Traits  in  C#.  Video  of  Talk  at  MicrosoR  Research,  September   2005.   [10]  N.  SCHÄRLI,  Traits  —  Composing  Classes  from  Behavioral  Building  Blocks,   PhD  thesis,  University  of  Berne,  Feb.  2005.   [11]  SOFTWARE  COMPOSITION  GROUP,  Traits  for  Squeak,  Smalltalk  VM,  University   of  Berne,  December  2006.  hOp://www.iam.unibe.ch/  scg/Research/ Traits/index.html.   [12]  L.  WALL,  Apocalypse  12:  Class  Composi;on  with  Roles,  tech.  report,  The   Perl  Founda@on,  2004.  hOp://www.perl.com/pub/a/2004/04/16/ a12.html?page=11.   15/12/10   Roundup  and  Conclusion   40