Pharo source code formatting guide

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

Pharo source code formatting guide

NorbertHartl
Sometimes I wonder when I change a piece of code in pharo if there is an official formatting guide line. Is the formatter in calypso the incarnation of it or how code is supposed to be formatted in the offical image?

I just see tons of occurrences where caret immediately follows a token and such which I don’t like at all.

Norbert


Reply | Threaded
Open this post in threaded view
|

Re: Pharo source code formatting guide

EstebanLM
Hi,

> On 5 Jul 2019, at 08:57, Norbert Hartl <[hidden email]> wrote:
>
> Sometimes I wonder when I change a piece of code in pharo if there is an official formatting guide line. Is the formatter in calypso the incarnation of it or how code is supposed to be formatted in the offical image?

We need a code style guide, yes.
But no, definitively the code formatter available should not be the canonical formatting (since its ugly and some times even illegible).

Esteban

>
> I just see tons of occurrences where caret immediately follows a token and such which I don’t like at all.
>
> Norbert
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Pharo source code formatting guide

ducasse


> On 5 Jul 2019, at 17:09, Esteban Lorenzano <[hidden email]> wrote:
>
> Hi,
>
>> On 5 Jul 2019, at 08:57, Norbert Hartl <[hidden email]> wrote:
>>
>> Sometimes I wonder when I change a piece of code in pharo if there is an official formatting guide line. Is the formatter in calypso the incarnation of it or how code is supposed to be formatted in the offical image?

We are working on an enh of the formatter.
        - more tests (it was easy there was only one)
        - cleaning the settings/describing the settings
        - the goal is to be able to reformat all the code of the image

Now in Pharo by example I have some examples.

> We need a code style guide, yes.
> But no, definitively the code formatter available should not be the canonical formatting (since its ugly and some times even illegible).
>
> Esteban
>
>>
>> I just see tons of occurrences where caret immediately follows a token and such which I don’t like at all.
>>
>> Norbert
>>
>>
>
>



Reply | Threaded
Open this post in threaded view
|

Re: Pharo source code formatting guide

Eliot Miranda-2
In reply to this post by NorbertHartl


On Thu, Jul 4, 2019 at 11:58 PM Norbert Hartl <[hidden email]> wrote:
Sometimes I wonder when I change a piece of code in pharo if there is an official formatting guide line. Is the formatter in calypso the incarnation of it or how code is supposed to be formatted in the offical image?

I just see tons of occurrences where caret immediately follows a token and such which I don’t like at all.

There are many styles, many opinions.  Kent Beck presents a well argued set of rules that work for visual thinkers like me; the main thing I like is rectangular blocks. 


As Kent says

"The priorities of these patterns are:
1. To make the gross structure of the method apparent at a glance. Complex messages and blocks, in particular, should jump out at the reader.

2. To preserve vertical space. There is a huge difference between reading a method that fits into the text pane of a browser and reading one that forces you to scroll. Keeping methods compact vertically lets you have smaller browsers and still be able to read methods without scrolling. This reduces window management overhead and leaves more screen space for other programming tools."

_,,,^..^,,,_
best, Eliot
Reply | Threaded
Open this post in threaded view
|

Re: Pharo source code formatting guide

Chris Muller-3
I think of Beck's Rectangular Block as like a textual representation of Scratch tiles.  It's about presenting the code-structure, rather than aligning text on tabs.

However, I do think his Indented Control Flow actually preserves _horizontal_ space at the expense of vertical space.  I've found myself eschewing that particular pattern more and more in my last couple of years of coding.  Spreading (1 to: 10) across two lines seems kinda crazy.

But that book is a must-read for newcomers interested in writing quality Smalltalk, IMO.  Not even for the formatting chapter, but the other ones which teach the "shoulds" and "should nots" that may not be obvious to a student, like avoiding different super send.

 - Chris
 

On Thu, Jul 4, 2019 at 11:58 PM Norbert Hartl <[hidden email]> wrote:
Sometimes I wonder when I change a piece of code in pharo if there is an official formatting guide line. Is the formatter in calypso the incarnation of it or how code is supposed to be formatted in the offical image?

I just see tons of occurrences where caret immediately follows a token and such which I don’t like at all.

There are many styles, many opinions.  Kent Beck presents a well argued set of rules that work for visual thinkers like me; the main thing I like is rectangular blocks. 


As Kent says

"The priorities of these patterns are:
1. To make the gross structure of the method apparent at a glance. Complex messages and blocks, in particular, should jump out at the reader.

2. To preserve vertical space. There is a huge difference between reading a method that fits into the text pane of a browser and reading one that forces you to scroll. Keeping methods compact vertically lets you have smaller browsers and still be able to read methods without scrolling. This reduces window management overhead and leaves more screen space for other programming tools."

_,,,^..^,,,_
best, Eliot