[DGD] New DGD user introducing himself...

Troels Therkelsen troels at 2-10.org
Sat Sep 1 13:11:52 CEST 2001


> > With all the strict typing going around, and the addition of LWOs, I have to
> > say I'm curious why you can't type objects ala Java, eg.,
> >
> >   void func(object /lib/lwo/sorter obj);
> >
> > Then func() would only accept objects either inheriting /lib/lwo/sorter or
> > being that object themselves.  Without this object typing, basically all
> > your objects are 'mixed'.  Especially with LWOs and passing them between
> > functions, it would be very convenient to have the runtime system do the
> > type checking for you.
>
> Easy to do yourself (which is a common theme in DGD):
>
> * Put a nomask function in /lib/lwo/sorter.c with a known name, for
>   instance like this:
>
>   nomask void   __lib_lwo_sorter() {}
>
> * Do a check for function_object(the-function-name, obj) to see if it
>   is indeed the one in /lib/lwo/sorter like this
>
>   object obj_fo;
>
>   obj_fo = function_object("__lib_lwo_sorter", obj);
>   if (!obj_fo || !object_name(obj_fo) != "/lib/lwo/sorter") {
>       error("Bad argument 1 to function func");
>   }
>
> Of course you can wrap this stuff in some macros to make life easier.
Yea, DIY seems to be the mentality behind DGD; if it's possible it can be
done in LPC, the driver will not support it, even if the resulting LPC
code to do it is (a little bit) hackish.  Which I personally happen to
agree with, actually.
Thanks for the viewpoint and idea on how to do this, I will definitely use
it :)

> > Maybe too Java-ish for LPC, I dunno.  This certainly is a Java-ism:
> >
> >   FACTORY:
> >   object sorter() {
> >     object ret = new_object {
> >       int compare(int a, int b) {
> >         return ((a == b) ? 0 : ((a > b) ? -1 : 1));
> >       }
> >     }
> >
> >     return ret;
> >   }
> >
> >   A:
> >   int *arr = ({ ... });
> >
> >   arr = sort_array(arr, FACTORY->sorter());
>
> And how is this different from having some utility functions in a
> library object that you inherit and then use?
>
> Quite possibly I missed the point of the example, though. *grin*
Hrm, now you raise the question, the only difference I can see is that
with the code snippet above you can create LWOs which doesn't have to have
been loaded from a file.  And I'm dubious as to whether that's such a hot
idea, after all.

I guess I need to kick a few Java habits or at least be able to subdue
them when I code DGD LPC ;-)

> Welcome aboard and you can leave the ranting to me, you can do the
> rambling if you want. ;-)
Hehe, deal!  *starts rambling* Now, back in the old days... *voice trails
off*

Anyway, thanks for the rapid and open minded response, I really appreciate
it :-)


Regards,

Troels Therkelsen

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list