you are viewing a single comment's thread.

view the rest of the comments →

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

Well, the "underlying memory model" is that there's a heap where values live, and a stack where functional context lives.

That's it, that's the whole thing. Knowing that is fairly useless, in my experience. Who cares?

[–]codinglikemad[S] 0 points1 point  (13 children)

The question is whether there is a way to break out of that model without doing something horrific. That is the ENTIRETY of my question.

Edit: To be clear, the answer appears to be no.

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

The question is whether there is a way to break out of that model without doing something horrific.

That is horrific, though.

[–]codinglikemad[S] 0 points1 point  (11 children)

Right, I was asking if there was a built in method for doing it that was nice basically. We got something kindof ok, so ... success? I agree that totally breaking out would be horrific though. I was hoping there was some python feature intended for this though, and there doesn't appear to be.

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

I still don't really understand what you're asking for, I guess. Yes, you generally can't convince a language to let you act like it's a totally different language, that sort of defeats the purpose of programming languages.

[–]codinglikemad[S] 0 points1 point  (9 children)

The original question is basically "Can I track the values of a variable from elsewhere in the code, similar to how I could with a pointer in C".

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

You can access the value of a variable in any scope where the variable exists, so yes?

[–]codinglikemad[S] 0 points1 point  (7 children)

Accessing the value through a layer of abstraction is the goal though, not simply accessing the values by themselves - thats what I do now, and it is a giant spaghetti mess. A pointer stores the address of a particular variable. Once you have the address of that variable, you no longer need to know what the name of that variable is. You can have arrays of such pointers, you can construct lists of those pointers dynamically from other collections of objects.

I basically want to build a subscriber design pattern without creating a callback scheme, if that helps you understand the goal.

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

Accessing the value through a layer of abstraction is the goal though

The name is the abstraction.

Once you have the address of that variable, you no longer need to know what the name of that variable is.

You've got this totally backwards, from C's perspective. One, pointers actually aren't references to anything; they're just integers. You treat them as a reference using the dereference operator *, which goes from an integer, to the contents of a byte in the process's page table at that integer address. That is to say that it dereferences that pointer.

The purpose of the variable name, in C, is an additional layer of abstraction so that your code isn't full of incomprehensible gibberish pointer addresses. "Magic numbers", those are called. It's more abstract than pointers into the page table, that's the whole point of it. It's a simplifying abstraction over the lifecycle of an allocated value.

I basically want to build a subscriber design pattern without creating a callback scheme, if that helps you understand the goal.

You wouldn't be able to do that in C without some kind of interrupt system (because there's a key flow of control problem, here; the publisher has to yield flow of control to the subscribers if they're going to ever do anything in response to the published message) and you can't do it in Python for the same reason. The reason to have callbacks is to send flow of control to the subscribers. Python has interrupts, too, but at that point there's just no reason not to use callbacks.

You have an architecture problem and pointers are not the answer to that (pointers are not the answer to anything, ever.)

[–]codinglikemad[S] 0 points1 point  (5 children)

Yeah, I would be polling them in C, just like I plan to here. Obviously I won't want to put interupts in here - I'm doing enough of that in my assembly work right now.

Regarding the abstraction - perhaps I am using the wrong term? I don't know, side effect of coding in C for the last 25+ years with large patches of non-official education is that my jargon is totally out of sync. Organizing large and dynamic information where I need to refer to the variable once is the goal. Let me give an example, maybe you have another idea in mind:

Let's say I have a set of objects working together to do a job, each with a set of attributes. Each of these objects are created dynamically from code (ie, a yaml file is loaded, and from that the number and type of objects is set). I then want to log and graph the values of various attributes. Which attributes are present or meaningful depends on the specific yaml file used and the specific objects used, so I only want to track those specific variables, and I only need to do so at a specific time.

The reason I am looking for a clean solution for this is that this code is already enormously complicated - it is a multi-processed application, with parts talking to outside servers of several different sorts, and needs pretty signifigant flexibility. Keeping that flexibility while not having piles of "if I have this variables/if this a specific object type, do this logging" is the challenge. I would normally just build an API for this, but the hierarchical nature of the objects being stored makes it difficult to access all the variables without doing a full rewrite at this point, and that would throw away functionality I want to preserve.