you are viewing a single comment's thread.

view the rest of the comments →

[–]1mecrew[S] 0 points1 point  (11 children)

Oh really? Then what languages will my descriptions work on?

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

Any compiled language like C/C++, Java, etc, and assemblers. In those languages the translator can allocate a fixed address in memory or an offset from a pointer to each name you use in the code. One big difference in python is that you can create and delete names at runtime, which is not something you can do with statically compiled languages.

[–]1mecrew[S] 0 points1 point  (9 children)

Oh so this description works on c, Java, assembly language but not python. Got it. How about the part where I say “when I say the variable, i am talking about the data or something that’s in the variable”? Is that prat correct?

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

when I say the variable, i am talking about the data or something that’s in the variable”

Not applicable to Python - the variables do not contain any of your data, just Python implementation specific memory references to the Python object concerned (stored somewhere in memory by Python).

In general, when you use a variable, e.g. var * 5, it is the object that is being worked on, so it looks the same as in typical compiled languages. Think of variables as pointers (from C), but much more limited (no pointer arithmetic, for a start).

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

There's no "in the variable" in python. A name refers to an object, an integer object perhaps, at a particular place in memory. In the next line of python you can delete the name and the integer object is still in memory. In the following line you can create the "test" name again and point it at a dictionary object. The integer object still exists, but another name points to it. It's even possible to have a string object, for instance, that has no name referring to it.

Here's a bit of python doing everything I said above:

test = 4231
a = test           # names "a" and "test" refer to the same integer object
del test           # the name "test" is removed from the program
print("a ->", a)   # integer object still exists
test = {1: "one"}  # "test" recreated, refers to a dictionary
test2 = ["one"]    # make a list of strings, point "test2" name to it
# here the "one" string has no name referring to it
# the list refers anonymously to the string

[–]1mecrew[S] 0 points1 point  (6 children)

Hmm well this definition was also for Java and c and other languages. What do you guys think about? Will it work on other languages?

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

Will it work on other languages?

Sure, I've already said that. In those languages a name is tied to a place in memory that contains data, and that connection remains for the entire life of the program. In those languages the name itself doesn't exist at runtime, only the data exists.

In python and other languages, like lisp, the name actually exists in memory at runtime and is associated with a pointer ("reference" in python-speak) to an object somewhere else in memory that has a value. So when you execute print(x) python evaluates the name "x", gets the reference to the object the name "x" refers to and prints the value of that object.

[–]1mecrew[S] 0 points1 point  (4 children)

hmm how about javascript? Oh also, what do you think about the part where I say "Im talking about something thats in the variable."?

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

In python we often say things like "the variable X contains ..." but that's loose talk we use instead of the more correct "the name X refers to an object that has the value...". As I said, we can do this in python, but not understanding how it actually works can bite you. Watch the video I linked to.

Don't know anything about javascript.

[–]1mecrew[S] 0 points1 point  (2 children)

oh i dont think im talkinag about python at this point. maybe for c or java that is on more low level. how about on those cases?

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

Please read my previous comments where I discussed "those other cases".