self xxx ifTrue: [ self bla. self foo
I don't like this very much because equivalent messages are formatted differently (they are not aligned). Now when you introduce block parameters, which everybody so far (Kent's book included) has ignored, it suddenly makes more sense to leave the first row empty. self xxx ifTrue: [ :param | self nicely. self aligned. ] Also the examples in the book seem to be picked to fit the rectangle criteria: ifTrue: [ [self clearCaches. self recomputeAngle] ifTrue: [ [self at: each put: 0] they both fit into a rectangle with a reason quite nicely. But if I pick [:each | aShape sendCommandAt: each; to: self] or a block which is very top heavy (long methods at top, short at bottom) I can hardly consider the bottom bracket as corner of a rectangle. But why not add a new option to the formatter to fit your criteria? (Btw I would love to have what IDEs often have -- code preview next to it to which all the options are being applied as you select it.) Peter On Thu, Sep 3, 2015 at 11:01 AM, Yuriy Tymchuk <yuriy.tymchuk@me.com> wrote:
I also code in the same way as Svenâs example. For more advanced things, why not to have:
self xxx ifTrue: [ self bla. self foo
or
self xxx ifTrue: [ self bla. self foo
this are the interesting things to me. I guess I should read Kent Beck's formatting rules :) but one more thing that I like to have is
anObject a: param1; cascading: param2; message: param3; formatted: param4
Although there are some issues around it.
Uko
On 03 Sep 2015, at 07:29, Sven Van Caekenberghe <sven@stfx.eu> wrote:
And what happened to the plain normal (in my mind/experience) ?
self xxx ifTrue: [ self bla. self foo ].
I would say that is the most common one I've seen in the image. And it is how the old formatter worked.
On 03 Sep 2015, at 03:39, Eliot Miranda <eliot.miranda@gmail.com> wrote:
Hi Ben,
have you read Kent Beck's formatting rules? I wish we would adhere to these in our formatters. And I wish he would put the formatting rules in the public domain on the web (Kent?). He actually justifies the rules he chooses; they're not just personal preferences. And IMO they produce eleant, readable Smalltalk. I have to say your block formatting below is horrible. Blocks are blocks. [ & ] are /not/ the same as { & } in C. [...] define an *object*, not merely delimit syntax. As such any good Smalltalk format will emphasize the objectness of blocks. And IMNERHO that is to make them rectangles as in
self ifIWantedYouToWriteC ifTrue: [self useABloodyCCompiler. self useCCMinusPToMakeSenseOfTheDamageDoneByTheCPreProcessor]
On Wed, Sep 2, 2015 at 6:23 PM, Ben Coman <btc@openinworld.com> wrote: On Thu, Sep 3, 2015 at 2:28 AM, stepharo <stepharo@free.fr> wrote:
I do not really like all the formattings of kent. Because sometimes it just does not work. But this is why we ask franck (an interns to start to have a look).
For example I do not like
self xxx ifTrue: [ self bla self foo.
Agreed. Unneccessary waste of a line.
in the current default formatter. and I prefer
self xxx ifTrue: [ self bla. self foo But here the problem is that the self foo is not tab aligned because ifTrue: [
self xxx ifTrue: [ self bla. self foo So may be this one is a nice compromise
Not quite there. The "self bla" is still not actually vertically aligned.
I think that we should change some settings. In fact in alpha things are there to evolve until the release :)
I like... self xxx ifTrue: [ self bla. self foo. ].
for three reasons: * the first statement of the block is vertically aligned with the rest * vertical alignment of paired brackets makes visual matching *simple* * the vertical whitespace enforced by the closing bracket on its own visually groups blocks.
Now some people don't like the closing brace on its own because they prefer code density. So maybe this...
self xxx ifTrue: [ self bla. self foo. ] ifFalse: [ self baa. self moo. ].
But still I prefer...
self xxx ifTrue: [ self bla. self foo. ] ifFalse: [ self baa. self moo. ].
cheers -ben
-- _,,,^..^,,,_ best, Eliot