block brace alignment (Re: feedback from J Brant)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

block brace alignment (Re: feedback from J Brant)

Ben Coman
On Thu, Sep 3, 2015 at 2:28 AM, stepharo <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|

Re: block brace alignment (Re: feedback from J Brant)

Eliot Miranda-2
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 <[hidden email]> wrote:
On Thu, Sep 3, 2015 at 2:28 AM, stepharo <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: block brace alignment (Re: feedback from J Brant)

Sven Van Caekenberghe-2
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 <[hidden email]> 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 <[hidden email]> wrote:
> On Thu, Sep 3, 2015 at 2:28 AM, stepharo <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

Re: block brace alignment (Re: feedback from J Brant)

Peter Uhnak
I like...
    self xxx
        ifTrue:
        [    self bla.
             self foo.
        ].

Check the settings. It's called "align brackets" I think.

 He actually justifies the rules he chooses; they're not just personal preferences.

This is thin ice. The justifications can still be based on personal preferences. Imagine tabs vs spaces flame wars, where both side do have valid arguments and you pick side based on what is more important to you.
Now with the new Rubric and BlueInk you can automatically have methods formatted for you, so it doesn't matter as much what other people use. But generally agreement is a good thing.

And what happened to the plain normal (in my mind/experience) ?
self xxx
    ifTrue: [
        self bla.
        self foo ].

And there is settings for that also.

Peter


On Thu, Sep 3, 2015 at 7:29 AM, Sven Van Caekenberghe <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
> On Thu, Sep 3, 2015 at 2:28 AM, stepharo <[hidden email]> 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



Reply | Threaded
Open this post in threaded view
|

Re: block brace alignment (Re: feedback from J Brant)

Uko2
In reply to this post by Sven Van Caekenberghe-2
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
On Thu, Sep 3, 2015 at 2:28 AM, stepharo <[hidden email]> 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



Reply | Threaded
Open this post in threaded view
|

Re: block brace alignment (Re: feedback from J Brant)

Peter Uhnak
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
On Thu, Sep 3, 2015 at 2:28 AM, stepharo <[hidden email]> 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