[Xotcl] Class unknown -> create is considered harmful
Ben Thomasson
ben.thomasson at gmail.com
Wed Jan 7 14:34:47 CET 2009
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://alice.wu-wien.ac.at/pipermail/xotcl/attachments/20090107/9060ad7c/attachment.html
More information about the Xotcl
mailing list