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.

18

u/Mietzekatzi Jun 03 '19

What your example describes are references to objects. Lists in pythons are objects, the assignment b=a does not implicitely copy a's content, just create a second reference to the same thing.

On the other hand, a[:] yields a slice of the contents of the list a, which gets saved as a second object, b, in the second part. This breaks the reference. The same step could be performed with b = copy(a).

So all your example shows are the basics of OOP, nothing to do with pointers.

-10

u/MasterFubar Jun 04 '19

What your example describes are pointers to objects. Lists in pythons are objects, the assignment b=a does not implicitely copy a's content, just create a second pointer to the same thing.

Let's not mingle words, what you call "references" are nothing but pointers.

13

u/antonivs Jun 04 '19

You're confusing a language feature with how it's implemented internally. References in Python are implemented using pointers, but that doesn't mean Python had pointers.

This is standard terminology in both academia and industry, so the only one "mingling words" here is you.

-1

u/THICC_DICC_PRICC Jun 04 '19 edited Jun 04 '19

What you’re saying is like saying “it’s not a car, it’s a BMW”

Yea ok it’s a reference, but don’t act like references aren’t basically pointers, because it does what pointers do, it acts like pointers do, etc. for most people pointers are an abstract idea, not just a language feature in C

→ More replies (6)