Pharo, an innovative and open-source Smalltalk
Upcoming SlideShare
Loading in...5
×
 

Pharo, an innovative and open-source Smalltalk

on

  • 4,188 views

 

Statistics

Views

Total Views
4,188
Views on SlideShare
4,172
Embed Views
16

Actions

Likes
5
Downloads
72
Comments
1

2 Embeds 16

http://www.slideshare.net 15
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • As someone who used Smalltalk/V and VisualAge in the 1990s, I've been away from the language for too long. This presentation brings it all back. I'm sure it is equally useful for newcomers.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • Preferences setDemoFonts <br /> <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Pharo, an innovative and open-source Smalltalk Pharo, an innovative and open-source Smalltalk Presentation Transcript

  • A clean, innovative, open-source Smalltalk http://www.pharo-project.org/ Serge Stinckwich Serge.Stinckwich@esug.org
  • 1 Smalltalk Syntax 2 Smalltalk object model 3 Pharo, an open-source Smalltalk
  • 1 Smalltalk syntax
  • What are the keywords ? How do you build expressions ?
  • Almost no keywords
  • Syntax for litterals 1 -10 30 3.14156 1e-10 -1.4e4 $A $z ‘Hello World’ #(1 2 3 4 5)
  • “A comment is a sequence of characters surrounded by quotation marks.”
  • Assignement x := 3. y := ‘Hello world’. z := x+4.
  • 6 pseudo-variables nil, true, false self, super, thisContext
  • Everything happens by message sending
  • (1) Unary message
  • receiver message.
  • 20 factorial
  • 2432902008176640000
  • ‘Esope reste et se repose’ reversed
  • ‘esoper es te etser eposE’
  • ‘12345’ isAllDigits
  • true
  • ‘Quelle est ma longueur ?’ size
  • 23
  • ‘foobar’ first
  • $f
  • (2) Binary Messages
  • aReceiver aSelector anArgument
  • 3+4
  • 7
  • ‘Bonjour ’, ‘monde’
  • ‘Bonjour monde’
  • 2@3
  • 2@3
  • (3) Keywords Messages
  • 12 between: 8 and:15.
  • 8 < 12 < 15 ?
  • true
  • #(1 4 9 16 25) at: 3
  • 9
  • aString.substring(2, 5) aString copyFrom: 2 to: 5 ColorValue hue: a new ColorValue(a, b, c) saturation: b value: c DateAndTime year: a day: new DateAndTime(a, b, c) b timeZone: c Easier to document the semantic role of arguments with keywords messages.
  • (Msg) > Unary > Binary > Keywords
  • Messages cascading
  • myBirthday := Date new. myBirthDay setYear: 1967. myBirthDay setMonth: 5. myBirthDay setDayOfMonth: 10.
  • myBirthday := Date new; setYear: 1967; setMonth: 5; setDayOfMonth: 10.
  • The End
  • if ... then ... else ?
  • Weather today isRaining ifTrue: [self takeMyUmbrella] ifFalse: [self takeMySunglasses] ifTrue:ifFalse is sent to an objet: a boolean
  • Closures [3+4] [‘Bonjour’ size. 3+4. #(1 2 3 4) at:2]
  • A block (lexical closure) is a Smalltalk object, whose value could be evaluated in the future. A block is evaluated by sending the message value.
  • [1+2] value. ⇒ 3
  • Block could be parametrized [:param1 :param2 ... | statements]
  • [:x | x+1] value:2. [:x :y | x,y] value:’Bonjour’ value:’monde !’.
  • Dynamic binding Postponing selection of an operation until execution time aCondition ifTrue:[y:= 3] ifFalse:[y:= #(1 2 3)]. y printOn: someStream. Many printOn: methods, compiler can’t preordain the choice.
  • Dynamic binding enables polymorphism
  • Where is implemented ifTrue:ifFalse: ?
  • Where is implemented ifTrue:ifFalse: ? True>>ifTrue:aBlock1 ifFalse: aBlock2 ^aBlock1 value False>>ifTrue:aBlock1 ifFalse: aBlock2 ^aBlock2 value
  • Build your own control structure ! 7 ifSeven:[Object inform: ‘Its seven’] Number>>ifSeven:aBlock self=7 ifTrue:[^aBlock value]
  • Iterations
  • [Weather today isRaining] whileTrue:[self doNotGoOutside. self readAGoodBook]
  • Array | life | life := #(calvin hates suzie). life at:2 put:#loves. life. ⇒ #(#calvin #loves #suzie) life first. ⇒ #calvin life last. ⇒#suzie life indexOf:#calvin. ⇒ 1 life indexOf:#asterix ifAbsent:[Transcript show:’Je ne connais pas’].
  • Set s := Set new. s add:1. s add:2. s add:2. s. ⇒ a Set(1 2)
  • Interval -10 to:10. ⇒ (-10 to: 10) (-10 to:10) at:2. ⇒ -9 (-10 to:10) at:2 put:3. ⇒ erreur
  • OrderedCollection distributions := OrderedCollection new. distributions add:’Slackware’; add:’Fedora’; add:’Ubuntu’. distributions. ⇒ an OrderedCollection('Slackware' 'Fedora' 'Ubuntu') distributions remove:’Fedora’. distributions. ⇒ an OrderedCollection('Slackware' 'Ubuntu')
  • OrderedCollection distributions addFirst:’Debian’. distributions addLast:’RedHat’. distributions. ⇒ an OrderedCollection('Debian' 'Slackware' 'Ubuntu' 'RedHat') distributions add:’Mandriva’ afterIndex:2. distributions. ⇒ an OrderedCollection('Debian' 'Slackware' 'Mandriva' 'Ubuntu' 'RedHat')
  • Collection enumeration A collection contains a lot of elements. Enumerate a collection is browsing the collection and running a statement for each element: do:, select:, reject: collect:, inject:
  • Enumeration messages are polymorphic = they work whatever the collection is
  • do: Evaluate the block for each element of the collection. total := 0. a := #(1 2 3 4 5 6). a do:[:unElement |  total := total + unElement]
  • select: Evaluate the block for each element of the collection and return a collectiof the items of the same class containing elements whose evaluation return true. a := #(1 2 3 4 5 6). a select:[:unElement| unElement even] Return : #(2 4 6)
  • detect: Evaluate the block for each element of the collection and return the first element that evaluate as the block value as true. a := #(1 2 3 4 5 6). a detect:[:unElement |  unElement>3]. Return : 4.
  • 2 Smalltalk object model
  • Classe Rectangle Rectangle width height area ...
  • Object subclass: #Rectangle instanceVariableNames: 'width height' classVariableNames: '' poolDictionaries: '' category: 'Exemples-Heritage'
  • Rectangle>>width: w width := w Rectangle>>height: h height := h Rectangle>>width ^width Rectangle>>height ^height Rectangle>>area ^ width*height
  • Classe ColoredRectangle ColoredRectangle width height color area ...
  • A colored rectangle is like a rectangle but with a color ...
  • Operations that can be done a rectangle, can also be done on a colored rectangle (e.g surface calculus)
  • a ColoredRectangle isa Rectangle
  • Rectangle subclass: #ColoredRectangle instanceVariableNames: 'color' classVariableNames: '' poolDictionaries: '' category: 'Exemples-Heritage'
  • ColoredRectangle>>color ^color ColoredRectangle>>color: aColor color := aColor
  • Class inheritance Rectangle width height area ... ColoredRectangle color ...
  • a := Rectangle new. a width:10. a height:50. a width. ⇒ 10 a height. ⇒ 50 a area. ⇒ 500
  • b := ColoredRectangle new. b width:10. b height:50. b color: Color blue. b width. ⇒ 10 b height. ⇒ 50 b color. ⇒ Color blue b area. ⇒ 500
  • Rule 1 Everything is an object Rule 2 Every object is an instance of one class Rule 3 Every class has a super-class Rule 4 Everything happens by message sending
  • Classes are also objects ! 1 class⇒ SmallInteger 20 factorial class ⇒ LargePositiveInteger ‘Hello’ class ⇒ ByteString #(1 2 3) class ⇒ Array
  • Every class has a superclass Integer superclass ⇒ Integer Number superclass ⇒ Magnitude Magnitude superclass ⇒ Object
  • doesNotUnderstand:
  • If a class is an object, every class should be also an instance of a specific classe. Metaclasses !
  • Metaclasses hierarchy is parallel to class hierarchy
  • Every metaclasses is instance of Metaclass
  • The metaclass of Metaclass is an instance of Metaclass
  • How many classes in the system ? Object allSubclasses size
  • How many abstract methods in the system ? Object allSubclasses do: [:aClass| aClass methodDict keys select: [:aMethod | (aClass>>aMethod) isAbstract ]]
  • What is a dynamic language ? Dynamic typing: greater polymorphism Metaprogramming (metaclasses): allow language itself to be dynamically changed allow hooks into object life cycle and method calls Work with code as easily as data Closures Higher-order programming
  • Readability Shorter code is easier to read and maintain and refactor Need balance between cryptic and expressive
  • square ^self*self public int square(int x) { return x * x; }
  • button on: #mouseDown send: #value to: [Object inform: 'You clicked me']. button.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { (Button) view.setText(""You Clicked Me!") } });
  • 3 Pharo, an open-source Smalltalk
  • In a nutshell Pharo = language + IDE Pure object-oriented programming language (Smalltalk) Dynamically language and trait-based Open and flexible environment Used Monticello for versionning (Metacello planned for 1.1)
  • iPhone
  • Pharo class Browser
  • other Pharo tools
  • Polymorph UI Polymorph provides support for selectable UI themes in Morphic, extra widgets to support a consistent look&fell, a framework for easily creating UI in code. Standard UI in Pharo
  • Demo of Pharo Simple examples BlinkMorph example Skins support MultiMorph UI (UITheme examples)
  • Tests ! 9179 unit tests includes in Pharo 1.0 9144 passes 20 expected failures 15 failures 0 errors
  • Everybody can help Reporting bugs Confirming bugs Writing tests Writing examples Writing comments Simple contributing fixes Deep discussion...
  • Community Process FIX/ ENHANCEMENT Discussed on In PharoInbox or Discussed Changesets on Mailing- BUG list Described Described BUG Tracker Discussed on Other version Integrated Rejected
  • http://www.pharobyexample.org/ Pharo by example vol. 2 on preparation
  • Pharo Sprints May 2008 Bern (Switzerland) July 2009 Bern (Switzerland) October 2009 Lille (France) November 2009 Buenos Aires (Argentina)
  • Thanks Hans Beck Matthew Fulmer Hilaire Fernandes Julian Fitzell David J Pennell Alexandre Bergel Tudor Girba Joseph Pelrine Cédric Beler Sean Glazier Alain Plantec Torsten Bergmann Norbert Hartl Damien Pollet Matthias Berth Dale Henrichs Lukas Renggli Ralph Boland Reinout Heeck Jorge Ressia Noury Bouraqadi Eric Hochmeister Mike Roberts Brian Brown Keith Hodges Robert Rothwell Gwenael Casaccio Henrik Sperre Johansen David Rotlisberger Damien Cassou Pavel Krivanek Michael Rueger Nicolas Cellier Adrian Kuhn Bill Schwab Gary Chambers Adrian Lienhard Niko Schwarz Miguel Coba Andreas Leidig Igor Stasenko Gabriel Cotelli Mariano Martinez Peck Francois Stephany Carlos Crosetti Dave Mason Serge Stinckwich Cyrille Delaunay John McIntosh Mathieu Suen Simon Denier Johnaton Meichtry Lawrence Trutter Marcus Denker Eliot Miranda Andrew Tween Ramiro Diaz Trepat Hernan Morales Durand Martin von loewis Stéphane Ducasse Philipp Marshall Juan Vuletich Morales Durand Hernan Jannick Menanteau Steven Wirts Stephan Eggermont Yann Monclair Hernan Wilkinson Luc Fabresse Oscar Nierstrasz
  • Join Us! Creating good energy, software quality, learning and having fun http://pharo-project.org
  • Cộng đồng Smalltalk Việt Smalltalk-VN mailing-list : http://lists.squeakfoundation.org/ mailman/listinfo/smalltalk-vn Smalltalk flyer in vietnamese EToys in vietnamese
  • Occam's razor: "entities should not be multiplied beyond what is necessary" (entia non sunt multiplicanda praeter necessitatem) the simplest solution is usually the correct one.
  • Thank you for your attention. Cám ơn sự quan tâm của bạn.