[squeak-dev] String & Text

Eliot Miranda eliot.miranda at gmail.com
Wed Jul 13 14:50:50 UTC 2022



> On Jul 13, 2022, at 2:14 AM, Rein, Patrick <Patrick.Rein at hpi.de> wrote:
> 
> ´╗┐To me String and Text should share all protocols related to dealing with a collection of characters. Text is a collection of characters with attached formatting information, thus Text "only" has to make sure that the attributes match whatever was done to the character collection. I regularly get slightly annoyed when I try using a String selector with a Text object and get a DNU.
> 
> Some time ago, someone proposed to have an abstract CharacterCollection as the superclass of both classes. I very much like that idea, as it would allow us to make the shared protocol explicit. We might not be able to factor much out to this shared superclass but at least, we can have a clear expectation of what should work for both. This would also signify (somewhat) that the behavior should be consistent between the two. In practice I would probably expect Text behavior to be a superset of the String behavior,

+1

> but I am not really sure about that.

The VisualWorks team back before Cincom (ie the team that started ParcPlace) were very sure on this point.

> 
> Just my humble oppinion though. :)
> 
> Cheers,
> Patrick
> 
> 
> ________________________________________
> From: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> on behalf of Jakob Reschke <jakres+squeak at gmail.com>
> Sent: Wednesday, July 13, 2022 10:12:29 AM
> To: The general-purpose Squeak developers list
> Subject: Re: [squeak-dev] String & Text
> 
> A common idiom is 'string literal' translated format: {...}
> 
> While textual placeholders may make the correct placement of the placeholders in the translated phrase easier, there is also the danger that an inexperienced translator will translate the placeholder's identifier. That would obviously break the intended formatting.
> 
> This is independent of the question whether Text and String should both support textual placeholders or not.
> 
> 
> Am Mi., 13. Juli 2022 um 10:09 Uhr schrieb Jakob Reschke <jakres+squeak at gmail.com<mailto:jakres%2Bsqueak at gmail.com>>:
> Hi,
> 
> Maybe it would be better if they did not share so much of the protocol. So that the system guided you better when to use String and when to use Text, separating the responsibilities more.
> 
> For example, I would argue that the asText send is misplaced in this example from AbstractFont>>#browseGlyphsByCategoryOf:select:label:
> 
> separatorBlock := [:codePoints :category |
>    (('\{1}\\' withCRs asText
>        format: { Unicode generalCategoryLabels at: category+1 ifAbsent: ['n/a'] })
>        addAttribute: (TextFontReference toFont: TextStyle defaultFixedFont);
>        addAttribute: (PluggableTextAttribute evalBlock: [self browseGlyphsByCategoryOf: codePoints select: aBlock label: aLabelOrNil]);
>        yourself) ].
> 
> asText could just as well come after the format:.
> 
> Later in the same method comes an example, which is not criticized so easily, where pieces with attributes already applied are inserted via format:
> 
> contents := (('Family name: {1}{6}\   Emphasis: {2}\ Point size: {3} ({4}ppi {5}px{7})\' withCRs asText format: { self familyName asText addAttribute: (PluggableTextAttribute evalBlock: [self explore]); yourself. [self emphasisString] on: Error do: [self subfamilyName]. self pointSize. self pixelsPerInch. self height. isRange ifTrue: [''] ifFalse: [' (selected code points)']. (self isTTCFont and: [(tmp := self extraGlyphScale) ~= 1]) ifFalse: [''] ifTrue: [' ', (tmp * 100) rounded asString, '%'] }) addAttribute: (TextFontReference toFont: TextStyle defaultFixedFont); yourself).
> 
> Many of the occurrences of Text>>format: that I saw are used to insert links in the text template, or highlighted pieces.
> 
> So I guess my opening statement is just dreaming without much practical expertise in the concrete matter. Since Text and String are already interchangeable in certain aspects, you cannot simply roll back without breaking lots of things. Under these circumstances I agree that they should behave equivalently for the protocol that they do share. Otherwise an existing pair of '...' and format: may suddenly fail if you put asText between the two later.
> 
> +1 for adding symbolic placeholders to Text >> #format:, unless format: gets removed from Text or the feature gets removed from String again. ;-)
> 
> Kind regards,
> Jakob
> 
> 
> Am Mi., 13. Juli 2022 um 08:48 Uhr schrieb Marcel Taeumel <marcel.taeumel at hpi.de<mailto:marcel.taeumel at hpi.de>>:
> Hi all --
> 
> What are your thoughts on String and Text. In GUI programming, it
> is rather annoying to have to sprinkle #asText all over the code. It's
> nice to have most important protocol shared between String and Text.
> 
> The recent change to only String >> #format: (see Collections-cmm.1016)
> to support symbols as placeholders indicates kind of a disagreement
> in how Text should be used in (GUI) code. Well, if some message is
> not there in Text, it is easy to find out. However, having a protocol there
> with different details feels rather challenging.
> 
> I accept that not all protocols are shared between String and Text.
> I do not like inconsistencies of method implementations where the
> message (and signature) is identical.
> 
> +1 for adding symbolic placeholders to Text >> #format: as well.
> 
> Best,
> Marcel
> 
> 


More information about the Squeak-dev mailing list