Scripting Language

Everything about development and the OpenMW source code.
User avatar
psi29a
Posts: 5361
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: Scripting Language

Post by psi29a »

ezzetabi wrote:Alex Martelli is NOT confused.
^-- Could not agree more.
Yacoby
Posts: 119
Joined: 30 Sep 2011, 09:42

Re: Scripting Language

Post by Yacoby »

Ok, sorry. I just read general posts. Although since when is SO rep (Still in the top 1% at SO) a good measure of knowledge? (Although the other stuff, sure). However I read his post an no where does he mention that it is pass by reference. In fact he goes as far as to call it "by object reference", which is what I would call passing references by value. This is nothing new, I point you to the Java Language Specification, which was equally written by knowledgeable people, and also uses "References" and exibits this behaviour (Mentioned by Martelli)

Code: Select all

def bar(b): b.append(2)

z = []
bar(z)
print z
>>> [2]
and Java Language Specification it clearly states that Java is Pass by Value.

The most common non scientific definition of pass by reference and pass by value I have heard is: can you write a simple swap function? If not then it is pass by value. You can't write a swap function in python without looking at the stack.
Yacoby
Posts: 119
Joined: 30 Sep 2011, 09:42

Re: Scripting Language

Post by Yacoby »

Overall this is a very silly debate though :D
ezzetabi
Posts: 407
Joined: 03 Feb 2012, 16:52

Re: Scripting Language

Post by ezzetabi »

I agree... it is really silly because the main problem is that Python is neither pass-by-value or pass-by-reference.

I just got a little annoyed reading that you said that Martelli was ``confused''. Sorry.

I had the honor to meet Martelli at the Europython of the last year; since I was a yellow shirt (people in the organization who help) I could talk with him few times and I can tell you he is seriously sharp and he worked directly in the development of the language. About that... do anyone was in the Europython?

So... I think the best way to close it is... quoting Martelli that explains the semantics:
The semantics of argument passing are _exactly_ identical to that of assignment (binding) to a barename; you can fruitfully see argument passing as local (bare) names of the called function being assigned initial values by the caller (that's exactly what happens, in practice).
And post a simple python2 code example that shows how Python is different from Java or C++.
I executed it and I read again what Martelli said, everyone interested should do the same. I think that once we understood the semantics the actual name is fairly unimportant. The python tutorial calls it ``call by object reference''

Code: Select all

def f(x):
    print id(x)
    x = ( x + 1 )
    print id(x)

def g(x):
    print id(x)
    x.append(1)
    print id(x)

a = 0
b = []

f(a)
print id(a)
print a

print

g(b)
print id(b)
print b
Yacoby
Posts: 119
Joined: 30 Sep 2011, 09:42

Re: Scripting Language

Post by Yacoby »

That is exactly how Java works, and that example clearly shows object references being passed by value. ;)


Whatever you want to call it, feel free, but it isn't pass by reference.
User avatar
Tes96
Posts: 232
Joined: 29 Feb 2012, 03:45
Location: Off-grid

Re: Scripting Language

Post by Tes96 »

Isn't D language the "next generation" of code, as opposed to C++? I'm just trying to think outside the box here. People won't always be using C++ and probably D will be the norm. Will you guys be coding/scripting in D or C++? I have no idea what the differences are between the two, though.
User avatar
werdanith
Posts: 295
Joined: 26 Aug 2011, 16:18

Re: Scripting Language

Post by werdanith »

Tes96 wrote:Isn't D language the "next generation" of code, as opposed to C++? I'm just trying to think outside the box here. People won't always be using C++ and probably D will be the norm. Will you guys be coding/scripting in D or C++? I have no idea what the differences are between the two, though.
Sorry to be this blunt, but you've just wandered into an art galery and argued that post-modern poetry is the future of architecture. :D
User avatar
Tes96
Posts: 232
Joined: 29 Feb 2012, 03:45
Location: Off-grid

Re: Scripting Language

Post by Tes96 »

werdanith wrote:
Tes96 wrote:Isn't D language the "next generation" of code, as opposed to C++? I'm just trying to think outside the box here. People won't always be using C++ and probably D will be the norm. Will you guys be coding/scripting in D or C++? I have no idea what the differences are between the two, though.
Sorry to be this blunt, but you've just wandered into an art galery and argued that post-modern poetry is the future of architecture. :D
Haha, well, shows what I know, huh? :mrgreen: :geek:
ezzetabi
Posts: 407
Joined: 03 Feb 2012, 16:52

Re: Scripting Language

Post by ezzetabi »

Yacoby wrote:That is exactly how Java works, and that example clearly shows object references being passed by value. ;)

Whatever you want to call it, feel free, but it isn't pass by reference.
It is not how Java works. In Java you always copy the variable value. For objects those values are references.
Java calls them references, but they are exactly the same as the C pointers so much the exception is NullPointerException. Just you cannot do arithmetics.
I also posted a piece of code to show it: the int in the f function after the call and the int outside is the same, in Java it would not.
Unfortunately you cannot easily replicate the piece of code in Java as there is no obvious way to get the memory address of a variable (the Python id() ).

It is more similar to C++ call passage denoted with the amp (e.g. void f(T & t); I do not care about the names anymore.)
On the other hand it still works differently. Just read the assignment, Python creates a new name x for the result of the expression (x + 1) the new name does not touch the one outside the function.

Just think whatever you like. I wont bother you anymore about the argument.
Yacoby
Posts: 119
Joined: 30 Sep 2011, 09:42

Re: Scripting Language

Post by Yacoby »

ezzetabi:
You probably have a better understanding of this than me. I will come back and take a better look later when I am less ill and have less coursework. However,
I also posted a piece of code to show it: the int in the f function after the call and the int outside is the same, in Java it would not.
Unfortunately you cannot easily replicate the piece of code in Java as there is no obvious way to get the memory address of a variable (the Python id() ).

It is more similar to C++ call passage denoted with the amp (e.g. void f(T & t); I do not care about the names anymore.)
On the other hand it still works differently. Just read the assignment, Python creates a new name x for the result of the expression (x + 1) the new name does not touch the one outside the function.
A better example for Java would be that the functions are void f(T* t); This is because Java is pass by value and not pass by reference. This can be seen in this example: http://ideone.com/QHGkg
Post Reply