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

messages for java programmers
SMART_READER_LITE
LIVE PREVIEW

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,


slide-1
SLIDE 1

Messages for Java Programmers

Damien Cassou, Stéphane Ducasse and Luc Fabresse

W2S02

http://www.pharo.org

slide-2
SLIDE 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

slide-3
SLIDE 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

slide-4
SLIDE 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

slide-5
SLIDE 5

Equivalence

In Java 8 new Thread(() −> this.doSomething()).start(); In Pharo [ self doSomething ] fork

W2S02 5 / 17

slide-6
SLIDE 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

slide-7
SLIDE 7

Keyword Messages for Java developers

In Java receiver.keyword1keyword2(arg1, arg2) In Pharo anObject keyword1: arg1 keyword2: arg2

W2S02 7 / 17

slide-8
SLIDE 8

Keyword Messages for Java developers

In Java postman.send(mail,recipient);

W2S02 8 / 17

slide-9
SLIDE 9

Keyword Messages for Java developers

postman.send(mail,recipient); postman . send ( mail , recipient );

W2S02 9 / 17

slide-10
SLIDE 10

Keyword Messages for Java developers

postman.send(mail,recipient); postman . send ( mail , recipient ); postman send mail recipient

W2S02 10 / 17

slide-11
SLIDE 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

slide-12
SLIDE 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

slide-13
SLIDE 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

slide-14
SLIDE 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

slide-15
SLIDE 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

slide-16
SLIDE 16

Summary

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

slide-17
SLIDE 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/