String concatenation vs. Stream

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

String concatenation vs. Stream

Kasper Osterbye

This is an old one, and I knew of cause that one should not use #, when you can use streams instead.

But that is was this bad to use #, came as a surprise I must say

Best,

Kasper

Reply | Threaded
Open this post in threaded view
|

Re: String concatenation vs. Stream

vince

Yes, but the real question is: What is the lower bound?

 

When would you consider it pointless to use streams and just concatenate away? Or even trying to profile the difference. For me, 3 or less.

 

Vince

 

From: Pharo-users [mailto:[hidden email]] On Behalf Of Kasper Østerbye
Sent: Friday, 18 October 2019 2:38 AM
To: Any question about pharo is welcome <[hidden email]>
Subject: [Pharo-users] String concatenation vs. Stream

 

EXTERNAL: Do not click links or open attachments if you do not recognize the sender.

This is an old one, and I knew of cause that one should not use #, when you can use streams instead.

But that is was this bad to use #, came as a surprise I must say

Best,

Kasper

Reply | Threaded
Open this post in threaded view
|

Re: String concatenation vs. Stream

Richard O'Keefe
When is it pointless to introduce a WriteStream and just use #, ?
When #, would not be in a loop or recursion.
Constructing error messages, class initialisation code, that sort of thing.

If you find yourself doing a lot of concatenations, you are probably
missing an abstraction.  For example, building up XML by string
concatenation would be very silly: you want to build a tree and have
it write itself to a stream.

Reply | Threaded
Open this post in threaded view
|

Re: String concatenation vs. Stream

Sven Van Caekenberghe-2


> On 18 Oct 2019, at 07:59, Richard O'Keefe <[hidden email]> wrote:
>
> When is it pointless to introduce a WriteStream and just use #, ?
> When #, would not be in a loop or recursion.
> Constructing error messages, class initialisation code, that sort of thing.
>
> If you find yourself doing a lot of concatenations, you are probably
> missing an abstraction.  For example, building up XML by string
> concatenation would be very silly: you want to build a tree and have
> it write itself to a stream.

+100

Reply | Threaded
Open this post in threaded view
|

Re: String concatenation vs. Stream

Kasper Osterbye
In reply to this post by Richard O'Keefe
On 18 October 2019 at 08.00.13, Richard O'Keefe ([hidden email]) wrote:
When is it pointless to introduce a WriteStream and just use #, ? 
When #, would not be in a loop or recursion. 
Constructing error messages, class initialisation code, that sort of thing. 

If you find yourself doing a lot of concatenations, you are probably 
missing an abstraction. For example, building up XML by string 
concatenation would be very silly: you want to build a tree and have 
it write itself to a stream. 

Absolutely agree. Streams use logarithmic extension of buffer, concatenation linear, but it is still amazing to see.

I am working on a pillar to `Text` generator. Here I found concatenation to be simpler to handle as I can add bold, italics, indentation, etc. in a much simpler way. To use a streaming method I would have to introduce both Canvas and Aggregate brushes. Doable indeed, but much less concise.

Best,

Kasper

Reply | Threaded
Open this post in threaded view
|

Re: String concatenation vs. Stream

Kasper Osterbye
In reply to this post by vince

When would you consider it pointless to use streams and just concatenate away? Or even trying to profile the difference. For me, 3 or less.

Sounds about right. Or if it fits within a line. Or if it makes the code significantly easier to read.

Best,

Kasper

Reply | Threaded
Open this post in threaded view
|

Re: String concatenation vs. Stream

NorbertHartl
In reply to this post by Kasper Osterbye


Am 18.10.2019 um 11:33 schrieb Kasper Østerbye <[hidden email]>:

On 18 October 2019 at 08.00.13, Richard O'Keefe ([hidden email]) wrote:
When is it pointless to introduce a WriteStream and just use #, ? 
When #, would not be in a loop or recursion. 
Constructing error messages, class initialisation code, that sort of thing. 

If you find yourself doing a lot of concatenations, you are probably 
missing an abstraction. For example, building up XML by string 
concatenation would be very silly: you want to build a tree and have 
it write itself to a stream. 

Absolutely agree. Streams use logarithmic extension of buffer, concatenation linear, but it is still amazing to see.

I am working on a pillar to `Text` generator. Here I found concatenation to be simpler to handle as I can add bold, italics, indentation, etc. in a much simpler way. To use a streaming method I would have to introduce both Canvas and Aggregate brushes. Doable indeed, but much less concise.


I started to do exactly the same. Well I started to do a converter between pillar markup and text attributes, but I think you do the same. We probably should talk. Is you code anywhere public?

Norbert

Best,

Kasper


Reply | Threaded
Open this post in threaded view
|

Pillar in-image rendering (was: String concatenation vs. Stream)

Kasper Osterbye
On 19 October 2019 at 10.51.53, Norbert Hartl ([hidden email]) wrote:
Am 18.10.2019 um 11:33 schrieb Kasper Østerbye <[hidden email]>:

I am working on a pillar to `Text` generator. Here I found concatenation to be simpler to handle as I can add bold, italics, indentation, etc. in a much simpler way. To use a streaming method I would have to introduce both Canvas and Aggregate brushes. Doable indeed, but much less concise.


I started to do exactly the same. Well I started to do a converter between pillar markup and text attributes, but I think you do the same. We probably should talk. Is you code anywhere public?

Norbert

I have the basic pillar rendering done: headers, lists, bold, emphasis, images, links (including a “open browser on method” link).

My main remaining issue is to do tables somehow. Any hints on how to render tables inside a text?

It is not on github atm - I need a pull request to come through there before I can be a modular extension. 

I’ll try to get it up on my own github sometime Monday.

I am currently working on a github markdown -> pillar tree (the internal rep of pillar). I estimate I am a few days out from that one.

Best,

Kasper

Reply | Threaded
Open this post in threaded view
|

Re: Pillar in-image rendering (was: String concatenation vs. Stream)

Pierce Ng-3
On Sat, Oct 19, 2019 at 04:39:21AM -0700, Kasper Østerbye wrote:
> I am currently working on a github markdown -> pillar tree (the internal
> rep of pillar). I estimate I am a few days out from that one.

Are you doing this in pure Pharo?

I have wrapped libhoedown, a Markdown to HTML library. libhoedown uses
callbacks to invoke its renderer and I started constructing a Markdown
to Pillar (string, not object tree) renderer by having libhoedown call
back into Pharo.

Pierce


Reply | Threaded
Open this post in threaded view
|

Re: Pillar in-image rendering (was: String concatenation vs. Stream)

Kasper Osterbye
On 20 October 2019 at 09.11.06, Pierce Ng ([hidden email]) wrote:
On Sat, Oct 19, 2019 at 04:39:21AM -0700, Kasper Østerbye wrote: 
> I am currently working on a github markdown -> pillar tree (the internal 
> rep of pillar). I estimate I am a few days out from that one. 

Are you doing this in pure Pharo? 

Yes. I want to be able to render it inside the image windows. 

I have wrapped libhoedown, a Markdown to HTML library. libhoedown uses 
callbacks to invoke its renderer and I started constructing a Markdown 
to Pillar (string, not object tree) renderer by having libhoedown call 
back into Pharo. 

Pierce 

I do understand you not wanting to write your own parser, it is a pest!  However, I want a simple distribution model with no external dependencies.

At the moment I have a working github-markdown parser (written in Pharo) which recognises:

Blocks: headers, paragraphs, ordered and unorderd (nested) lists, block, code-blocs.

Inline: bold, italics, overstrike, inline-code. 

I want links and images before releasing it as version 1.

It is restrictive and is a bit peculiar regarding indentation and a few other things.

— Kasper

Reply | Threaded
Open this post in threaded view
|

Re: Pillar in-image rendering (was: String concatenation vs. Stream)

Guillermo Polito
In reply to this post by Kasper Osterbye

On Sat, Oct 19, 2019 at 1:40 PM Kasper Østerbye <[hidden email]> wrote:

My main remaining issue is to do tables somehow. Any hints on how to render tables inside a text?


Hi Kasper, some intuition from my part for this.
What if instead of putting tables into text you put text into tables ;).
In other words, think both text and tables as renderable elements (cof cof morphs).
Then, since we can make a morph from a text, and a table morph, then both can be combined.

Cheers,
Guille
Reply | Threaded
Open this post in threaded view
|

Re: Pillar in-image rendering (was: String concatenation vs. Stream)

Kasper Osterbye
On 21 October 2019 at 16.17.49, Guillermo Polito ([hidden email]) wrote:
What if instead of putting tables into text you put text into tables ;).
In other words, think both text and tables as renderable elements (cof cof morphs).
Then, since we can make a morph from a text, and a table morph, then both can be combined.

Out of the table thinking :-)

So by putting a table on the outside, I can make the normal paragraphs individual rows of one column?

To make an actual table, it would be some rows with more columns than one?

Do the tables morphs allow for merged  cells?

I will look into it, but I am not too optimistic that I will be able to get anything that looks nice. 

Best,

Kasper