[Article] Elegant Pharo Code

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

[Article] Elegant Pharo Code

Sven Van Caekenberghe-2
Hi,

I have written a new article presenting Pharo using a list of 23 short examples.

  Elegant Pharo Code

  Beautiful & Powerful One-liners, Expressions and Snippets

  https://medium.com/@svenvc/elegant-pharo-code-bb590f0856d0

As mentioned at the end of the article, I welcome feedback, remarks, comments, alternative solutions and other examples. The idea is to create yet another way to lure people into exploring Pharo while explaining by example why we like Pharo.

Enjoy!

Sven

--
Sven Van Caekenberghe
Proudly supporting Pharo
http://pharo.org
http://association.pharo.org
http://consortium.pharo.org





Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

Tudor Girba-2
Neat :)

Doru


On Tue, Jul 8, 2014 at 12:21 AM, Sven Van Caekenberghe <[hidden email]> wrote:
Hi,

I have written a new article presenting Pharo using a list of 23 short examples.

  Elegant Pharo Code

  Beautiful & Powerful One-liners, Expressions and Snippets

  https://medium.com/@svenvc/elegant-pharo-code-bb590f0856d0

As mentioned at the end of the article, I welcome feedback, remarks, comments, alternative solutions and other examples. The idea is to create yet another way to lure people into exploring Pharo while explaining by example why we like Pharo.

Enjoy!

Sven

--
Sven Van Caekenberghe
Proudly supporting Pharo
http://pharo.org
http://association.pharo.org
http://consortium.pharo.org








--

"Every thing has its own flow"
Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

HilaireFernandes
In reply to this post by Sven Van Caekenberghe-2
Thanks Sven,

It is nice and helpful, I would look at it if I have the opportunity to
give a talk about Pharo while in Taiwan this summer.


Hilaire


Le 08/07/2014 06:21, Sven Van Caekenberghe a écrit :

> Hi,
>
> I have written a new article presenting Pharo using a list of 23 short examples.
>
>    Elegant Pharo Code
>
>    Beautiful & Powerful One-liners, Expressions and Snippets
>
>    https://medium.com/@svenvc/elegant-pharo-code-bb590f0856d0
>
> As mentioned at the end of the article, I welcome feedback, remarks, comments, alternative solutions and other examples. The idea is to create yet another way to lure people into exploring Pharo while explaining by example why we like Pharo.
>
> Enjoy!
>
> Sven
>
> --
> Sven Van Caekenberghe
> Proudly supporting Pharo
> http://pharo.org
> http://association.pharo.org
> http://consortium.pharo.org
>
>
>
>
>
>


--
Dr. Geo - http://drgeo.eu
iStoa - http://launchpad.net/istoa


Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

hernanmd
In reply to this post by Sven Van Caekenberghe-2
Hello Sven,

I will try to give some feedback for you. My major issue is that the objects you use are pretty basic. There is no reason to put limits with so many contributed packages. Visualizations have impact and you could use Roassal, GraphViz, CodeCity, GraphET. SQL is also of interest for many developers. Or Big Data which is a requirement now. An example with Spec and DynamicLayout would be cool. For reverse engineering there is Moose and you could show an overview pyramid maybe? A one-liner with #linesOfCode would be magic :)

About the article: When writing sample code with random, don't forget to add a paragraph explaining the random source. It is /dev/urandom? To randomize a String I write this:

(UUID new asString reject: #isDigit) copyWithoutAll: '-'.

To count digits (doesn't work for 1 digit but I like it):

42 factorial log ceiling.

I don't know how this could be useful besides doing many things: "Split a string on dashes, reverse the order of the elements and join them using slashes". If you could find a example with some real application would be nice too.

For Collection messages people is often interested in speed comparisons. Because audience already knows how to do that in R, Python or other language.

Hope you could find them useful.

Hernán




2014-07-07 19:21 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
Hi,

I have written a new article presenting Pharo using a list of 23 short examples.

  Elegant Pharo Code

  Beautiful & Powerful One-liners, Expressions and Snippets

  https://medium.com/@svenvc/elegant-pharo-code-bb590f0856d0

As mentioned at the end of the article, I welcome feedback, remarks, comments, alternative solutions and other examples. The idea is to create yet another way to lure people into exploring Pharo while explaining by example why we like Pharo.

Enjoy!

Sven

--
Sven Van Caekenberghe
Proudly supporting Pharo
http://pharo.org
http://association.pharo.org
http://consortium.pharo.org






Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

philippeback
Wow, I wouldn't go there in that particular article.

But things like: 

(groups at: (aBlock value: each) ifAbsentPut: [ OrderedCollection new ]) add: each

Especially when they are in Collection>>groupedBy: aBlock

could make cool other articles.

There are also Matrix etc which are understandable by people and add value. I guess you may have some Bio samples here.

Sven, thanks for taking the time to write those articles on medium. They look great and I enjoyed them immensely.

I pushed me to look into how to write for that website. That a step :-)
Phil


On Wed, Jul 9, 2014 at 9:11 AM, Hernán Morales Durand <[hidden email]> wrote:
Hello Sven,

I will try to give some feedback for you. My major issue is that the objects you use are pretty basic. There is no reason to put limits with so many contributed packages. Visualizations have impact and you could use Roassal, GraphViz, CodeCity, GraphET. SQL is also of interest for many developers. Or Big Data which is a requirement now. An example with Spec and DynamicLayout would be cool. For reverse engineering there is Moose and you could show an overview pyramid maybe? A one-liner with #linesOfCode would be magic :)

About the article: When writing sample code with random, don't forget to add a paragraph explaining the random source. It is /dev/urandom? To randomize a String I write this:

(UUID new asString reject: #isDigit) copyWithoutAll: '-'.

To count digits (doesn't work for 1 digit but I like it):

42 factorial log ceiling.

I don't know how this could be useful besides doing many things: "Split a string on dashes, reverse the order of the elements and join them using slashes". If you could find a example with some real application would be nice too.

For Collection messages people is often interested in speed comparisons. Because audience already knows how to do that in R, Python or other language.

Hope you could find them useful.

Hernán




2014-07-07 19:21 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
Hi,

I have written a new article presenting Pharo using a list of 23 short examples.

  Elegant Pharo Code

  Beautiful & Powerful One-liners, Expressions and Snippets

  https://medium.com/@svenvc/elegant-pharo-code-bb590f0856d0

As mentioned at the end of the article, I welcome feedback, remarks, comments, alternative solutions and other examples. The idea is to create yet another way to lure people into exploring Pharo while explaining by example why we like Pharo.

Enjoy!

Sven

--
Sven Van Caekenberghe
Proudly supporting Pharo
http://pharo.org
http://association.pharo.org
http://consortium.pharo.org







Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

Ben Coman
In reply to this post by hernanmd
Hernán Morales Durand wrote:
Hello Sven,

I will try to give some feedback for you. My major issue is that the objects you use are pretty basic. There is no reason to put limits with so many contributed packages. Visualizations have impact and you could use Roassal, GraphViz, CodeCity, GraphET. SQL is also of interest for many developers. Or Big Data which is a requirement now. An example with Spec and DynamicLayout would be cool. For reverse engineering there is Moose and you could show an overview pyramid maybe? A one-liner with #linesOfCode would be magic :)

I wouldn't add those to the existing article, but they would be great in another article, perhaps entitled "Elegant Pharo Ecosystem" - because the ecosystem (aka libraries) of a language is important. 
cheers -ben



2014-07-07 19:21 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
Hi,

I have written a new article presenting Pharo using a list of 23 short examples.

  Elegant Pharo Code

  Beautiful & Powerful One-liners, Expressions and Snippets

  https://medium.com/@svenvc/elegant-pharo-code-bb590f0856d0

As mentioned at the end of the article, I welcome feedback, remarks, comments, alternative solutions and other examples. The idea is to create yet another way to lure people into exploring Pharo while explaining by example why we like Pharo.

Enjoy!

Sven

--
Sven Van Caekenberghe
Proudly supporting Pharo
http://pharo.org
http://association.pharo.org
http://consortium.pharo.org







Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

Sven Van Caekenberghe-2
In reply to this post by hernanmd
Hi Hernán,

On 09 Jul 2014, at 09:11, Hernán Morales Durand <[hidden email]> wrote:

> Hello Sven,
>
> I will try to give some feedback for you.

It is good to talk about the contents, the essence.

> My major issue is that the objects you use are pretty basic. There is no reason to put limits with so many contributed packages.

Well, I tried to stick with stock Pharo (except for the very last example that needs JSON parsing). Yes, some examples make little sense, but they each do show something powerful, something that is missing in many languages.

I was kind of hoping to get some discussion going with people submitting their favourites/alternatives, so that the list of examples could be improved/extended. But I am a hard judge ;-)

> Visualizations have impact and you could use Roassal, GraphViz, CodeCity, GraphET. SQL is also of interest for many developers. Or Big Data which is a requirement now. An example with Spec and DynamicLayout would be cool. For reverse engineering there is Moose and you could show an overview pyramid maybe? A one-liner with #linesOfCode would be magic :)

Like others said, there could/should be other articles doing something similar (giving a couple of cool examples as an overview/introduction), focused on the areas/libraries/frameworks you mention. Please feel inspired.

> About the article: When writing sample code with random, don't forget to add a paragraph explaining the random source. It is /dev/urandom? To randomize a String I write this:
>
> (UUID new asString reject: #isDigit) copyWithoutAll: '-'.

Talking about the random source would lead a bit far, no ?
I don't like your random string example, it is too contrived.
The one I used is not perfect either, I would probably write it myself as

String
  new: 256
  streamContents: [ :string |
    256 timesRepeat: [ string nextPut: 'abcdef' atRandom ]  ].

But having to write 256 twice is not cool, hence the my other choice.

> To count digits (doesn't work for 1 digit but I like it):
>
> 42 factorial log ceiling.

That is cool indeed.

What I wanted to show is that, not only are Pharo numbers real objects that can be mixed freely, without thinking about them, but that they are more than that: real normal objects that you can add lots of useful methods too.

> I don't know how this could be useful besides doing many things: "Split a string on dashes, reverse the order of the elements and join them using slashes". If you could find a example with some real application would be nice too.

Yes indeed, it does not make enough sense. Any ideas ?

> For Collection messages people is often interested in speed comparisons. Because audience already knows how to do that in R, Python or other language.

Speed is not the subject of the article. Sure, some operations can certainly be done in some other languages but certainly not in all of them, out of the box. I would really like to see the standard deviation one (17) done in other languages, for example.

> Hope you could find them useful.

Yes ;-)

Sven

> Hernán
>
>
>
>
> 2014-07-07 19:21 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
> Hi,
>
> I have written a new article presenting Pharo using a list of 23 short examples.
>
>   Elegant Pharo Code
>
>   Beautiful & Powerful One-liners, Expressions and Snippets
>
>   https://medium.com/@svenvc/elegant-pharo-code-bb590f0856d0
>
> As mentioned at the end of the article, I welcome feedback, remarks, comments, alternative solutions and other examples. The idea is to create yet another way to lure people into exploring Pharo while explaining by example why we like Pharo.
>
> Enjoy!
>
> Sven
>
> --
> Sven Van Caekenberghe
> Proudly supporting Pharo
> http://pharo.org
> http://association.pharo.org
> http://consortium.pharo.org
>
>
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

Nicolai Hess



2014-07-09 16:13 GMT+02:00 Sven Van Caekenberghe <[hidden email]>:
Hi Hernán,

On 09 Jul 2014, at 09:11, Hernán Morales Durand <[hidden email]> wrote:

> Hello Sven,
>
> I will try to give some feedback for you.

It is good to talk about the contents, the essence.

> My major issue is that the objects you use are pretty basic. There is no reason to put limits with so many contributed packages.

Well, I tried to stick with stock Pharo (except for the very last example that needs JSON parsing). Yes, some examples make little sense, but they each do show something powerful, something that is missing in many languages.

I was kind of hoping to get some discussion going with people submitting their favourites/alternatives, so that the list of examples could be improved/extended. But I am a hard judge ;-)

> Visualizations have impact and you could use Roassal, GraphViz, CodeCity, GraphET. SQL is also of interest for many developers. Or Big Data which is a requirement now. An example with Spec and DynamicLayout would be cool. For reverse engineering there is Moose and you could show an overview pyramid maybe? A one-liner with #linesOfCode would be magic :)

Like others said, there could/should be other articles doing something similar (giving a couple of cool examples as an overview/introduction), focused on the areas/libraries/frameworks you mention. Please feel inspired.

> About the article: When writing sample code with random, don't forget to add a paragraph explaining the random source. It is /dev/urandom? To randomize a String I write this:
>
> (UUID new asString reject: #isDigit) copyWithoutAll: '-'.

Talking about the random source would lead a bit far, no ?
I don't like your random string example, it is too contrived.
The one I used is not perfect either, I would probably write it myself as

String
  new: 256
  streamContents: [ :string |
    256 timesRepeat: [ string nextPut: 'abcdef' atRandom ]  ].

But having to write 256 twice is not cool, hence the my other choice.

> To count digits (doesn't work for 1 digit but I like it):
>
> 42 factorial log ceiling.

That is cool indeed.

What I wanted to show is that, not only are Pharo numbers real objects that can be mixed freely, without thinking about them, but that they are more than that: real normal objects that you can add lots of useful methods too.

> I don't know how this could be useful besides doing many things: "Split a string on dashes, reverse the order of the elements and join them using slashes". If you could find a example with some real application would be nice too.

Yes indeed, it does not make enough sense. Any ideas ?

split - reverse - join

$: join: ($: split:'0A:0B:0C:0D' ) reverse.

convert hex address host/network.


Btw, do we have a single message like split, but split at every nt element?
3 split '123456789' -> '123' '456' '789'






 

> For Collection messages people is often interested in speed comparisons. Because audience already knows how to do that in R, Python or other language.

Speed is not the subject of the article. Sure, some operations can certainly be done in some other languages but certainly not in all of them, out of the box. I would really like to see the standard deviation one (17) done in other languages, for example.

> Hope you could find them useful.

Yes ;-)

Sven

> Hernán
>
>
>
>
> 2014-07-07 19:21 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
> Hi,
>
> I have written a new article presenting Pharo using a list of 23 short examples.
>
>   Elegant Pharo Code
>
>   Beautiful & Powerful One-liners, Expressions and Snippets
>
>   https://medium.com/@svenvc/elegant-pharo-code-bb590f0856d0
>
> As mentioned at the end of the article, I welcome feedback, remarks, comments, alternative solutions and other examples. The idea is to create yet another way to lure people into exploring Pharo while explaining by example why we like Pharo.
>
> Enjoy!
>
> Sven
>
> --
> Sven Van Caekenberghe
> Proudly supporting Pharo
> http://pharo.org
> http://association.pharo.org
> http://consortium.pharo.org
>
>
>
>
>
>



Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

Buddha Buck
In reply to this post by Sven Van Caekenberghe-2

On Wed, Jul 9, 2014 at 10:13 AM, Sven Van Caekenberghe <[hidden email]> wrote:
> I don't know how this could be useful besides doing many things: "Split a string on dashes, reverse the order of the elements and join them using slashes". If you could find a example with some real application would be nice too.

Yes indeed, it does not make enough sense. Any ideas ?

There are probably better ways to do it (using true date objects) but converting ISO date strings to US or EU date strings (yyyy-mm-dd to mm-dd-yyyy or dd-mm-yyyy) is almost "Split a string on dashes, rearrange the order of the elements and join them using slashes."

Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

Sven Van Caekenberghe-2

On 09 Jul 2014, at 17:04, Buddha Buck <[hidden email]> wrote:

>
> On Wed, Jul 9, 2014 at 10:13 AM, Sven Van Caekenberghe <[hidden email]> wrote:
> > I don't know how this could be useful besides doing many things: "Split a string on dashes, reverse the order of the elements and join them using slashes". If you could find a example with some real application would be nice too.
>
> Yes indeed, it does not make enough sense. Any ideas ?
>
> There are probably better ways to do it (using true date objects) but converting ISO date strings to US or EU date strings (yyyy-mm-dd to mm-dd-yyyy or dd-mm-yyyy) is almost "Split a string on dashes, rearrange the order of the elements and join them using slashes."

I changed the example to use the euro/us date conversion as that is indeed something most people will understand.

Thx!



Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

Offray
In reply to this post by hernanmd
Sven,

Thanks for your articles. I really like the approach and the idea of
starting with more problem oriented writting (making a game is more
project oriented, which is also fine by the way, just a complementary
approach I prefer more). I would add myself to the Hernán's suggestion
of using visualization to explain Smalltalk better, of course this could
not be appropriate for on liners, but could be used in future post of
your blog. I have thought about this myself[1] and made some small
experiments[2] and in some sense Pharo seems a richer environment that
even IPython


[1]
http://mutabit.com/offray/static/blog/output/posts/pharo-by-visualization.html
[2]
http://mutabit.com/offray/static/blog/output/posts/borrachos-bochinche-futbol.html
[3] http://mutabit.com/mutabit/default/wiki/ipython-deepness

I would write a (Dyna)booklet on "Visual Data Narratives using Pharo
Smalltalk" but for that I need to bootstrap my writing process inside
Pharo by making tools that support outlining which is my best way to
organize my writing[3]. That's where I'm now and in the process I hope
to bootstrap myself from mailing list lurker and newbie to a more active
member of this community. Your blog post are a good inspiration in this pad.

Cheers,

Offray


On 07/09/2014 02:11 AM, Hernán Morales Durand wrote:

> Hello Sven,
>
> I will try to give some feedback for you. My major issue is that the objects you
> use are pretty basic. There is no reason to put limits with so many contributed
> packages. Visualizations have impact and you could use Roassal, GraphViz,
> CodeCity, GraphET. SQL is also of interest for many developers. Or Big Data
> which is a requirement now. An example with Spec and DynamicLayout would be
> cool. For reverse engineering there is Moose and you could show an overview
> pyramid maybe? A one-liner with #linesOfCode would be magic :)
>
> About the article: When writing sample code with random, don't forget to add a
> paragraph explaining the random source. It is /dev/urandom? To randomize a
> String I write this:
>
> (UUID new asString reject: #isDigit) copyWithoutAll: '-'.
>
> To count digits (doesn't work for 1 digit but I like it):
>
> 42 factorial log ceiling.
>
> I don't know how this could be useful besides doing many things: "Split a string
> on dashes, reverse the order of the elements and join them using slashes". If
> you could find a example with some real application would be nice too.
>
> For Collection messages people is often interested in speed comparisons. Because
> audience already knows how to do that in R, Python or other language.
>
> Hope you could find them useful.
>
> Hernán
>
>
>
>
> 2014-07-07 19:21 GMT-03:00 Sven Van Caekenberghe <[hidden email]
> <mailto:[hidden email]>>:
>
>      Hi,
>
>      I have written a new article presenting Pharo using a list of 23 short examples.
>
>         Elegant Pharo Code
>
>         Beautiful & Powerful One-liners, Expressions and Snippets
>
>      https://medium.com/@svenvc/elegant-pharo-code-bb590f0856d0
>
>      As mentioned at the end of the article, I welcome feedback, remarks,
>      comments, alternative solutions and other examples. The idea is to create
>      yet another way to lure people into exploring Pharo while explaining by
>      example why we like Pharo.
>
>      Enjoy!
>
>      Sven
>
>      --
>      Sven Van Caekenberghe
>      Proudly supporting Pharo
>      http://pharo.org
>      http://association.pharo.org
>      http://consortium.pharo.org
>
>
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: [Article] Elegant Pharo Code

Sean P. DeNigris
Administrator
Offray wrote
I would write a (Dyna)booklet...
Great idea! Active Essays should be our only documentation :)
Cheers,
Sean