[squeak-dev] Coding style
leves at elte.hu
Wed Mar 10 12:47:27 UTC 2010
On Wed, 10 Mar 2010, Bert Freudenberg wrote:
> On 10.03.2010, at 02:53, commits at source.squeak.org wrote:
>> + ^packageList ifNil:[packageList := (PackageInfo allPackages collect: [ :each | each packageName]) sort]!
>> - ^packageList ifNil:[packageList := (MCWorkingCopy allManagers collect:[:each| each packageName]) sort]!
> This to me replaces one style of too few spaces with another of too many ;)
> I'd have written
> collect: [:each | each packageName]
> but I just looked at the Blue Book and there indeed is a space before and after a block argument. OTOH it does conform to Kent's examples:
I try not to change the formatting of methods written by others to my
taste, but there are times when I just can't stop myself. This one liner
is half baked though...
If this was written by me entirely it would look like something like this:
^packageList ifNil: [
packageList := (PackageInfo allPackages collect: [ :each |
each packageName ]) sort ]
I used to add a space before and after all [ and ].
> Generally I feel this is not much of a problem. But I have occasionally seen rather strange formatting, So for the benefit of better readability, do we want to have general rules for formatting code?
> Many projects have such rules. One good example IMHO is PEP-8 in the Python community.
> For Smalltalk I only know Kent Beck's rules from "Best Practice Patterns" which seem like a good set. And IMHO any rules are better than none, so maybe we want to just agree that if in doubt, follow that suggested practice?
If someone has his/her own code formatting rules, he/she will hardly
change to another. I find my rules (which are mostly based on this book:
) very readable, especially with shout which colorizes the brackets too.
Therefore I'm against of forcing a single code formatting. I personally
dislike Kent's "rectangular block" idea.
I found this more readable
do: [ :each |
nextPut: $) ]
You can notice the rectangular shape in both examples.
I think the best would be a highly customizable pretty printer which would
allow anyone to read all methods formatted in the way he/she prefers.
> - Bert - (hoping this does not open a can of worms ...)
More information about the Squeak-dev