« 1 common belief in the Domino community | Main| From the jokes-that-write-themselves dept. »

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

1 - Curious. Doesn't make sense to me either. I'll have to write this up and see what the language folks have to say.

2 - Nathan, why do you ask? Emoticon
IMO this is obviously an compiler bug. The usage of a type (derivedClass) never should depend on its implementation (with or without constructor).
Thomas

3 - Probably just a compiler bug, but there is one possibility that comes to mind... As you know, LotusScript's OOP is weird: it'll allow you to override methods in a derived class, but not overLOAD them... except for the constructor:

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.

4 - I pasted your code into Domino Design 6.0.4 and it compiled just fine. So it may be a regression bug with the version of Domino Designer you are using...

5 - Compiles fine in 7.01.

No run time error either when Instantiating wrapperclass.

6 - I think it was a mirage. I can't reproduce it either.

7 - Odd... Perhaps it NOT compiling was a one-time bug in Designer.

8 - Son of a B*@#%

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.

9 - I'm assuming the answer is "no", but just to be certain: did you "Use" any other libraries, or did you *ever* at some time? Maybe this started as a larger library and you stripped it down?

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.


10 - @8: Andrew, we definitely have to talk together. Emoticon
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

11 - @Andrew Pollack (#8):

I have to maintain one application that uses a bunch of derived classes and it's the most annoying thing in the world. Period. :-/

12 - @11 - Can you elaborate? I've had great success with maintenance in derived classes, so your statement surprises me.

What kind of annoyances do you have?

13 - It's just to complicate to have overview of subs or functions that are defined in different classes in different LS Libraries...

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?

14 - @11 & 13

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 }

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

11 Aug 

Hire Me 

Lotus-911-Logo.jpg

Search 

Disclaimer 

Welcome to Escape Velocity!

Opinions expressed here by Nathan T. Freeman are not necessarily those of his employer. However, there's a decent chance they are, so check with them if you really want to know.

But really... do you need that kind of validation? Are the opinions expressed here in doubt?

MiscLinks