indenting code

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

indenting code

NorbertHartl
Hi,

I'm asking myself if there is any common sense about
how to indent the code in smalltalk/squeak.

Most of the time I see something like

statement do: [ :parameter |
   otherStatement selector: [
        mostinnerstatement ] ].

or

statement do: [ :parameter | otherStatement ].

Is this indenting common? Is the difference between those
two above depending on the length of the line? If it is,
how long are lines supposed to be? etc.

Any hints or links are appreciated.

thanks,

Norbert

 

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: indenting code

Herbert König
Hello Norbert,


NH> I'm asking myself if there is any common sense about
NH> how to indent the code in smalltalk/squeak.

there also must be some common sense about it but in my case lazyness
rules.

I type without thinking about indentation and let the pretty printer
take care that every method is formatted the same.
(context menu in the code pane, more, pretty print, *after* accepting
changes)

Sometimes I don't like the output but I dislike even more to do it
manually or to change the pretty printer. What I do manually is insert
blank lines between code phrases. This more in Lisp than in Squeak.

I believe that a consistent look is more important than an optimal
look.


Cheers,

Herbert                            mailto:[hidden email]

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: indenting code

Göran Krampe
Hi!

> Hello Norbert,
>
> NH> I'm asking myself if there is any common sense about
> NH> how to indent the code in smalltalk/squeak.
>
> there also must be some common sense about it but in my case lazyness
> rules.
>
> I type without thinking about indentation and let the pretty printer
> take care that every method is formatted the same.
> (context menu in the code pane, more, pretty print, *after* accepting
> changes)

I actually never use the pretty printer even though I definitely
understand those who use it like Herbert described. This is of course
highly individual, but I tend to "care" too much :) (I wish I wouldn't
because I am probably wasting time doing manual formatting) about how my
code is formatted and don't like the results from the current pretty
printers.

I also can not claim any clear rules - I do it differently depending on
lots of factors - the example mentioned could be formatted differently
depending on length of statements and length of selectors/number of
keywords.

If we had a much smarter pretty printer I might perhaps use it.

regards, Göran

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: indenting code

Benjamin Schroeder-2
In reply to this post by NorbertHartl
Hi Norbert,

> Hi,
>
> I'm asking myself if there is any common sense about
> how to indent the code in smalltalk/squeak.
>
> Most of the time I see something like
>
> statement do: [ :parameter |
>    otherStatement selector: [
> mostinnerstatement ] ].
>
> or
>
> statement do: [ :parameter | otherStatement ].

Kent Beck's "Smalltalk Best Practice Patterns" has a good section on  
this. He presents ten simple patterns to drive the formatting of  
Smalltalk code.

The book is a bit older now - it dates from 1997 - but might not be  
too hard to find. I think our local library system (here in Columbus,  
OH) even had a copy.

Beck's Indented Control Flow pattern says,

        Put zero or one argument messages on the same lines as their receiver.
        For messages with two or more keywords put each keyword/argument
        pair on its own line, indented one tab.

So, you would say

        limit := myList size.

or

        larger := firstCount max: secondCount.

but

        inRange := amount
                between: low
                and: high.

He also has patterns that describe how to format conditionals,  
blocks, etc. The rest of the book is good too - it has advice about  
other parts of Smalltalk usage.

As others have said, of course the most important thing is to pick a  
style that works well and use it consistently. I like Beck's style,  
but as you have seen, there are other good ones in use.

Benjamin Schroeder

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: indenting code

NorbertHartl
On Wed, 2006-12-13 at 09:09 -0500, Benjamin Schroeder wrote:

> Hi Norbert,
>
> > Hi,
> >
> > I'm asking myself if there is any common sense about
> > how to indent the code in smalltalk/squeak.
> >
> > Most of the time I see something like
> >
> > statement do: [ :parameter |
> >    otherStatement selector: [
> > mostinnerstatement ] ].
> >
> > or
> >
> > statement do: [ :parameter | otherStatement ].
>
> Kent Beck's "Smalltalk Best Practice Patterns" has a good section on  
> this. He presents ten simple patterns to drive the formatting of  
> Smalltalk code.
>
Ok, that is nice. I have this book for several years now :)
Thank you for pointing this out. As I have some
experience in smalltalk now it is maybe a good time to
read it again.

thanks,

Norbert

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: indenting code

Frank Caggiano
Also take a look at Smalltalk with Style.  Stéphane Ducasse has it  
available at http://www.iam.unibe.ch/~ducasse/FreeBooks.html

------------------------
Frank Caggiano
[hidden email]
http://www.crystal-objects.com

The best education for the best is the best education for all.
                     Robert Maynard Hutchins


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: indenting code

stephane ducasse
In reply to this post by NorbertHartl
You can find some hints in the book of kent Beck
Best smalltalk practices.

He stresses the idea to have recognizable block.
I like the following.
Damien Pollet did Gutenberg a new pretty printer for squeak.
Giving him feedback is the best way to see it improved.

fooMethod
        "my comment"

        (self foo) ifTrue: [ self bar ]

barMethod
        "my comment"

        (self foo)
                ifTrue: [ self bar.
                           self grumbleAtBit.
                           self done ]
                ifFalse: []

...
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners