|
![](/i/fill.gif) |
In article <4038a02f@news.povray.org>, Warp <war### [at] tag povray org>
wrote:
> Christopher James Huff <cja### [at] earthlink net> 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] earthlink net>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tag povray org>
http://tag.povray.org/
Post a reply to this message
|
![](/i/fill.gif) |