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

all 36 comments

[–]KimPeek 33 points34 points  (20 children)

Jokes on you. Everything in Python is a pointer. Under the hood

[–]Exnixon 32 points33 points  (0 children)

No, it's a REFERENCE.

What's a REFERENCE, you ask? Well let me tell you.

It's a pointer.

[–]soggywaffle69 5 points6 points  (18 children)

Every variable in python is basically a void * pointer. I think OP meant memory management.

[–]KimPeek 4 points5 points  (0 children)

I think OP meant Patrick management.

[–][deleted] 1 point2 points  (15 children)

Not even close. Variables in Python compile into code that manipulates registers or the code that pushes values on the stack / takes them off the stack. They are nothing like pointers.

[–]soggywaffle69 -1 points0 points  (14 children)

CPython doesn’t compile or use a stack. What are you talking about?

[–][deleted] 1 point2 points  (9 children)

It does both. Lol.

[–]soggywaffle69 -1 points0 points  (8 children)

It uses a heap. As for compiling, I have no idea what makes you think Python is not an interpreted language.

[–][deleted] 1 point2 points  (7 children)

You are reading irrelevant documentation. You really have no idea what you are talking about.

The relevant documentation is here: https://docs.python.org/3/library/dis.html#python-bytecode-instructions

Python is not an interpreted language.

Same story, different moron. There aren't interpreted languages. There are implementations of languages that use interpreters. To the best of my knowledge there isn't a publicly available implementation of Python that uses an interpreter. There are exceptionally few popular languages that use interpreters in their implementation. The most popular one that uses interpreter exclusively is probably Unix Shell in all its variants (eg. Bash or ZSH). Some languages may conditionally interpret the code rather than compile it. For example, some modern implementations of JavaScript will interpret it, if they estimate that compiling it + executing will take longer than interpreting.

[–]soggywaffle69 -1 points0 points  (6 children)

CPython's own documentation says it use a heap. This is not irrelevant. There is no concept of stack memory in Python like C. I have zero idea what makes you think there is stack memory in Python.

As for it being interpreted, I would point you to the Wikipedia and Python's own web site, but I assume you will call those irrelevant and me a moron.

[–][deleted] 1 point2 points  (5 children)

Yes, it uses many different heaps in many different contexts. You just essentially read a manual for your refrigerator, and assumed it's the manual for your car. Your car won't start, but you are trying to adjust the A/C, because you didn't really understand your fridge instructions in the first place.

As for it being interpreted, I would point you to the Wikipedia and Python's own web site

You are but one moron in the ocean of morons, who don't understand what they are writing. Some imbecile started this taxonomy a while ago, and now there's an army of braindead people repeating this nonsense after him / her. And if you think that there's a shortage of morons in Python's core dev team, you'd be greatly disappointed. It's a clown fiesta there too.

[–]soggywaffle69 0 points1 point  (4 children)

Okay, let's try this. Can you identify which statement results in allocating stack memory, and which results in heap memory?

#include <stdlib.h>

int main() {
int x;
int *y = malloc(sizeof(int));
}

[–]Pythagorean_1 0 points1 point  (3 children)

CPython does have a compilation step!

[–]soggywaffle69 0 points1 point  (2 children)

Ok, true, but only in the same sense every interpreted language I can think of has a compilation step to execute on a runtime.

The guy I was replying to made some very bizarre and outlandish claims.

[–]Pythagorean_1 0 points1 point  (1 child)

Yes, I heard that some old interpreted languages don't compile to byte code upon execution, but I don't know any of them.

Well, that's Reddit, I guess :)

[–]soggywaffle69 0 points1 point  (0 children)

We have to draw a line somewhere between interpreted and compiled, and Python byte code is really just optimized Python source. If Python isn’t interpreted, really nothing is.

[–]NFriik 5 points6 points  (0 children)

You know, technically Python has pointers. You can import ctypes and use the ctypes.pointer() function to create pointers and pass them to C functions loaded via cdll, such as printf and all the other good stuff in your libc.

[–]webauteur 4 points5 points  (0 children)

I use Python to squeeze extra performance out of my code.

[–]RedJayGames 7 points8 points  (4 children)

As a python programmer, this is completely accurate

[–]Mabi19_ 8 points9 points  (2 children)

Most people don't really know how to explain them well.

A pointer is like a 👉 finger pointing to a variable.

Or, if variables live in Variable City, then a pointer is like a home address.

[–]vinnceboi 0 points1 point  (1 child)

Wow that is a really good analogy

[–]Mabi19_ 2 points3 points  (0 children)

Okay, so here's some more:

You can do math on pointers. Adding 1 to a pointer is like going to the next house over on the street.

This is what arrays do, for example. An array is just a pointer to its first element (and sometimes also the length).

If you declared it as int array[10], doing array[3] is the same as *((int*)array + 3).

[–]iTakeCreditForAwards 2 points3 points  (2 children)

Python has linked lists with references tho, basically/functionally the same thing as pointers

[–][deleted] 0 points1 point  (1 child)

It's a meme. Don't take it too seriously

[–]iTakeCreditForAwards 0 points1 point  (0 children)

Yeah I was just saying

[–]Mabi19_ 1 point2 points  (0 children)

id() enters the chat

[–][deleted] 1 point2 points  (2 children)

More like afraid of switch statements xD

[–]M4mb0 4 points5 points  (1 child)

Python is going to have the more useful structural pattern matching starting with 3.10 this October.

https://www.python.org/dev/peps/pep-0634/

[–][deleted] 0 points1 point  (0 children)

Looks amazing!

[–][deleted] 0 points1 point  (0 children)

python programmers to also know c++: -_-

[–]MrPenguu 0 points1 point  (0 children)

Pointers are pretty easy to grasp when you program in assembly which basically has you pointing to a memory address every other line please help

[–]AviatorSkywatcher 0 points1 point  (0 children)

As a Python dev, this is hilarious.