[squeak-dev] Re: [Pharo-project] Alien FFI

Vassili Bykov smalltalkbigot at gmail.com
Mon Nov 24 20:53:56 UTC 2008


On Mon, Nov 24, 2008 at 11:37 AM, John M McIntosh
<johnmci at smalltalkconsulting.com> wrote:
> Ok, well asAlien seems to be used as conversion methods to ensure a passed
> object is an alien.
> What would you like to do instead?

I'd like to remove String>>asAlien and have no #asAlien methods. C and
Smalltalk worlds are too different, and poor man's marshalling with
#asAlien only adds confusion. It works in a simple unambiguous way
only for some objects like True and False. String>>asAlien is already
not transparent because it allocates a static buffer that needs
freeing. And then, how far do we take this? A ByteArray could
conceivably have #asAlien, but should we also handle Arrays of
Integers? What about Arrays of Strings?

Apart from the C semantics, this is also a questionable style. The
general rule for the choice between instance creation or conversion
messages is that conversion messages make sense when the classes are
sufficiently similar. An Alien is not an alternative form of a String,
and "'foo' asAlien" is not a conversion of a String to an Alien. It's
a creation of an Alien initialized in a particular way. There could be
other equally meaningful ways of initializing it from the same data,
so "Alien newCString: 'foo'" works because we could also have "Alien
newUnicodeString: 'foo'", and "'foo' asAlien" is a convenience that
doesn't scale (and also makes aliens appear less alien than they ought
to).

--Vassili



More information about the Squeak-dev mailing list