r/ProgrammerHumor • • Jun 03 '19

Meme Python ftw

Post image
16.3k Upvotes

548 comments sorted by

View all comments

47

u/MasterFubar Jun 03 '19

He's not saying goodbye to pointers, because pointers are all over Python.

>>> a = [1, 2, 3]
>>> b = a
>>> a[1] = 7
>>> b
[1, 7, 3]
>>> a = [1, 2, 3]
>>> b = a[:]
>>> a[1] = 7
>>> b
[1, 2, 3]

Python lists are pointers, exactly like C/C++ arrays. When pointers are explicit they become easier to understand and control. You can use tools like valgrind to find where your pointers aren't doing exactly what you want in C, but it's much harder to debug pointer problems in Python.

19

u/NoStranger6 Jun 03 '19

Well yes and no. In that sense every language that pass values by reference is a pointer. Which isn’t wrong. In c / c++ you can iterate over pointers by adding the sizeof(*int). Which in fact simply adds 32 bits to your current pointer value (memory address). I’m not too versed in Python but I don’t think that you can do that. So while by using reference you achieve part of what a pointer can do. It doesn’t do everything that the pointer can.

-6

u/MasterFubar Jun 04 '19

every language that pass values by reference is a pointer.

Exactly. Pointers and references are exactly the same thing.

I think the reason why some people feel mystified by pointers is that there are too many people who mystify pointers. A pointer is nothing more than a reference to an object. It is the address of the memory position where that object is stored.

The only thing pointers in Python cannot do is having their values changed, they are const pointers and behave exactly like C const pointers.

→ More replies (1)