A few examples: Object>>perform: selector orSendTo: otherTarget "If I wish to intercept and handle selector myself, do it; else send it to otherTarget" ^ (self respondsTo: selector) ifTrue: [ self perform: selector ] ifFalse: [ otherTarget perform: selector ] Object>>doesNotUnderstand: aMessage "Handle the fact that there was an attempt to send the given message to the receiver but the receiver does not understand this message (typically sent from the machine when a message is sent to the receiver and no method is defined for that selector)." "Testing: (3 activeProcess)" "fixed suggested by Eliot miranda to make sure [Object new blah + 1]  on: MessageNotUnderstood  do: [:e | e resume: 1] does not loop indefinitively" | exception resumeValue | (exception := MessageNotUnderstood new) message: aMessage; receiver: self. resumeValue := exception signal. ^ exception reachedDefaultHandler ifTrue: [ aMessage sentTo: self ] ifFalse: [ resumeValue ] Below is an example that shows the placement of block brackets with multiline blocks. I would like to change that so that the brackets are placed on the line above (that's in my opinion the only major flaw in the automatic formatting), unfortunately I haven't found the time to do this: Object>>copyFrom: anotherObject "Copy to myself all instance variables I have in common with anotherObject. This is dangerous because it ignores an object's control over its own inst vars. " <primitive: 168> | mine his | mine := self class allInstVarNames. his := anotherObject class allInstVarNames. 1 to: (mine size min: his size) do: [ :ind | (mine at: ind) = (his at: ind) ifTrue: [ self instVarAt: ind put: (anotherObject instVarAt: ind) ] ]. self class isVariable & anotherObject class isVariable ifTrue: [ 1 to: (self basicSize min: anotherObject basicSize) do: [ :ind | self basicAt: ind put: (anotherObject basicAt: ind) ] ] Object>>longPrintStringLimitedTo: aLimitValue "Answer a String whose characters are a description of the receiver." | str | str := String streamContents: [ :aStream | self longPrintOn: aStream limitedTo: aLimitValue indent: 0 ]. "Objects without inst vars should return something" ^ str isEmpty ifTrue: [ self printString , String cr ] ifFalse: [ str ] On 28 February 2010 10:58, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
Lukas do you have some code samples. Something that I particularly hate is the following
    self bla ifTrue: [         ...
    ] ifFalse: [         ...     ]
That is see in the code.
I want     self bla         ifTrue: [ ...                     ]         ifFalse: [             ...       ]
I would use a formatter, like this you can make it really consistent. The RBConfigurableFormatter is pretty good in that, the only thing I don't like is the placing of the square brackets. I should look into fixing that, otherwise it formats exactly the way I would format myself (and in the way you propose).
I would really like to play with the idea of automatic formatting to see how it goes.
Stef
Lukas
On 28 February 2010 10:36, stephane ducasse <stephane.ducasse@free.fr> wrote:
Hi guys
I would like to build a set of canonical code formatting convention for Pharo. I need your help. Now take time before replying :) I would like to structure the discussion and proceed step by step. So at max I would like to discuss one or two formatting approach per mail. Once we agree I would like to define a wiki page.
**Space after : rule ============= for example I would like to always have a space after a :
classes := Smalltalk allClasses select:[:aClass| Â Â Â Â Â Â Â (aClass class includesSelector: #cleanUp) Â Â Â Â Â Â Â Â Â Â Â or:[aClass class includesSelector: #cleanUp:] Â Â Â ].
->
classes := Smalltalk allClasses select: [:aClass| Â Â Â Â Â Â Â (aClass class includesSelector: #cleanUp) Â Â Â Â Â Â Â Â Â Â Â or: [aClass class includesSelector: #cleanUp:] Â Â Â ].
**Block arg rule ============= Do we want a space before and after block arg
Smalltalk allClasses select: [:aClass :method|
-> Smalltalk allClasses select: [ :aClass :method |
** selector or block indented compared to receiver =======================================
Finally do we follow kent block ideas?
classes := Smalltalk allClasses select: [:aClass| Â Â Â Â Â Â Â (aClass class includesSelector: #cleanUp) Â Â Â Â Â Â Â Â Â Â Â or: [aClass class includesSelector: #cleanUp:] Â Â Â ].
-> classes := Smalltalk allClasses             select: [:aClass| (aClass class includesSelector: #cleanUp)                             or: [aClass class includesSelector: #cleanUp:]].
Stef _______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Lukas Renggli http://www.lukas-renggli.ch
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Lukas Renggli http://www.lukas-renggli.ch