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 <https://gist.github.com/kasperosterbye/d8c9bd518fba68289c9f129d553ad6b6> Best, Kasper
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:pharo-users-bounces@lists.pharo.org] On Behalf Of Kasper Ãsterbye Sent: Friday, 18 October 2019 2:38 AM To: Any question about pharo is welcome <pharo-users@lists.pharo.org> 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<https://urldefense.com/v3/__https:/gist.github.com/kasperosterbye/d8c9bd518f...> Best, Kasper
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.
On 18 Oct 2019, at 07:59, Richard O'Keefe <raoknz@gmail.com> 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
On 18 October 2019 at 08.00.13, Richard O'Keefe (raoknz@gmail.com) 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
Am 18.10.2019 um 11:33 schrieb Kasper Ãsterbye <kasper.osterbye@gmail.com>:
On 18 October 2019 at 08.00.13, Richard O'Keefe (raoknz@gmail.com <mailto:raoknz@gmail.com>) 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
On 19 October 2019 at 10.51.53, Norbert Hartl (norbert@hartl.name) wrote: Am 18.10.2019 um 11:33 schrieb Kasper Ãsterbye <kasper.osterbye@gmail.com>: 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 <https://github.com/pillar-markup/pillar/pull/391> 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
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
On 20 October 2019 at 09.11.06, Pierce Ng (pierce@samadhiweb.com) 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
On Sat, Oct 19, 2019 at 1:40 PM Kasper Ãsterbye <kasper.osterbye@gmail.com> 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
On 21 October 2019 at 16.17.49, Guillermo Polito (guillermopolito@gmail.com) 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
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
participants (7)
-
Guillermo Polito -
Kasper Ãsterbye -
Norbert Hartl -
Pierce Ng -
Richard O'Keefe -
Sven Van Caekenberghe -
Vince Refiti