[Pharo-project] about code formatting in pharo

Igor Stasenko siguctua at gmail.com
Sun Feb 28 06:47:55 EST 2010


On 28 February 2010 12:44, Stéphane Ducasse <stephane.ducasse at inria.fr> wrote:
> But, if there is only single block, i usually typing:
>
> self bla ifTrue: [
>   code.
>   code.
>  ]
>
> Yes I see
> I would prefer
>
> self bla ifTrue: [
>   code.
>   code. ]
>
>
> for me I try
>
>> self bla ifTrue: [ code ].
>
yes, one-liner is ok, but only if its short.

The most disguising thing in formatting an exception handling code:

runTest: aSelector

	| actualResult expectedResult |
	[ self
		logTest: aSelector;
		clearLog;
		perform: aSelector ]
			on: MyTestError do:
				[ :ex | self log: 'Unhandled Exception'.
					ex return: nil ].

as you can see, its a bit hard to quickly determine, where ends one
block and starts another one.
That's why i'm always putting ' ] ' at the next line, and align its
indentation to be the same as in opening brace:

	[ self
		logTest: aSelector;
		clearLog;
		perform: aSelector
	]
	on: MyTestError do:
		[ :ex | self log: 'Unhandled Exception'.
			ex return: nil
		].

do you agree that this one is much more readable?

>
> or
> self bla
>        ifTrue: [ code.
>                   code.]
>
> but I'm not happy because tabbing does not work to align the last line.
> So any ideas. I have to reread the kent book.
>
> Stef
>
>> also i'm usually putting closing ' ] ' at new line, but indented
>> relatively to receiver, not like:
>>
>>
>> self bla ifTrue: [
>>    code.
>>    code. ]
>>
>>
>> Also, if statement ends with ']' , i adding a blank like at the end:
>>
>>
>> self bla ifTrue: [
>>    code.
>>   ].
>>
>> self bla ifTrue: [
>>    code.
>>   ].
>>
>>
>>>
>>>> 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 at 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 at 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 at lists.gforge.inria.fr
>>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> Pharo-project at lists.gforge.inria.fr
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>
>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>> _______________________________________________
>> Pharo-project mailing list
>> Pharo-project at lists.gforge.inria.fr
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> Pharo-project at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



-- 
Best regards,
Igor Stasenko AKA sig.




More information about the Pharo-dev mailing list