On Sat, Apr 9, 2016 at 3:56 AM, stepharo <steph...@free.fr> wrote: > new cheatsheet for Pharo syntax. > Any feedback is welcome
So I really went to town and picked the eyes out of it... > #(abc 123) > literal array with the symbol #abc and the number 123 This one surprised me. I had to test it to check it was true. It doesn't seem very consistent. Regardless of whether we *can* do it like that, it would be more intuitive to be #(123 #abc). But really, should we even allow it? > 12 2r1100 16rC > twelve (decimal, binary, hexadecimal) floating-point numbers The correspondence of the '2' of the '12 very close to the '2' of the '2r' is a bit awkward. Also I think we can take decimal numbers for granted and its easier for people to immediately identify A=10 rather than C=12, and lets not leave the meaning of 'r' implicit. So perhaps use.... 2r1010 16rA binary and hexadecimal radix of 10 > {foo . 3 + 2} Perhaps move the "declaration of two temporary variables" above this, so foo it properly introduce foo as a variable rather than leaving it implicit. Otherwise from the literal array example it might be inferred that foo is a symbol. Also, the "expression separator" should be introduced before it is used in the dynamic array. So perhaps the dynamic array (or all array) examples should be closer to the end. > A method is invoked by sending a message to an object, the message receiver; > the message returns an object. A message is an identifier for which objects provide methods of implementation. A method is invoked by sending a message to an object. The object is the /receiver/ of the message. The message returns an object. > Messages syntax mimics natural language Message syntax mimics natural language > Pharo: aColor r: 0.2 g: 0.3 b: 0 This is not very natural language. We only need one Java/Pharo example. Delete this one. > Array new You would never(?) really use that line. So lets not mislead a newcomer who might try it and get frustrated why they can't add items to it. OrderedCollection new is described later, so here perhaps instead use... 2 squared The receiver of the squared message is the object 2, with the object 4 returned. > A keyword message can take one or more arguments that are inserted in the message name. A keyword message can take one or more arguments that are interspersed through the message name. (Put the example of this first, i.e. #to:by: before #allButFirst: > Precedence Message Precedence > Parentheses > unary > binary > keyword, Is too concise. I know the answer but I still feel awkward decoding that line. Better... Message sending order of precedence is: parentheses, unary, binary, keyword, left to right. > (10 between: 1 and: 2 + 4 * 3) not Might be better to one more unary message... (10 between: 1 and: 2 + 4 * 3 negated) not The unary #negated message inside the parentheses is sent first, then #+ as the left most binary message, followed by #*. Then keyword message #between:and: is sent, and finally #not. > The rule suffers no exception: operators The rule suffers no exception. Operators > so 2 + 4 * 3 reads left-to-right and gives 18, not 14! so 2 + 4 * 3 reads left-to-right and gives 18, not 14! Note, comparison operators like equals = is just binary messages, so... 1 * 3 = 3 produces boolean object true but 3 = 3 * 1 produces an error, since a boolean object does not understand multiplication. Hint, while beginning with Pharo, make liberal us of parentheses in calculations to make precedence explicit and thus easy to observe. > OrderedCollection new > add: #abc; > add: #def; > add: #ghi. Rather than just mentioning needing to send #yourself in the text, show the pattern more explicitly by putting it in the example... OrderedCollection new add: #abc; add: #def; add: #ghi; yourself. The message new is sent to OrderedCollection which results in a new collection to which three add: messages are sent. The value of the whole message cascade is the value of the last message sent, so without #yourself this would be the symbol #ghi. With #yourself, the return value is {#abc. #def. #ghi} > Blocks are objects containing code that is executed on demand, > (anonymous functions). They are the basis for control structures > like conditionals and loops. Blocks are objects, that contain code to be executed on demand (anonymous functions). They defined by square brackets and are the basis for control structures like conditionals and loops. > 2 = 2 > ifTrue: [Error signal: ’Help’]. Lets not mix in additional concepts. How about... 2 = 2 ifTrue: [self inform: 'Equal'] > The first example sends the message ifTrue: to the boolean > true (computed from 2 = 2 ) with a block as argument. >From 2 = 2 comes the boolean object true, to which the #ifTrue: message is sent with the block as argument. The object true always evaluates #ifTrue: arguments, thus the text "Equal' displays on the screen. > As a result, Hello World! is printed. As a result, Hello World! is printed. in the Transcript window (which you from the World > Tools menu) > Pharo is a live programming environment: you can modify your > objects and your code while your program is executing. > • and much, much more! There doesn't seem much use in that line hanging on its lonesome at the top of a column > When a protocol name starts with a *, methods of this protocol belong to a > different package A protocol name starting with a * indicates methods belonging to a different package. > To add a package: first column + menu add package To add a package, right-click lower down in the Packages pane. (If they right-click near the top they wont get that option - something I find annoying) > To add a class, edit the proposed template! To add a class, select a package and edit the proposed template. (its not that exciting to need an exclamation mark :) > Counter new . > initialize > super initialize > count := 0 It looks like the first line is part of the rest of the code sample. Also this should be moved beneath the Methods subheading. > Methods are public and virtual. There are always looked up in Methods are public and virtual. They are always looked up in > Class methods follow the same dynamic lookup than instance Class methods follow the same dynamic lookup as instance cheers -ben