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

Fabien Bodard gambas.fr at ...626...
Sat Apr 20 11:36:55 CEST 2013


The check is not done for the "_new" special method, as the inheritance of
_new is special (see "inheritance and constructor" in the "Gambas object
model" documentation on the wiki).


2013/4/20 Bruce <bbruen at ...2308...>

> 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
>
>
>
>
> ------------------------------------------------------------------------------
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



-- 
Fabien Bodard



More information about the User mailing list