Clear code is the best code.
Shawn Lau wrote:On a register level, they work exactly the same. Is there a technology on the horizon where computers are going to be register free? That's the part I was criticizing, like it somehow looks different than any other language when its spit out into assembly.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Shawn Lau wrote:Well what do you think they are? How do you suppose the CPU finds the data without using an address register?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Shawn Lau wrote:Wrong. It passes the starting address of the 3.5 magabyte picture.
And that's a very important consideration when writing a program, because I believed the documentation, and was very nervous about passing large objects to methods. But no, the objects aren't separate copies.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
It passes the reference to that picture, and you have no idea what that is, because you have no idea how that object is mapped in memory.
Clear code is the best code.
Clear code is the best code.
Clear code is the best code.
Shawn Lau wrote:A reference isn't an object. Its an address of an object. No amount of philosophy is going to change that fact.
Paul Clapham wrote:
Shawn Lau wrote:A reference isn't an object. Its an address of an object. No amount of philosophy is going to change that fact.
Abstractly speaking a reference is an "address" of an object. But it may or may not be implemented as a 32-bit (or 64-bit) quantity which contains the actual memory address of the object; it may be more complicated than that, for example to support garbage collection. It's entirely up the writers of the JVM to make that decision. But yes, from the abstract point of view a reference is an address.
Hopefully you don't consider an abstraction to be "philosophy". It's a very important tool in the design of computer languages and demanding to know how things actually work inside the abstraction is not especially useful when trying to understand modern computer languages.
Clear code is the best code.
Shawn Lau wrote:You don't care how it comes and yet you scoff that I know how it comes. Well it doesn't come by telegraph. The CPU pushes a memory address (A POINTER) into an address register and that's how the data is accessed. Is not mystical. It been the same flow for 40 years.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Shawn Lau wrote:An NO double NO NO a reference isn't an object. Its an address of an object. No amount of philosophy is going to change that fact.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
To be more specific, when it follows a period it matches anything that follows - like load("mypic.*"); That's just the common use of the wild card and to use it differently is eccentric.
You've never heard of a register variable? What do you think that is
I'm not trying to belabor this, but some things I've read are just plain wrong. I've read java passes everything by value. So if you have a big old 3.5 megabyte picture in memory, java passes that by value. Wrong. It passes the starting address of the 3.5 magabyte picture.
A reference may hide a handle rather than a pointer. A pointer must point to the exact memory address. You use direct indexing for one and you use indirect indexing for the other. And that is not a philosophical statement. The fact that Java® fortunately hides all those details from you doesn't mean they don't exist.Shawn Lau wrote:. . . Whats the practical difference between a method and a function? Reference - pointer? Any difference? . . .
"Java passes everything by value. There is no getting around that fact. "
Clear code is the best code.
It is difficult.Campbell Ritchie wrote:That might be because of the difficulty many people have moving from procedural programming to thinking in object.
Clear code is the best code.
Campbell Ritchie wrote:
A reference may hide a handle rather than a pointer. A pointer must point to the exact memory address. You use direct indexing for one and you use indirect indexing for the other. And that is not a philosophical statement. The fact that Java® fortunately hides all those details from you doesn't mean they don't exist.Shawn Lau wrote:. . . Whats the practical difference between a method and a function? Reference - pointer? Any difference? . . .
I think a lot of this has been said already. I also think this discussion is no longer suitable for the “beginning” forum and I shall move it.
Clear code is the best code.
I'm embarrassed by how steadfast I was in this thread. I should not post after a few beers. But this just isn't true. I'm working with very big graphics objects in java, and its physically impossible they are being passed by value.
(although in Java it can be a magical lamp).
Clear code is the best code.
Stephan van Hulst wrote:Shawn, I hope this has made it clear why we say Java passes everything by value? The thing is that the only values Java can pass are primitives and references. Passing an object by reference is different from passing a reference by value, as I've tried to explain with my examples.
Clear code is the best code.
Clear code is the best code.
Clear code is the best code.
Shawn Lau wrote:For me it was confusing, and I think its misstated. When something is passed by value, a copy is passed. Saying its passed by value because a copy of its location is passed, is a loop hole.
Shawn Lau wrote:If I pass something to a method by value, that method should not change the variable I passed whether the variable is an integer or an object. The fact that it does shows it is not passed by value, but its location is passed by value.
Shawn Lau wrote:That's very thin ice to claim everything is passed by value. With that loop hole, any language could make that claim. The problem with misstating what is really happening, is it has you changing the way you design things because you take it at its word that is going to be copying your giant object, and that would be a performance issue. But the fact is it doesn't copy the giant object. It just claims it does. It copies the giant objects address or location which is exactly what C does.
Shawn Lau wrote:Here's a rough example:
int a = 10;
doStufftoInt( a);
System.out.println(a) and it print 10 no matter what dostuff() did.
Oh but if
BufferedImage bi; // bi is null
myLoadImage(bi) // bi now contains an image.
Shawn Lau wrote:Here's a better way to describe it, but I have to do it on an assembly level.
Shawn Lau wrote:Passing a variable by value works like this.
a = 10;
An address in the stack area of ram holds that value of ten.
dosomething(a);
The value of a - in this case 10, is put into a data register and a function ( er method) is called. There is no more connection with that stack area that put the 10 into the data register. That's why the local variable a can't be changed. There is no connection to it after the value is put into the data register. It was passed by value. Its just a value in a data register that will be lost when the function ends. The data register has no idea where it got it. But when you pass something by reference or pointer, you don't copy something into a data register, but you copy the location of the data into an address register. In this case, the data survives AFTER the function. Its in ram, not in a data register. It might be on the stack, but it might be somewhere else- like a global or some other functions stack. It can be changed by the the method it is used in, because it is not in a data register, but in ram. The changes are pushed into ram and are permanent changes, not function life changes.
Dave Tolls wrote:Every time I see this discussion I think "surely this is the last time", but it seems to reappear every few years.
I've been living in hope for over 15 years.
Clear code is the best code.
but it certainly is not being placed directly onto a register since registers aren't big enough to hold 1MB of data
Clear code is the best code.
Shawn Lau wrote:
Dave Tolls wrote:Every time I see this discussion I think "surely this is the last time", but it seems to reappear every few years.
I've been living in hope for over 15 years.
And why do you think that is? Something isn't being presented quite right or people who have been programming for decades on very low levels don't understand the difference between passing by value and passing a memory location?
Shawn Lau wrote:
but it certainly is not being placed directly onto a register since registers aren't big enough to hold 1MB of data
no. its placed onto the stack and its memory location on the stack is sent to the function. If as in the old days, you had 32 kilobyte stack, trying to initialize a 1mb array would gain you a stack overflow error. So now, lets say you have an unlimited or gigabyte stacks. When a function is done, the stack ( for that function) is GONE. Its not a permanent thing, it lasts as long as the function.
Clear code is the best code.
Consider Paul's rocket mass heater. |