Pass variable by reference

Chris Angelico rosuav at gmail.com
Tue May 6 22:39:34 EDT 2014


On Wed, May 7, 2014 at 12:18 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> Wrong conclusion!
>
> These 3 lines look the same and amount to much the same in python and C.
>
> But as the example widens to something beyond 3 lines, the difference
> will become more and more significant

Python, C, REXX, BASIC, and pretty much anything else with a broadly
imperative style.

The thing is, though, the difference between one language's variable
semantics and another's is similar to, as Ned said, the difference
between one language's integer semantics and another's. What happens
in C when you do this?

x = 1 << 31;
x += x;

The only possible answer is "it depends", as you can't know how big an
int is, but certainly it's of finite size. In Python, the equivalent
is guaranteed to put 2**32 into x, because integers store arbitrary
precision. That's a pretty important difference, yet we're happy to
call both "integer". A Python list is very different from a LISP list.
A Python array is very different from a Pike array. A Python function
is very different from a mathematical function. Why do we object to
the difference in "variable" but not the others?

Yes, there are differences. That's why we have different languages;
you can't do a minimalist transformation of source code and expect
exactly identical semantics. But we start with familiar names that
will give people some idea of what's going on.

ChrisA



More information about the Python-list mailing list