Re: News for Java?
On Jan 4, 9:26 am, Tim Slattery <Slatter...@bls.gov> wrote:
Travers Naran <tna...@gmail.com> wrote:
Passed by reference: *splurts coffee* am I the only programmer that
hates this? I hate sending 10 parameters in when I can just send in a
class/structure.
And objects are passed by reference. All non-basic Java variables
(everything except char, int, float, double, boolean...) are
references to an object.
Let me clarify. My understanding of pass by reference, in this C#
context, is:
public void createStream(out StreamClass b) {
b = new StreamClass();
}
public void main() {
...
StreamClass b = null;
createStream(b);
// b is now magically filled with a reference to a new StreamClass
}
It's _this_ kind of C# pass by reference I am opposed to. In OOP, I
don't believe one needs this kind of pass by reference for anything.
I can think of maybe one case for optimization:
class Coord {
public void toPixelXY(out int x, out int y) {
x = ...;
y = ...;
}
}
In this case, the overhead of creating a new class just to pass two
integers back may be overkill. But I'd still say, "Profile first,
Optimize Second". Also, one could use instead:
class WorldCoord {
public void toPixelXY( PixelCoord coord ) {
coord.x = ...;
coord.y = ...;
}
}
Which could potentially be just as efficient, especially in case like:
PixelCoord pc = new PixelCoord();
for {i = 0; i <= MAX_POINTS; i++ ) {
wc[i].toPixelXY(pc);
// Draw with pc
}