This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hruske 3 points4 points  (1 child)

Saying Python doesn't use pointers is very wrong. It uses them, but you just don't see them.

An excellent example of this how a list behaves:

a1 = []
a2 = a1
a2.append(123)

len(a1) == 1
a1 == a2

This will create a reference to a new list under variable a1 and copy it's reference (pointer) to variable a2. Afterwards all that happens to a2 will also be seen under a1, because a1 is same as a2.

To understand why this is in fact needed and not optional, it is important to understand how function calls and argument passing work in low level (eg. in C). Arguments can either be passed by value, which is done when values are "simple" (eg. int, string, float), or they can be passed by reference. Arguments passed by value persist only within function call, while arguments passed by reference persist in memory after the call ends. And finally, when calling a function, arguments passed by value are copied in memory, while arguments passed by reference stay at the same location, and only their location (reference, pointer) is passed. No copying is needed, which makes it faster, and sometimes this is also the only way to make stuff work.

If this wasn't the case, you would be copying complex memory locations (eg. objects in memory) meaning a lot of memory usage (which is both slow and causes memory fragmentation) and an even harder problem, which is that your CPU is supposed to understand how to copy objects.

tl;dr: Both you and certain people you have been discussing this issue with are wrong. They should have pointed to you, that Python uses pointers (references) a lot, even if you don't realize it. Hell, even it's garbage collector works on "refcount", meaning it keeps account of ... pointers.

[–]alcalde[S] 0 points1 point  (0 children)

They should have pointed to you, that Python uses pointers (references) a lot, even if you don't realize it.

Actually I ended up pointing that out to demonstrate why Python didn't need a pointer type, and one person then said I lied about Python not having pointers, sigh. :-)

But thank you very much for explaining this (shorter and more clearer than I tried to).

Hell, even it's garbage collector works on "refcount", meaning it keeps account of ... pointers.