Good practicces! Looking for examples

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

Good practicces! Looking for examples

Stéphane Ducasse
Hi guys

talking with sven during the last sprint we realized that it would be good to collect and document some good practices.
So I started a chapter for PBE2 on coding practices.

I will take the some of the optimization that sven did in time/date printOn: as a start

If you have some suggestions with examples I could integrate to the chapter.


Stef



Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

abergel
Not sure what you mean with good coding practice, but here my contrib:

- the command pattern (e.g., OB, Mondrian Easel, MonticelloBrowser)
- symbol polymorphic to block and other object-as-function
- writing test before fixing code
- having short methods

Alexandre


On 24 Dec 2011, at 10:53, Stéphane Ducasse wrote:

> Hi guys
>
> talking with sven during the last sprint we realized that it would be good to collect and document some good practices.
> So I started a chapter for PBE2 on coding practices.
>
> I will take the some of the optimization that sven did in time/date printOn: as a start
>
> If you have some suggestions with examples I could integrate to the chapter.
>
>
> Stef
>
>
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.






Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Stéphane Ducasse

On Dec 24, 2011, at 3:07 PM, Alexandre Bergel wrote:

> Not sure what you mean with good coding practice, but here my contrib:
>
> - the command pattern (e.g., OB, Mondrian Easel, MonticelloBrowser)
> - symbol polymorphic to block and other object-as-function

Not sure that this is a good practices. I think that you like them because you use Smalltalk as a DSL.

> - writing test before fixing code
> - having short methods
indeed

Here is what I started to write.


GoodPractices.pdf (136K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Nicolas Cellier
Bad practices and anti-pattern might be very instructive too...

Nicolas

2011/12/24 Stéphane Ducasse <[hidden email]>:

>
> On Dec 24, 2011, at 3:07 PM, Alexandre Bergel wrote:
>
>> Not sure what you mean with good coding practice, but here my contrib:
>>
>> - the command pattern (e.g., OB, Mondrian Easel, MonticelloBrowser)
>> - symbol polymorphic to block and other object-as-function
>
> Not sure that this is a good practices. I think that you like them because you use Smalltalk as a DSL.
>
>> - writing test before fixing code
>> - having short methods
> indeed
>
> Here is what I started to write.
>

Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Stéphane Ducasse
Yes this is what I wrote in the 4 pages so far :)

Stef

On Dec 24, 2011, at 4:18 PM, Nicolas Cellier wrote:

> Bad practices and anti-pattern might be very instructive too...
>
> Nicolas
>
> 2011/12/24 Stéphane Ducasse <[hidden email]>:
>>
>> On Dec 24, 2011, at 3:07 PM, Alexandre Bergel wrote:
>>
>>> Not sure what you mean with good coding practice, but here my contrib:
>>>
>>> - the command pattern (e.g., OB, Mondrian Easel, MonticelloBrowser)
>>> - symbol polymorphic to block and other object-as-function
>>
>> Not sure that this is a good practices. I think that you like them because you use Smalltalk as a DSL.
>>
>>> - writing test before fixing code
>>> - having short methods
>> indeed
>>
>> Here is what I started to write.
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Nicolas Cellier
In reply to this post by Nicolas Cellier
Oh, but I didn't understand it was about optimization...
Good practice is to not optimize prematurely ;)

For example, inlining some message send, replacing explicit iteration
message by more obscure to:do: or whileTrue: loops etc... are not good
practices, just compromises...

Nicolas

2011/12/24 Nicolas Cellier <[hidden email]>:

> Bad practices and anti-pattern might be very instructive too...
>
> Nicolas
>
> 2011/12/24 Stéphane Ducasse <[hidden email]>:
>>
>> On Dec 24, 2011, at 3:07 PM, Alexandre Bergel wrote:
>>
>>> Not sure what you mean with good coding practice, but here my contrib:
>>>
>>> - the command pattern (e.g., OB, Mondrian Easel, MonticelloBrowser)
>>> - symbol polymorphic to block and other object-as-function
>>
>> Not sure that this is a good practices. I think that you like them because you use Smalltalk as a DSL.
>>
>>> - writing test before fixing code
>>> - having short methods
>> indeed
>>
>> Here is what I started to write.
>>

Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Stéphane Ducasse

On Dec 24, 2011, at 4:28 PM, Nicolas Cellier wrote:

> Oh, but I didn't understand it was about optimization...
> Good practice is to not optimize prematurely ;)

Not only but I started to collect what I have

> For example, inlining some message send, replacing explicit iteration
> message by more obscure to:do: or whileTrue: loops etc... are not good
> practices, just compromises…

Indeed :)
I would like something more in the vein of Smalltalk by Example


Stef

>
> Nicolas
>
> 2011/12/24 Nicolas Cellier <[hidden email]>:
>> Bad practices and anti-pattern might be very instructive too...
>>
>> Nicolas
>>
>> 2011/12/24 Stéphane Ducasse <[hidden email]>:
>>>
>>> On Dec 24, 2011, at 3:07 PM, Alexandre Bergel wrote:
>>>
>>>> Not sure what you mean with good coding practice, but here my contrib:
>>>>
>>>> - the command pattern (e.g., OB, Mondrian Easel, MonticelloBrowser)
>>>> - symbol polymorphic to block and other object-as-function
>>>
>>> Not sure that this is a good practices. I think that you like them because you use Smalltalk as a DSL.
>>>
>>>> - writing test before fixing code
>>>> - having short methods
>>> indeed
>>>
>>> Here is what I started to write.
>>>
>


Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Schwab,Wilhelm K
In reply to this post by Stéphane Ducasse
Stef,

My current working theory is that the command pattern is indeed good practice; it also has a way of exacting a price for the flexibility.

Objects as functions are useful.  I do a fair amount of that in gathering data from/about various algorithms.  The objects can (by inheritance) share details of what to record (with overrides where needed) and then do their own thing on what/how to compute.  Add a #subclassResponsibility method for the algorithm's name/label, and the result is fairly nice.

FWIW, I sometimes ask myself why I "bothered" to use command (as I said, it is powerful and trouble all at the same time), but I don't recall regret over objects as functions.

Find bug, write failing test, fix bug with help of new test, in that order; +10.

Short methods - not always!! :)  I am reminded of the first time I *enrolled* in a numerical analysis class.  Details below for those who have nothing better to do.  During that one lecture I attended, he said many things of interest.  He talked about generic programming, using equations of lines (Ax+By=C always works, slope-intercept can become indeterminate).  He didn't care what language we chose to use for exercises, because (without a hint of arrogance about it) "I will be able to READ (his emphasis) anything in common use."  There was more (not bad for a first day of an undergraduate class).  The relevant point was his description of structured programming as an alternative to goto instructions.  But he said something that was a new thought to me at the time: the problem was not the goto, it was the label, which invites jumps from anywhere.

My point?  Short methods come at the cost of many little methods.  Each of those "helper" methods is what Dr. X would see as a label.  Think about it.  Please do not suggest that we enforce private methods in Smalltalk, because the code still reads the same way, and all it really does is force people to copy methods or create forwarding methods to be able to call what they want, making more entry points - IMHO at least.

I am *not* saying that we should have a minimum line length for methods, but there are indeed times when it helps to put an entire thought in one place.  If it helps any, I usually encounter this in methods that fork processes.  By the time the process gets a loop started, has an #ensure: block to clean up after itself, has a critical section or two, etc., it's not what one would call short, but IMHO, it is one "phrase" that is best seen as a whole.

Bill


So what's all this about enrolling for a class I didn't take?  My undergraduate advisor was an interesting guy.  One of the more colorful instructions he gave me was to try to get ahead of things by taking numerical analysis as taught by the computer science department; scheduling details meant that I would get the course almost a year earlier than would have otherwise been possible.  One caveat: I had clear instructions that if (let's call him Dr. X) was assigned to teach it, leave immediately, drop the course and add (I forget what) in its place.

You already know what happened: Dr. X walked in the room.  Not wanting to walk out in the middle of his lecture, I stuck around.  After about 20 minutes, I really wanted to take the class, which is why I tried to talk my advisor into letting me do so, but he was emphatic that Dr. X was a first class nut job (some US slang) and that I would end up being just one more bright student who would come back screaming - he had tried several times earlier, always with the same results.  With that, I followed his instructions and took numerical analysis in turn.



________________________________________
From: [hidden email] [[hidden email]] on behalf of Stéphane Ducasse [[hidden email]]
Sent: Saturday, December 24, 2011 9:51 AM
To: [hidden email]
Subject: Re: [Pharo-project] Good practicces! Looking for examples

On Dec 24, 2011, at 3:07 PM, Alexandre Bergel wrote:

> Not sure what you mean with good coding practice, but here my contrib:
>
> - the command pattern (e.g., OB, Mondrian Easel, MonticelloBrowser)
> - symbol polymorphic to block and other object-as-function

Not sure that this is a good practices. I think that you like them because you use Smalltalk as a DSL.

> - writing test before fixing code
> - having short methods
indeed

Here is what I started to write.


Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Damien Pollet
In reply to this post by Stéphane Ducasse
On 24 December 2011 14:53, Stéphane Ducasse <[hidden email]> wrote:
> If you have some suggestions with examples I could integrate to the chapter.

Hernán had a good list in his talk on the design of patagonia:
http://www.slideshare.net/esug/design-principlesbehindpatagonia

--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet

Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Stéphane Ducasse
indeed the presentation is quite good and I like the tips section.
Right now I started to collect coding examples (i.e. do not use , but nextPutAll:….).

Stef

On Dec 25, 2011, at 3:26 AM, Damien Pollet wrote:

> On 24 December 2011 14:53, Stéphane Ducasse <[hidden email]> wrote:
>> If you have some suggestions with examples I could integrate to the chapter.
>
> Hernán had a good list in his talk on the design of patagonia:
> http://www.slideshare.net/esug/design-principlesbehindpatagonia
>
> --
> Damien Pollet
> type less, do more [ | ] http://people.untyped.org/damien.pollet
>


Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Franz Josef Konrad-2
In reply to this post by Stéphane Ducasse
Stef,

you should also refere to Kent Beck's book "SmallTalk Best Practice
Patterns" in your chapter. IMHO it's one of the best Smalltalk books
written in this area.

Franz Josef


Am 24.12.2011 14:53, schrieb Stéphane Ducasse:

> Hi guys
>
> talking with sven during the last sprint we realized that it would be good to collect and document some good practices.
> So I started a chapter for PBE2 on coding practices.
>
> I will take the some of the optimization that sven did in time/date printOn: as a start
>
> If you have some suggestions with examples I could integrate to the chapter.
>
>
> Stef
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

onierstrasz
In reply to this post by Stéphane Ducasse

Don't forget, there are lectures on idioms and best practice patterns with lots of examples in the Smalltalk course.

https://www.iam.unibe.ch/scg/svn_repos/Lectures/Smalltalk/

Many of these come from Kent Beck's book.

- on

On 25 Dec 2011, at 10:11, Stéphane Ducasse wrote:

> indeed the presentation is quite good and I like the tips section.
> Right now I started to collect coding examples (i.e. do not use , but nextPutAll:….).
>
> Stef
>
> On Dec 25, 2011, at 3:26 AM, Damien Pollet wrote:
>
>> On 24 December 2011 14:53, Stéphane Ducasse <[hidden email]> wrote:
>>> If you have some suggestions with examples I could integrate to the chapter.
>>
>> Hernán had a good list in his talk on the design of patagonia:
>> http://www.slideshare.net/esug/design-principlesbehindpatagonia
>>
>> --
>> Damien Pollet
>> type less, do more [ | ] http://people.untyped.org/damien.pollet
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Randal L. Schwartz
In reply to this post by Franz Josef Konrad-2
>>>>> "Franz" == Franz Josef Konrad <[hidden email]> writes:

Franz> Stef,
Franz> you should also refere to Kent Beck's book "SmallTalk Best Practice Patterns"
Franz> in your chapter. IMHO it's one of the best Smalltalk books written in this
Franz> area.

But... it's not "SmallTalk"... it's "Smalltalk".  I wonder why people
keep doing that.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion

Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Franz Josef Konrad-2
blame the German Amazon site for that... I've copied the title from
there to make sure that I don't write it wrong ...

<http://www.amazon.de/SmallTalk-Best-Practice-Patterns-Kent/dp/013476904X>

Sorry Randal, for not fixing that ...


Am 25.12.2011 15:33, schrieb Randal L. Schwartz:

>>>>>> "Franz" == Franz Josef Konrad<[hidden email]>  writes:
>
> Franz>  Stef,
> Franz>  you should also refere to Kent Beck's book "SmallTalk Best Practice Patterns"
> Franz>  in your chapter. IMHO it's one of the best Smalltalk books written in this
> Franz>  area.
>
> But... it's not "SmallTalk"... it's "Smalltalk".  I wonder why people
> keep doing that.
>


Reply | Threaded
Open this post in threaded view
|

Re: Good practicces! Looking for examples

Marcus Denker-4
In reply to this post by Stéphane Ducasse

On Dec 25, 2011, at 3:26 AM, Damien Pollet wrote:

> On 24 December 2011 14:53, Stéphane Ducasse <[hidden email]> wrote:
>> If you have some suggestions with examples I could integrate to the chapter.
>
> Hernán had a good list in his talk on the design of patagonia:
> http://www.slideshare.net/esug/design-principlesbehindpatagonia
>

This is online as a video, too:

        http://www.youtube.com/watch?v=8cgmdaKwRvU


--
Marcus Denker -- http://marcusdenker.de


Reply | Threaded
Open this post in threaded view
|

Packages and Pharo and Portability : the 3 Ps !

Benoit St-Jean
In reply to this post by Schwab,Wilhelm K
I was wondering what is planned regarding packages available on SqueakSource and Pharo.  More and more packages can't load in Pharo and it gets more and more frustrating not being able to load anything without having to add/modify methods/classes all over the place so those packages can load properly in Pharo.  Are we looking at a Pharo-only kind of SqueakSource in the future ? 

Besides, having to handle platform specific (i.e. Pharo vs Squeak) for every package is adding more complexity than what is needed.  I know backward compatibility was thrown away from the start to avoid compromises in Pharo but how do we take care of the fact that as each day passes, less and less stuff from SqueakSource is usable in Pharo ?

tia
 
-----------------
Benoit St-Jean
Yahoo! Messenger: bstjean
A standpoint is an intellectual horizon of radius zero.
(Albert Einstein)
Reply | Threaded
Open this post in threaded view
|

Re: Packages and Pharo and Portability : the 3 Ps !

Igor Stasenko
On 29 December 2011 15:44, Benoit St-Jean <[hidden email]> wrote:

> I was wondering what is planned regarding packages available on SqueakSource
> and Pharo.  More and more packages can't load in Pharo and it gets more and
> more frustrating not being able to load anything without having to
> add/modify methods/classes all over the place so those packages can load
> properly in Pharo.  Are we looking at a Pharo-only kind of SqueakSource in
> the future ?
>
> Besides, having to handle platform specific (i.e. Pharo vs Squeak) for every
> package is adding more complexity than what is needed.  I know backward
> compatibility was thrown away from the start to avoid compromises in Pharo
> but how do we take care of the fact that as each day passes, less and less
> stuff from SqueakSource is usable in Pharo ?
>
The recipe is simple: maintenance.

If you really care, spend time maintaining packages you using.
If nobody cares to maintain the software, it is dead.
It is only a matter of time for it to get broken.
We cannot give any guarantee that something which worked fine 10 years
ago will keep working today,
without keeping everything unchanged.

If you have a garden and planted a rose there, do you expect that 5
years later it will still grow there, without you taking care of it?

--
Best regards,
Igor Stasenko.

Reply | Threaded
Open this post in threaded view
|

Re: Packages and Pharo and Portability : the 3 Ps !

Stéphane Ducasse
In reply to this post by Benoit St-Jean
Benoit

Let us start with some concrete questions
        - Do you have a concrete list of package not working?
        - Then do you prefer to have a vectorial UI with zomable facilities, clean code or just and old fuzzy bitmap.
        Same question: do you prefer Zinc and a nice HTTP layer or and old pre internet library?
        - Do you expect DOS applications to work nowadays? Do you care?

Stef


On Dec 29, 2011, at 3:44 PM, Benoit St-Jean wrote:

> I was wondering what is planned regarding packages available on SqueakSource and Pharo.  More and more packages can't load in Pharo and it gets more and more frustrating not being able to load anything without having to add/modify methods/classes all over the place so those packages can load properly in Pharo.  Are we looking at a Pharo-only kind of SqueakSource in the future ?  

Probably.
With quality-rules run automatically, style checking rules and some more.
And with tests of course and automatically.

We should have a Pharo distribution. I will come.

> Besides, having to handle platform specific (i.e. Pharo vs Squeak) for every package is adding more complexity than what is needed.  I know backward compatibility was thrown away from the start to avoid compromises in Pharo but how do we take care of the fact that as each day passes, less and less stuff from SqueakSource is usable in Pharo ?
>
> tia
>  
> -----------------
> Benoit St-Jean
> Yahoo! Messenger: bstjean
> A standpoint is an intellectual horizon of radius zero.
> (Albert Einstein)


Reply | Threaded
Open this post in threaded view
|

Re: Packages and Pharo and Portability : the 3 Ps !

Mariano Martinez Peck
In reply to this post by Igor Stasenko


On Thu, Dec 29, 2011 at 5:02 PM, Igor Stasenko <[hidden email]> wrote:
On 29 December 2011 15:44, Benoit St-Jean <[hidden email]> wrote:
> I was wondering what is planned regarding packages available on SqueakSource
> and Pharo.  More and more packages can't load in Pharo and it gets more and
> more frustrating not being able to load anything without having to
> add/modify methods/classes all over the place so those packages can load
> properly in Pharo.  Are we looking at a Pharo-only kind of SqueakSource in
> the future ?
>
> Besides, having to handle platform specific (i.e. Pharo vs Squeak) for every
> package is adding more complexity than what is needed.  I know backward
> compatibility was thrown away from the start to avoid compromises in Pharo
> but how do we take care of the fact that as each day passes, less and less
> stuff from SqueakSource is usable in Pharo ?
>
The recipe is simple: maintenance.

If you really care, spend time maintaining packages you using.
If nobody cares to maintain the software, it is dead.
It is only a matter of time for it to get broken.
We cannot give any guarantee that something which worked fine 10 years
ago will keep working today,
without keeping everything unchanged.

If you have a garden and planted a rose there, do you expect that 5
years later it will still grow there, without you taking care of it?


Igor, I think he is not criticizing that. What he points out is not the lack of maintenance but a clear way of knowing which project/packages are expected to work or not in Pharo. If you take a random package/project from SS there is no way to know that. Having a Pharo catalog/certified packages/projects would help here.

Cheers
 

--
Best regards,
Igor Stasenko.




--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: Packages and Pharo and Portability : the 3 Ps !

Sean P. DeNigris
Administrator
Mariano Martinez Peck wrote
a clear way of knowing which project/packages are
expected to work or not in Pharo. If you take a random package/project from
SS there is no way to know that. Having a Pharo catalog/certified
packages/projects would help here.
Yes, something is needed. Squeak has revived SqueakMap and documented a procedure. See http://forum.world.st/How-to-publish-software-for-Squeak-4-3-td4240339.html
Cheers,
Sean
12