POV-Ray : Newsgroups : povray.advanced-users : Object Oriented POV code : Re: Object Oriented POV code Server Time
29 Jul 2024 18:18:14 EDT (-0400)
  Re: Object Oriented POV code  
From: Christopher James Huff
Date: 22 Feb 2004 11:29:18
Message: <cjameshuff-5800AC.11300022022004@news.povray.org>
In article <4038a02f@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

> Christopher James Huff <cja### [at] earthlinknet> wrote:
> > Pass everything by reference
> 
>   That can be problematic.
...snip...
> Int foo = container.size(); // <- gets a *reference*

No, that initializes an Int named foo to the object returned by 
container.size. Not a problem.
This was a problem in Sapphire...not a major one, but it required 
annoying additional code to create a copy. Now I have an additional 
syntax for creating variables:

def foo: val; //defines a variable foo attached to the value val
def foo = val; //defines a variable foo attached to a copy of val


>   The big problem is that since your variable is actually a reference
> to the original 'numberOfItems' variable, you'll end up breaking the
> container.

You could also introduce const references...not sure if its worth the 
trouble.

>   I don't know enough about Java to know how this problem is avoided
> there.

Java passes everything by value. Objects are only handled through 
references, those references are passed by value. And it will break in 
the way you describe above, but it isn't very common...in this case, you 
would use the primitive int type instead of an integer object.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

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