messages for java programmers
play

Messages for Java Programmers Damien Cassou, Stphane Ducasse and - PowerPoint PPT Presentation

Messages for Java Programmers Damien Cassou, Stphane Ducasse and Luc Fabresse W2S02 http://www.pharo.org Only Objects and Messages code in Pharo only manipulates objects: mouse, booleans, arrays, numbers, compressed, strings, windows,


  1. Messages for Java Programmers Damien Cassou, Stéphane Ducasse and Luc Fabresse W2S02 http://www.pharo.org

  2. Only Objects and Messages � code in Pharo only manipulates objects: mouse, booleans, arrays, numbers, compressed, strings, windows, scrollbars, canvas, files, trees, compiler, sound, url, socket, fonts, text, collections, stack, shortcut, streams, ... � messages and assignments are the only way to do something W2S02 2 / 17

  3. Equivalence In Java ArrayList<String> strings = new ArrayList<String>(); In Pharo strings := OrderedCollection new. � 1 assignment, 1 message sent � new is a message sent to a class � no static typing � no generics W2S02 3 / 17

  4. Equivalence In Java Thread regThread = new Thread( new Runnable() { @Override public void run() { this.doSomething(); } }); regThread.start(); In Pharo [ self doSomething ] fork W2S02 4 / 17

  5. Equivalence In Java 8 new Thread(() − > this.doSomething()).start(); In Pharo [ self doSomething ] fork W2S02 5 / 17

  6. Three Kinds of Messages � Unary 5 factorial Transcript cr � Binary 3 + 4 5 − > 10 � Keyword-based Transcript show: 'hello world' 2 between: 0 and: 5 W2S02 6 / 17

  7. Keyword Messages for Java developers In Java receiver.keyword1keyword2(arg1, arg2) In Pharo anObject keyword1: arg1 keyword2: arg2 W2S02 7 / 17

  8. Keyword Messages for Java developers In Java postman.send(mail,recipient); W2S02 8 / 17

  9. Keyword Messages for Java developers postman.send(mail,recipient); postman . send ( mail , recipient ); W2S02 9 / 17

  10. Keyword Messages for Java developers postman.send(mail,recipient); postman . send ( mail , recipient ); postman send mail recipient W2S02 10 / 17

  11. Keyword Messages for Java developers postman.send(mail,recipient); postman . send ( mail , recipient ); postman send mail recipient postman send mail to recipient W2S02 11 / 17

  12. Keyword Messages for Java developers postman.send(mail,recipient); postman . send ( mail , recipient ); postman send mail recipient postman send mail to recipient postman send: mail to: recipient W2S02 12 / 17

  13. Keyword Messages for Java developers In Java postman.send(mail,recipient); In Pharo postman send: mail to: recipient � the message ◦ is named send:to: ◦ is sent to postman ◦ includes two arguments ( mail and recipient ) W2S02 13 / 17

  14. Conditionals are Just Messages � in Java, if , else , for , while , do , ... are language keywords � in Pharo, conditional expressions are messages � booleans are objects fullName isEmpty ifTrue: [ 'FirstnameLastname' ] ifFalse: [ fullName ] W2S02 14 / 17

  15. Loops are Just Messages 4 timesRepeat: [ self doSomething ] 0 to: 100 do: [ :i | ... ] 0 to: 100 by: 3 do: [ :i | ... ] aCollection do: [ :each | ... ] W2S02 15 / 17

  16. Summary � Three kinds of messages: unary, binary and keywords � () > unary > binary > keywords � Conditionals are messages � Loops too W2S02 16 / 17

  17. A course by and in collaboration with Inria 2016 Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France https://creativecommons.org/licenses/by-nc-nd/3.0/fr/

Recommend


More recommend