Re: [Pharo-dev] New book: Pharo with Style

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

Re: [Pharo-dev] New book: Pharo with Style

Pharo Smalltalk Users mailing list
On 2018-12-30 16:13, Stephane Ducasse wrote:

> Hello Fellow Pharoers
>
> I'm happy to announce a new little book to improve the culture around Pharo.
> I will revise it in the future so you can feel free to send feedback
> and pull requests
> to https://github.com/SquareBracketAssociates/Booklet-PharoWithStyle
>
> Stef
>
> "The best way to predict the future is to invent" so I do it.
Stéphane,

You'll find, attached, a revised PDF version with my comments.



--
-----------------
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamneth
Blogue: endormitoire.wordpress.com
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein)


bstj_revised_withStyle-wip.pdf (286K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] New book: Pharo with Style

Pharo Smalltalk Users mailing list
Besides, I forgot to add one comment : you should have guidelines for
protocol naming.  It's not critical per se but I find it quite annoying
to look for stuff in "enumerating" when it's been put in "printing" !  loll

On 2018-12-31 03:51, Stephane Ducasse wrote:

> Thanks! Thanks!
> I will go over it (now laying on my back :(( stupid muscles strike back!)
>
> On Mon, Dec 31, 2018 at 2:18 AM Benoit St-Jean <[hidden email]> wrote:
>> On 2018-12-30 16:13, Stephane Ducasse wrote:
>>> Hello Fellow Pharoers
>>>
>>> I'm happy to announce a new little book to improve the culture around Pharo.
>>> I will revise it in the future so you can feel free to send feedback
>>> and pull requests
>>> to https://github.com/SquareBracketAssociates/Booklet-PharoWithStyle
>>>
>>> Stef
>>>
>>> "The best way to predict the future is to invent" so I do it.
>> Stéphane,
>>
>> You'll find, attached, a revised PDF version with my comments.
>>
>>
>>
>> --
>> -----------------
>> Benoît St-Jean
>> Yahoo! Messenger: bstjean
>> Twitter: @BenLeChialeux
>> Pinterest: benoitstjean
>> Instagram: Chef_Benito
>> IRC: lamneth
>> Blogue: endormitoire.wordpress.com
>> "A standpoint is an intellectual horizon of radius zero".  (A. Einstein)
>>
--
-----------------
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamneth
Blogue: endormitoire.wordpress.com
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein)


Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] New book: Pharo with Style

Richard O'Keefe
On naming protocols: it would be nice to have clear guidance about
when to use '-ion' and when to use '-ing'.  In my own code I've been
using '-ing' except for a few traditional categories like
'instance creation'.  One reason for this was that I didn't want to
keep on re-deciding "is it 'enumerating' or 'enumeration'".

On Mon, 31 Dec 2018 at 22:04, Benoit St-Jean via Pharo-users <[hidden email]> wrote:
Besides, I forgot to add one comment : you should have guidelines for
protocol naming.  It's not critical per se but I find it quite annoying
to look for stuff in "enumerating" when it's been put in "printing" !  loll

On 2018-12-31 03:51, Stephane Ducasse wrote:
> Thanks! Thanks!
> I will go over it (now laying on my back :(( stupid muscles strike back!)
>
> On Mon, Dec 31, 2018 at 2:18 AM Benoit St-Jean <[hidden email]> wrote:
>> On 2018-12-30 16:13, Stephane Ducasse wrote:
>>> Hello Fellow Pharoers
>>>
>>> I'm happy to announce a new little book to improve the culture around Pharo.
>>> I will revise it in the future so you can feel free to send feedback
>>> and pull requests
>>> to https://github.com/SquareBracketAssociates/Booklet-PharoWithStyle
>>>
>>> Stef
>>>
>>> "The best way to predict the future is to invent" so I do it.
>> Stéphane,
>>
>> You'll find, attached, a revised PDF version with my comments.
>>
>>
>>
>> --
>> -----------------
>> Benoît St-Jean
>> Yahoo! Messenger: bstjean
>> Twitter: @BenLeChialeux
>> Pinterest: benoitstjean
>> Instagram: Chef_Benito
>> IRC: lamneth
>> Blogue: endormitoire.wordpress.com
>> "A standpoint is an intellectual horizon of radius zero".  (A. Einstein)
>>
--
-----------------
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamneth
Blogue: endormitoire.wordpress.com
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein)


Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] New book: Pharo with Style

Richard O'Keefe
I'm not sure that the advice on method comments is as good as it could be.
Consider Point >>
    setX: xValue setY: yValue 
x := xValue.
y := yValue

It is pretty obvious what this does, and if I'm reading chapter 4 correctly
the advice is that it doesn't need a comment.  But it does: why DOESN'T this
method check that xValue and yValue are numbers, something which is assumed
by practically every method on the instance side?  In short, why does
    (Point x: nil y: nil) r
fail when the point is USED instead of when the point is CREATED?
*Somewhere*, in the class comment, the class-side #x:y: method, or this
method, this ought to be explained.

In my own code, every class has an (instance-side) #invariant method which
I can call from the debugger.  Even if it is just ^super invariant, at least
that's explicit documentation.  I used to write comments, and then I realised
that code I could call was even better.  That's something useful to say about
comments too.

"Method comments should contain sufficient information for a user to know
exactly how to use the method, what the method does including any side ef-
fects, and what it answers without having to look at the source code."

This is advice that almost none of the code in Pharo follows.
What the method *does* and *answers* can be determined by reading the code;
in Smalltalk you are much more likely to have (decompiled) source code
without comments than comments without source code.  What the method is
*for* is the thing that you cannot see in the code.

To get an example, I did (String allSelectors atRandom), getting
#copyWithoutAll:.  That has only one definition, in Collection:
   copyWithoutAll: aCollection
"Answer a copy of the receiver that does not contain any elements 
equal to those in aCollection."

^ self reject: [:each | aCollection includes: each]

The comment simply paraphrases the rather simple code.
It does NOT explain how to use the method:  when (if ever) is it better
to pass a set than a string?  Above all, why is it a good idea for
aCollection to be in charge of which elements of the receiver count as
equal to something in aCollection instead of the receiver being in
charge?  Consider
    |c a|
    c := IdentitySet with: 0.0.
    a := Array with: c anyOne * 1.0.
    { c copyWithoutAll: a. a copyWithoutAll: c }
Why does the >Identity<Set use #= for the decision while the Array
uses #==?  Why is the code not

    ^self select: [:it |
       aCollection noneSatisfy: [:each | it = each]]

?  It is the code that is NOT there that needs explaining most.

I am not blaming the Pharo team here.  They have other maddened grizzly bears
to stun, and did not invent this particular method.  Just by sheer dumb luck,
the random number generator turned up a method that has always annoyed me for
obviously but inexplicably doing something seriously weird.

Oh, there's another important thing about that particular comment.
It is wrong.  It refers to "elements equal to", which leads the reader
to assume that the same notion of equality in every case.  It should read
something like

    "Answer a copy of the receiver that does not contain any element
     equivalent to an element of aCollection, with equivalence defined
     by aCollection and NOT by the receiver."
 
There should be some advice about wrong or misleading comments being worse
than none.

PS: Benoit St-Jean did not catch all the typos.

On Tue, 1 Jan 2019 at 16:22, Richard O'Keefe <[hidden email]> wrote:
On naming protocols: it would be nice to have clear guidance about
when to use '-ion' and when to use '-ing'.  In my own code I've been
using '-ing' except for a few traditional categories like
'instance creation'.  One reason for this was that I didn't want to
keep on re-deciding "is it 'enumerating' or 'enumeration'".

On Mon, 31 Dec 2018 at 22:04, Benoit St-Jean via Pharo-users <[hidden email]> wrote:
Besides, I forgot to add one comment : you should have guidelines for
protocol naming.  It's not critical per se but I find it quite annoying
to look for stuff in "enumerating" when it's been put in "printing" !  loll

On 2018-12-31 03:51, Stephane Ducasse wrote:
> Thanks! Thanks!
> I will go over it (now laying on my back :(( stupid muscles strike back!)
>
> On Mon, Dec 31, 2018 at 2:18 AM Benoit St-Jean <[hidden email]> wrote:
>> On 2018-12-30 16:13, Stephane Ducasse wrote:
>>> Hello Fellow Pharoers
>>>
>>> I'm happy to announce a new little book to improve the culture around Pharo.
>>> I will revise it in the future so you can feel free to send feedback
>>> and pull requests
>>> to https://github.com/SquareBracketAssociates/Booklet-PharoWithStyle
>>>
>>> Stef
>>>
>>> "The best way to predict the future is to invent" so I do it.
>> Stéphane,
>>
>> You'll find, attached, a revised PDF version with my comments.
>>
>>
>>
>> --
>> -----------------
>> Benoît St-Jean
>> Yahoo! Messenger: bstjean
>> Twitter: @BenLeChialeux
>> Pinterest: benoitstjean
>> Instagram: Chef_Benito
>> IRC: lamneth
>> Blogue: endormitoire.wordpress.com
>> "A standpoint is an intellectual horizon of radius zero".  (A. Einstein)
>>
--
-----------------
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamneth
Blogue: endormitoire.wordpress.com
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein)


Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] New book: Pharo with Style

Pharo Smalltalk Users mailing list
Hi Richard,

On Tue, 1 Jan 2019 at 07:26, Richard O'Keefe <[hidden email]> wrote:

>
> ...
>
> To get an example, I did (String allSelectors atRandom), getting
> #copyWithoutAll:.  That has only one definition, in Collection:
>    copyWithoutAll: aCollection
> "Answer a copy of the receiver that does not contain any elements
> equal to those in aCollection."
>
> ^ self reject: [:each | aCollection includes: each]
>
> The comment simply paraphrases the rather simple code.

I agree with pretty much everything you've written, but have a
slightly different view here.

Including what the method does, even when the code is fairly simple
(OK, not getter / setter methods), is still useful.  If the comment is
absent, I have to look at the code, figure out what it does, and then
either figure out if that's what it is supposed to do, or just assume
that I'm correct.  Having to figure out whether I've interpreted the
code correctly just increases the cognitive load.  If the comment
includes what it is supposed to do, I have a context in which to read
and evaluate the code, and it becomes much less effort.

Cheers,
Alistair

Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] New book: Pharo with Style

Pharo Smalltalk Users mailing list
In reply to this post by Pharo Smalltalk Users mailing list
I’ve always felt the XP book nailed it - don’t use comments as a crutch to avoid fixing confusing code and don’t do work twice by simply writing a comment that says the same as the code. (You can of course try to write the comment and auto-generate the code, but we’ve tried that before).

Smalltalk is an expressive language that should read like comments naturally - both with the name of a method, the variables and the statements in it.

This leaves comments as a good place to tell a story about the wider context and where to look to get started or learn more. I think this is possibly where Documentor is going to help you navigate along the real code.

Of course if after all of this you can’t figure out how to fix the code - then a comment is a good last resort.

Tim
Sent from my iPhone

> On 1 Jan 2019, at 12:43, Alistair Grant <[hidden email]> wrote:
>
> Hi Richard,
>
>> On Tue, 1 Jan 2019 at 07:26, Richard O'Keefe <[hidden email]> wrote:
>>
>> ...
>>
>> To get an example, I did (String allSelectors atRandom), getting
>> #copyWithoutAll:.  That has only one definition, in Collection:
>>   copyWithoutAll: aCollection
>> "Answer a copy of the receiver that does not contain any elements
>> equal to those in aCollection."
>>
>> ^ self reject: [:each | aCollection includes: each]
>>
>> The comment simply paraphrases the rather simple code.
>
> I agree with pretty much everything you've written, but have a
> slightly different view here.
>
> Including what the method does, even when the code is fairly simple
> (OK, not getter / setter methods), is still useful.  If the comment is
> absent, I have to look at the code, figure out what it does, and then
> either figure out if that's what it is supposed to do, or just assume
> that I'm correct.  Having to figure out whether I've interpreted the
> code correctly just increases the cognitive load.  If the comment
> includes what it is supposed to do, I have a context in which to read
> and evaluate the code, and it becomes much less effort.
>
> Cheers,
> Alistair
>


Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] New book: Pharo with Style

Pharo Smalltalk Users mailing list
In reply to this post by Pharo Smalltalk Users mailing list
That is a useful contribution, thank you (again) for your efforts !

> On 30 Dec 2018, at 22:13, Stephane Ducasse <[hidden email]> wrote:
>
> Hello Fellow Pharoers
>
> I'm happy to announce a new little book to improve the culture around Pharo.
> I will revise it in the future so you can feel free to send feedback
> and pull requests
> to https://github.com/SquareBracketAssociates/Booklet-PharoWithStyle
>
> Stef
>
> "The best way to predict the future is to invent" so I do it.
> <withstylebook.pdf>


Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] New book: Pharo with Style

Pharo Smalltalk Users mailing list
In reply to this post by Pharo Smalltalk Users mailing list
Nice work.

Doru



> On Dec 30, 2018, at 10:13 PM, Stephane Ducasse <[hidden email]> wrote:
>
> Hello Fellow Pharoers
>
> I'm happy to announce a new little book to improve the culture around Pharo.
> I will revise it in the future so you can feel free to send feedback
> and pull requests
> to https://github.com/SquareBracketAssociates/Booklet-PharoWithStyle
>
> Stef
>
> "The best way to predict the future is to invent" so I do it.
> <withstylebook.pdf>

--
www.feenk.com

"To utilize feedback, you first have to acquire it."