On Mon, Aug 18, 2008 at 10:41:23AM +0200, Arne Goedeke wrote:
Actually, no. I do not want to have objects that are subclasses of basic types. I just want them to be casted to basic types where appropriate and possible.
deciding where it is appropriate and possible is the hard issue. not all places where it is possible also make it appropriate, therefore this decision must be an explicit one in the code.
I am not sure about that. The discussion is about fun(Int()) vs. fun((int)Int()). Its necessary to check the type of arguments at runtime anyway. At least for cmods its done automatically when using PIKEFUN, etc. Would not be to hard to implement a cast at that point. For native pike code its of cause different, but I guess that would not be too hard either. Still there exists quite some c code that would require hand-made changes (builtin_functions.c, etc). Also the type checker should never complain about object arguments at compile time then..
if you want a class that is casted automatically then this fact needs to be codified in the class. and inheriting a basic type would be one way to do that.
One could argue that that is encoded in the cast method and can be checked at compile-time only.
I am not sure if having automatic casts would do more harm than good. As I said before, it certainly adds new traps and hides things from someone who is reading code, looking for bugs, etc.
arne