[Gambas-devel] Proper way to the current object

Randall Morgan rmorgan62 at ...176...
Sat Feb 11 23:07:47 CET 2012


Hi Benoit,

The reason for creating a new object containing the result was requested by
Juergen. He's the math wizard her, I am just trying to make the GSL work in
Gambas for him. However, I do feel after thinking about it that if most
methods save the result in the current method you limit the usuability of
the library. Most calculations will require the result to be passed to
another object. Now I am still learning about all of this so it could
change...

The code in the current files is nowhere near final and is there for
experimentation as for me that is the best way to learn.

The reason for creating  a separate complex number is because this
structure may change to include both accuracy information and may or may
not be modified to include information on whether the number
is Cartesian or polar. Both of which could also be included in a single
object. However, when I move to vectors and matrices these structures will
need to be separate structures and at the moment this gives me a way to
experiment with having a separate structure.

2012/2/11 Benoît Minisini <gambas at ...1...>

> Le 11/02/2012 20:24, Benoît Minisini a écrit :
> > Le 11/02/2012 20:23, Benoît Minisini a écrit :
> >> Le 09/02/2012 15:56, Randall Morgan a écrit :
> >>> Hi Benoit,
> >>>
> >>> I am a bit perplexed. I have some code that works and some that
> >>> doesn't...
> >>
> >> If a method or a property returns a "GslComplex", then its signature
> >> must use "GslComplex;" (or just "GslComplex" in a return value
> >> signature). Do not use "o", this is an anonymous object that you should
> >> use only if the method or property returns any object.
> >>
> >> And when you receive an object reference through GB_OBJECT, you must use
> >> GB.CheckObject() to check it (to ensure it is not null).
> >>
> >> Regards,
> >>
> >
> > Another point: Use NULL and not a void string for methods returning
> > nothing, and/or having no arguments.
> >
>
> Other points again.
>
> 1) Why didn't you use gsl_complex directly in the GSLCOMPLEX structure?
>
> 2) You chose to create a new Complex each time you act on it.
>
> Maybe this is not a good idea (for performance reasons). I think you
> should better:
>
> - Act on the current object without creating a new one, and return it
> anyway.
>
> - Add a Copy() method to copy a complex number when this is really needed.
>
> So here is the "not-tested" result:
>
> --------------------------------------------------------------------
>
> typedef
>   struct {
>     GB_BASE ob;
>     gsl_complex c;
>     }
>   GSLCOMPLEX;
>
> BEGIN_METHOD(GslComplex_Add, GB_OBJECT x)
>
>   GSLCOMPLEX *x = VARG(x);
>
>   if (GB.CheckObject(x))
>     return;
>
>   THIS->c = gsl_complex_add(THIS->c, x->c);
>   GB.ReturnObject(THIS); // GB.ReturnXXXX() methods return nothing!
>
> END_METHOD
>
> --------------------------------------------------------------------
>
> The code is simpler, isn't it?
>
> --
> Benoît Minisini
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Gambas-devel mailing list
> Gambas-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-devel
>



-- 
If you ask me if it can be done. The answer is YES, it can always be done.
The correct questions however are... What will it cost, and how long will
it take?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20120211/406cdded/attachment.html>


More information about the Devel mailing list