Posted by
jas on
Nov 09, 2004; 1:01am
URL: https://forum.world.st/Character-asCharacter-tp3372010p3372026.html
Chris Uppal wrote:
> costas menico wrote:
>
>
>>It doesnt make sense to have one because asCharacter takes a character
>>and answers its ascii representation, an integer.
>
>
> (I'm assuming that wrong-way-around conversion in the above is a typo.)
>
> The #as* type methods generally come in a "ring" of mutually convertible
> objects. E.g. consider asArray, asSet, asOrderedCollection, etc. In these
> cases the #as* methods allow you to treat arrays, etc, similarly without
> worrying about the specific classes because #asXXX will convert it for you /if
> necessary/. That pattern would break if, for instance, Array did not implement
> #asArray or if it did not answer self. The #as* methods aren't really about
> /converting/ one object into another, they are about /hiding the differences
> between them/.
>
> Now one could make an argument that Integers and Characters aren't
> intra-convertible in this way. If you take that line then integer>>asCharacter
> should not exist, and neither should Character>>asInteger.
>
> OTOH one could say that Integers and Characters are almost the same since (in
> many contexts) a Character can be identified with its code-punt. If you see it
> that way, then Integer>>asCharacter and Character>>asInteger are fine, but then
> you'd expect to find Integer>>asInteger and Character>>asCharacter implemented
> too. In the current Dolphin code base, the second of these is missing.
>
> -- chris
Agreed.
These things are "missing" all over the place,
and this is not confined to Dolphin.
Neither is it confined to issues of full circularity,
although that's a great description for many cases.
For example,
ReadStream>>readStream
is also "missing", but not because
ReadStream>>asString
is also missing.
In this case, the reason is found here:
>>doSomethingWith: stringOrStream
| rs |
rs := stringOrStream readStream.
.
.
.
The upside is that you either do this, or not.
So collision of method names isn't very likely.
I just add them as I encounter the need.
Regards,
-cstb