[Newbies] pretty printing
Claus Kick
claus_kick at web.de
Mon Sep 29 19:11:40 UTC 2008
Bert Freudenberg wrote:
>
> Am 29.09.2008 um 10:07 schrieb Claus Kick:
>
>> Bert Freudenberg wrote:
>>
>> > Guess I have to provide an alternative:
>>
>>> #('&' '&' '<' '<' '>' '>' '''' ''' '"' '"')
>>> pairsDo: [:c :s| string := string copyReplaceAll: c with: s].
>>
>>
>>> (this is the same approach as in String>>asHTML)
>>
>>
>> Ok, to nitpick (;)) one message send less for each pair:
>>
>> #('&' '&' '<' '<' '>' '>' '''' ''' '"' '"')
>> pairsDo: [:c :s| string := string copyReplaceAll: c with: s
>> asTokens:false].
>
>
> This is silly advice. Why would you willingly expose an implementation
> detail? There are many constructs that could be expanded but
> readability and portability is hurt by that.
Yes, it was mostly silly, thats what the ;) was for.
Sometimes, however, if you have lets say an operation going for a
million of loops (i.e. recursive checks over huge object groups), a few
unnecessary message sends can cost you precious time. We had code like
that at my old shop.
However mostly, I wanted to ask the following:
>> How do pairs compare to dictionaries in Squeak?
>
>
> Well, there are no "pairs" per se but just an iteration method on
> sequenceable collections.
>
> When iterating a Dictionary, the order is unpredictable. In my example
> it is vital to replace '&' first.
>
> Also, Squeak does not have a literal syntax for dictionaries but for
> Arrays so my example is more efficient because the Array is constructed
> at compile-time. OTOH, in real code one might put the dictionary into
> a class variable so this wouldn't matter.
Ok, so if you used a class variable then it would not matter. How well
are look-ups performing with Squeak?
More information about the Beginners
mailing list