[squeak-dev] Formatting?

Levente Uzonyi leves at caesar.elte.hu
Thu Jun 2 15:19:36 UTC 2016

On Thu, 2 Jun 2016, Eliot Miranda wrote:

> Hi Tim,
>> On Jun 1, 2016, at 5:42 PM, tim Rowledge <tim at rowledge.org> wrote:
>> Now I *don’t* like this
>>>>     coll do:
>>>>           [ :each |
>>>>           statement1.
>>>>           (condition1) ifTrue: [ statement2 ] ]
>> At least if applied vigourously. When there are *short* statements I’d rather see
>>  coll do: [:each| statement]
>> or
>> coll do:[:each| (condition) ifTrue:[statement]]
>> etc, keeping as much as possible nicely compact.
> That's just what Kent's style guide recommends.  If the block fits comfortably on one line then by all means put it in one line.  The primary constraint is that the block braces form the top left and bottom right of a rectangle which contains all of the block's text.  So a one line block trivially satisfies that.  The main thing this precludes is attaching the opening brace to the end of an ifTrue:/ifFalse; far to the right of the start of the first line of the block;
>    braceAtTheEndOfLine ifTrue: [
>         (this isA: #Monstrosity) because:
>                blocks are objects not syntax].

This is absolutely personal preference, but I prefer to have blocks have
similar syntax as methods, because that makes it easier to read code.
This means that the first line, which contains the opening bracket and the 
argument names, is far less important than what the block does, so it's 
perfectly okay to leave it on the previous line.
The indentation tells where the block starts and ends.
What Chris did with the arguments, the additional spaces around variable 
names, is a step towards this, because that's exactly how you would write 
it, if it were a method.

And methods are objects as well; still you leave a tab at the beginning of 
each line, don't you? :)


>> I find pretty-print makes code far too ‘tall’ for my taste - oh and hardwrapping comments is really annoying!
> +1 & +1
>> tim
>> --
>> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
>> Useful random insult:- Only playing with 51 cards.

More information about the Squeak-dev mailing list