[Gambas-user] How to stop "Greedy" constructors consuming parameters

Bruce bbruen at ...2308...
Sat Apr 20 09:51:46 CEST 2013


On Sat, 2013-04-20 at 15:08 +1000, Ian Haywood wrote:
> On Sat, Apr 20, 2013 at 11:13 AM, Bruce <bbruen at ...2308...> wrote:
> > I have a deep hierarchy of classes, seven levels of specialisation so
> > far and likely to grow.
> wow.
> 
> > At level 4, 6 dummy and the 2 real parameters, i.e.
> >         hObj = New
> >         Level4Class(Null,Null,Null,Null,Null,Null,Source,Name)
> >
> > This is becoming very painful.
> >
> > Is there any way to "turn off" the way constructors consume parameters?
> It's a core language design decision, so I doubt it.
> Personally instead of using the "official" constructor _new I often
> have a separate
> Init( ) function which is called immediately after instantiation
> 
> foo = New MyClass()
> foo.Init(someParameter)
> 
> Messy, but because .Init( ) is an "ordinary" function in the eyes of
> the the Gambas compiler, ancestor
> classes to not "consume" parameters in the same way, plus it is only
> overridden in the hierarchy when required.

That's what I was afraid of. :-( But, ces't la vie.
> 
> Unfortunately Gambas doesn't allow any change in function signatures,
> so if you wanted an extra parameter in a descendant
> constructor you would have to have an "Init2" method which then calls
> "Me.Init()"
> 
(Sshhh! There is a way around this, a 5 line change to gbx_class.c can
remove/disable the signature checking.  We have been running it for
quite some time (August, 2011) with none of the reported "failures" in
over 30 client sites. I can send you the diff privately if you want it,
but remember, it is very unsupported by Benoit.  It all started here:
http://code.google.com/p/gambas/issues/detail?id=78

cheers
Bruce






More information about the User mailing list