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
Dear Ben,
i do agree with you, that the default unknown handler for classes/metaclasses is harmful. i prefer as well the explicit create/new statement for various reasons.
The handler is a heritage from OTcl, and the reason XOTcl keeps the heritiage is backward compatibility. Many programs simply use unknown....
However, maybe we should mark its usage as deprecated and remove it in future versions, such as XOTcl 2.0....
best regards -gustaf neumann
Ben Thomasson schrieb:
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
Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
On 7 Jan 2009, at 15:45, Gustaf Neumann wrote:
i do agree with you, that the default unknown handler for classes/metaclasses is harmful. i prefer as well the explicit create/new statement for various reasons.
The handler is a heritage from OTcl, and the reason XOTcl keeps the heritiage is backward compatibility. Many programs simply use unknown....
However, maybe we should mark its usage as deprecated and remove it in future versions, such as XOTcl 2.0....
As someone who has stumbled across this as well, I would vote for deprecation. I always use 'new' anyway.