[squeak-dev] The Trunk: Multilingual-tpr.185.mcz

Levente Uzonyi leves at elte.hu
Wed Oct 9 22:20:47 UTC 2013


On Wed, 9 Oct 2013, Bert Freudenberg wrote:

>
> On 09.10.2013, at 00:52, Levente Uzonyi <leves at elte.hu> wrote:
>
>> On Tue, 8 Oct 2013, Nicolas Cellier wrote:
>>
>>> I would prefer decent default being ^Unicode, if ever (EncodedCharSets at:1) isNil for some (bad) reason.
>>
>> Wouldn't it be better to fill the EncodedCharSets array with Unicode by default in EncodedCharSet class >> #initialize? (replace the line
>>
>> 	EncodedCharSets := Array new: 256.
>>
>> with:
>>
>> 	EncodedCharSets := Array new: 256 withAll: Unicode
>> )
>>
>> That way #charsetAt: could be simply
>>
>> 	^EncodedCharSets at: encoding + 1
>>
>>
>> Levente
>
>
> IMHO that would obscure the intention. It is technically equivalent, yes, but I'd like to see the explicit default. Most readable might be this:

I think it's better, because the intention is expressed in a single 
method, instead of two. The explicit default is there, but in #initialize.

>
> 	^ (EncodedCharSets at: encoding + 1) ifNil: [Unicode]
>
> We could even skip the "+ 1" part and only store the encoded charsets in EncodedCharSets. Unicode is not encoded, which is well-expressed by the code 0.
>
> 	^ (EncodedCharSets at: encoding ifAbsent: [nil]) ifNil: [Unicode]

Performance wise it's better to keep the "+ 1", and even better to save 
the #ifNil: too. :)


Levente

>
>
> - Bert -
>
>>>        charsetAt: encoding
>>>      + "Find  the char set encoding that matches 'encoding'; return a decent default rather than nil"
>>>      +       ^ (EncodedCharSets at: encoding + 1) ifNil: [EncodedCharSets at: 1].
>>>      -
>>>      -       ^ EncodedCharSets at: encoding + 1 ifAbsent: [EncodedCharSets at: 1].
>>>        !
>
>
>
>
>


More information about the Squeak-dev mailing list