Lotusscript Compiler Weirdness
Perhaps someone smarter than I am can explain this...
Class baseClass
Private someMember as String
End Class
Class derivedClass as baseClass
Private someOtherMember as String
End Class
Class wrapperClass as baseClass
Property Get derivedObject as derivedClass
'some code
End Property
End Class
This fails in the Lotusscript editor when it compiles. (side note: the single most annoying aspect of Lotusscript is that custom classes have exactly ONE error message "type mismatch on external name." Apparently that's the only thing in the universe that can be wrong in a class.)
Keep reading for more details...
This...
Class baseClass
Private someMember as String
End Class
Class derivedClass as baseClass
Private someOtherMember as String
End Class
Class wrapperClass as baseClass
Property Get derivedObject as baseClass
'some code
End Property
End Class
...works just fine.
Turns out that the problem is whether the derived class has an explicit Sub New...
Class baseClass
Private someMember as String
End Class
Class derivedClass as baseClass
Private someOtherMember as String
Sub New
End Sub
End Class
Class wrapperClass as baseClass
Property Get derivedObject as derivedClass
'some code
End Property
End Class
...works just fine.
So my question, good reader, is WHY!?!?! Is there some OOP design principle at work here that I don't know? Or is this just a bug in the compiler?




Comments
Posted by Andre Guirard At 11:30:06 AM On 03/28/2008 | - Website - |
IMO this is obviously an compiler bug. The usage of a type (derivedClass) never should depend on its implementation (with or without constructor).
Thomas
Posted by Thomas Bahn At 11:47:42 AM On 03/28/2008 | - Website - |
Public Class Monkey
Public Sub New (MonkeyID As String)
'Construct yer monkey
End Sub
End Class
Public Class Marmoset As Monkey
Public Sub New (MonkeyID As String, MonkeyName As String), Monkey(MonkeyID)
'Construct yer marmoset
End Sub
End Class
So when you instantiate a marmoset, it knows it's a monkey, so it has to construct it as a monkey first before evolving (constructing) it into a marmoset. But because the base constructor requires a parameter, the compiler needs to know which parameter in the derived constructor to pass to the base constructor, hence the weird syntax.
In your initial example, there's no explicit constructor for either the base or the derived class, which implicitly means that you're not overloading or even overriding the constructor, so it shouldn't need a constructor definition for the derived class; it should just know that the new object will be passed through two empty constructors. But apparently it doesn't know that... so, um, yeah. My verdict is that it's a compiler bug.
Posted by Tim Tripcony At 11:51:07 AM On 03/28/2008 | - Website - |
Posted by Peter Presnell At 12:47:03 PM On 03/28/2008 | - Website - |
No run time error either when Instantiating wrapperclass.
Posted by veer At 02:44:03 PM On 03/28/2008 | - Website - |
Posted by Andre Guirard At 03:02:32 PM On 03/28/2008 | - Website - |
Posted by Nathan T. Freeman At 03:08:32 PM On 03/28/2008 | - Website - |
In all the years I've been writing LS -- and let me be clear, I can THINK in LS on a bad day -- I've never used or seen used a derived class.
Now that I've seen it, I don't think I'll use it. It doesn't seem to buy much.
Posted by Andrew Pollack At 06:36:15 PM On 03/28/2008 | - Website - |
There's some definite bugs with user-defined classes in LS libraries caused by some internal versioning timestamp. I'm convinced it was introduced via an SPR in late R5 -- I'll try to find it in the Fix List DB and post it.
But as a result you can now get "Type Mismatch on External Name" at runtime after editing a user-defined class in a script library. The fix? IBM's official fix is "Recompile All LS" but I've found that all you really need to do is perform a second edit-save on the single library that you touched. If I get a few free hours I'll submit it at some point. It's pretty ridiculous, and has to be some basic versioning/timestamp problem.
I'd guess that's what is biting you, especially since nobody else can reproduce it. The LS compiler gets stupid sometimes.
Posted by Erik Brooks At 09:20:01 AM On 03/29/2008 | - Website - |
Or talk with Bill Buchan. Or Nathan. ...
There ARE benefits in using OOP in LS, and this includes using class inheritance.
Thomas
tbahn@assono.de
Posted by Thomas Bahn At 03:05:25 PM On 03/30/2008 | - Website - |
I have to maintain one application that uses a bunch of derived classes and it's the most annoying thing in the world. Period. :-/
Posted by Tihomir Pantovic At 06:50:43 AM On 03/31/2008 | - Website - |
What kind of annoyances do you have?
Posted by Nathan T. Freeman At 07:11:25 AM On 03/31/2008 | - Website - |
In my exact case, I have a dozen of derived classes { Link } and IMHO it's more complicate to browse trough them than in some other RAD tool...
Are You using just Designer or some 3rd party tools?
Posted by Tihomir Pantovic At 02:10:34 PM On 04/03/2008 | - Website - |
OO gives you polymorphism (go wikipedia OOP), which gives you the ability to distill patterns out of chaos.
Designer is admittedly a dog when it comes to OO, so try using this free tool from Craig Schumann -> { Link }
Posted by Colin Macdonald At 11:51:14 PM On 04/03/2008 | - Website - |