On Sat, Aug 19, 2017 at 12:43 AM, Stefan Ram <r...@zedat.fu-berlin.de> wrote: > Ben Bacarisse <ben.use...@bsb.me.uk> writes: >>Steve D'Aprano <steve+pyt...@pearwood.info> writes: >>>"Java is call by value, dammit!" >>I don't think this is a fair point. You will run out of ideas if they >>are to be avoided because some people will get the wrong idea when >>reading part of a description of that idea applied to some other language. > > You are trying to cool off the topic. An expression such as > "da...t!" should be avoided in a cold topic. But otherwise, > "Java is call by value." is just fine. > > The rest has nothing to do with calls, but with expressions. > > What happens in Java (Python and JavaScript are similar), > when this piece of code is executed? > > { final java.lang.Object object = new java.lang.Object(); > java.lang.System.out.println( object ); } > > In C terms, the value of »new java.lang.Object()« is an > address. The evaluation of »object« in the next lines yields > an address. This address then is passed to println. > > Python and JavaScript both want to be "higher-level" in this > regard and avoid words such as "address", they use other > means of description. Java is in between: it speaks of the > addresses, but calls them "references".
It doesn't matter. What happens, in any sane language, is that the object gets printed out. (In C, you'd have to somehow tell the println function that it's getting an object. In C++, that would be handled by operator overloading in cout, or somesuch.) You aren't printing out the object's address - you're printing out the object. You pass the object, not the address of the object. Details of memory locations etc are important if you care about the implementation, but that's all. In the same way that "x = 1" means that x now has the value of 1, your code snippet is going to print the value of the new object, one way or another. ChrisA -- https://mail.python.org/mailman/listinfo/python-list