'Implements' not being enforced unless used
Monkey Forums/Monkey Programming/'Implements' not being enforced unless used
| ||
Hi all. I have just noticed that even if a class says it implements an interface, you can happy NOT implement it and the compiler does not care, so long as you don't call it. While it doesn't generate errors per-se it does mean that typos can go unnoticed and as you continue development you may find yourself having to debug a strange error down the track when you actually do use it. Here's an example: Interface I Method Do() End Class C Implements I Method Do(i:Int) ' Note the Int here End End ' This takes an actual C so all good Function GoAndDo(c:C) c.Do(20) End Function Main() Local c:C = New C() GoAndDo(c) End This all works fine, but it is a little inconsistent with what Interface implies I think. An error to tell you about unimplemented interface methods would be nice. Cheers Aaron |
| ||
An extension to this problem seems to be with globals. If I have Global thingy:SomeClass = new SomeClass() class SomeClass Method New() DoSomeInitisation() End end Then New() isn't called when the program starts. Is this expected behaviour? I use this way of working quite a lot in C++. The object gets created, and registers itself with some sort of other object in the constructor. |
| ||
Aaron, As you point out only the code that is actually referred to is processed. I believe Mark outlined the reasons for this at some stage. |
| ||
Hi Matt, thanks for that. Looks like I'll need to be a bit more careful then but it'd still be a nice addition I think. |