[squeak-dev] Re: sane defaults and doesNotUnderstand: (was Future blah blah blah)

David Goehrig dave at nexttolast.com
Tue Jun 30 16:24:21 UTC 2009


On Tue, Jun 30, 2009 at 11:28 AM, Klaus D. Witzel <klaus.witzel at cobss.com>wrote:
>
>
> You just want this? result = (anObject.methodName ? methodName() : false)
>
> ?


Not quite.. if you were attempting to write it in javascript it would look
more like:

   result = ( typeof(anObject[methodName]) == "function" ) ?
anObject[methodName]() :
        currentContext == "boolean" ?  false :
        currentContext == "number" ? 0 :
        currentContext == "string" ? '' :
        currentContext == "array" ? [] :
        currentContext == "object" ? {} :
        undefined;

where currentContext would be an internal variable denoting the desired type
/ class / or traits
of the result.
 The idea is that the defaultHandler of doesNotUnderstand would
produce a reasonable
approximation of a result based on the semantics and context in which
the call appears.

Here's the specific use case that I've been fighting with... I have a
virtual world in which objects can build other objects, and most objects are
unique.  Any object in the world can send any other object in the world any
number of messages to interact with it.  The limitations are defined in an
external dictionary of valid semantic actions, but no object is likely to
implement any more than 3-8 methods.

Since there is no programmer intervention in object creation, and the
messages passed need not even be sensical every action requires a sane
default.  The way I deal with this is subclass all of these objects from an
object that has its own custom doesNotUnderstand:aMessage.

Now the problems start to arise from users.  People are more clever than
objects that randomly evolve due to sexual reproduction. (surprising I know
:) and often have expectations of what the words they are typing mean,
independent of the implementation details under the hood.  In order to keep
in line with most of these expectations, I've hacked my
doesNotUnderstand:aMessage to return false by default.  I've been
experimenting with examining the context of the call as well to return sane
defaults.  My current hack is to force Boolean to respond to all of the
messages various strings, and numbers, also do, and return equivalent
values.

At the heart of this problem is that most professional Smalltalk programmers
understand the meaning of words, the semantics of messages, in terms of
their implementation semantics.  To the end user, however, their mental
model is based upon the semantics of both the real world, and the virtual
world that they think they understand.  Etoys made the system accessible by
focusing on the user's semantics over the semantics of implementation.  Well
written code that is a pleasure to read typically merges the implementation
and expressive aspects of the semantics into one coherent whole.



-- 
-=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090630/d6d62df5/attachment.htm


More information about the Squeak-dev mailing list