View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] Class unknown -> create is considered harmful

From: Ben Thomasson <ben.thomasson_at_gmail.com>
Date: Wed, 7 Jan 2009 08:34:47 -0500

Hi XOTcl developers,

I have been using XOTcl for a while and I have discovered that the default
implementation of the Class unknown method is harmful to large scale
development. The default implementation calls create from the unknown
method. Here is an example that shows the problem:

Class A

A nstproc doX {} { puts done}

A intsproc doY {} { puts done }

The problem here is that misspellings of class methods will cause objects to
be created instead of methods to be defined on the class. Here we will have
an object named ::nstproc and one named ::intsproc which are both
misspellings of instproc.

There is a simple fix for this:

Class proc unknown { args } {

error "[ self ] Unknown command: \"$args\""

}

Class instproc unknown { args } {

error "[ self ] Unknown command: \"$args\""

}

This will require classes and objects to be created explicitly with the
create or new method. I find this preferable to having mistakes silently
ignored. I have seen this problem in the wild as well as in my code.
XOTclIDE had several misspellings that were ignored until I loaded with my
fix. Of course existing XOTcl projects will have to be modified to
insert create methods where needed.

Ben Thomasson