POV-Ray : Newsgroups : povray.pov4.discussion.general : Next Generation SDL: What's wrong with Lua, JavaScript, ... : Re: Next Generation SDL: What's wrong with Lua, JavaScript, ... Server Time
14 Apr 2024 23:14:20 EDT (-0400)
  Re: Next Generation SDL: What's wrong with Lua, JavaScript, ...  
From: clipka
Date: 12 Apr 2009 07:15:01
Message: <web.49e1cc5be7a64ad834d4c3f10@news.povray.org>
"MessyBlob" <nomail@nomail> wrote:
> > > Sph = new Sphere( {
> > >   radius: 1,
> > >   position: [0,0,1]
> > > } );
>
> The class defines default property values in its constructor. Then when you
> create instances, you can optionally assign values to the properties. So the
> examples of 'radius' and 'position' are the names of the properties defined in
> the class. I think this is a very elegant way of instantiating objects, with
> syntax that is very similar to POV-Ray SDL.

Yes, but unless I'm mistaken, all you can do in the object's namespace at this
time is assign values. You cannot, for instance, call functions defined by the
contructor - you could only assign a different value to that function.

> Can you explain your thoughts on what the problem will be with this approach?
> Are you thinking of transformations? Method-triggering property
> assignments ('set' methods) achieve this, e.g. a "translate: [1,0,0]" property
> would call ".doTranslate([1,0,0])" to change the transform matrix just like the
> current SDL parser would. As I understand it, properties are set *after* object
> instantiation, even if they are evaluated before the instantiation.

Hm, maybe then I'm mistaken indeed. I'll have to investigate that.

But even then I must say that I'd actually not like the syntax - for POV needs,
it would mean an unreasonably large number of braces-inside-parentheses "({ ...
})" where only one type of brackets would suffice; and a host of "new"
statements which - as proven by current SDL - shouldn't really be necessary.
Not to speak of all the colons (":").

> The JavaScript way seems better than the 'predefined parameters' approach of
> most other languages, even when (with other languages) overloaded constructors
> (variants that have different types or number of parameters) are specified in
> the class.
>
>
> One weakness I see with this approach, is when POV-Ray SDL containers may have a
> number of children, e.g. with CSG, it might be better to use a ".add(new ...)"
> method call to add child objects to the list.

Shouldn't that, too, be possible using

new scene ({
    object: new sphere ({ ... }),
    object: new box ({ ... }),
    ...
})

(at least if I understand you correctly about the 'set' methods mentioned)


> (With apologies if I'm going over unnecessary background information; I don't
> know how much you, or a typical reader, knows about JavaScript or OO).

No problem here - I think the level of detail is just about right for me ;)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.