I
Ian Kelly
Those people are confused, then. Python is strongly typed: objects
always know their type, the type is always exact, and the type of an
object can't be changed.
Except when it can.
True
Cheers,
Ian
Those people are confused, then. Python is strongly typed: objects
always know their type, the type is always exact, and the type of an
object can't be changed.
Well I'm a beginner
Yes of course I am, thank you for pointing that out.
I don't know why I have this overwhelming need to see variables explicitly
defined ... years of 'same old same old' I suppose.
[...]
Looking at the self I'm assuming that's a method and not a function.
2) Related to the above, you can infinitely nest scopes. There's nothing
wrong with having six variables called 'q'; you always use the innermost
one. Yes, this can hurt readability
Then maybe you should read more and write less.
We need to separate out the 'view' from the 'implementation' here. Most
developers I know, if looking at the code and without the possibly
dubious benefit of knowing that in Python 'everything is an object'
would not call this 'strong typing'
You haven't discovered anything about types; what you have discovered is
that Python name bindings are not variables.
In fact, Python doesn't have variables – not as C or Java programmers
would understand the term. What it has instead are references to objects
(with names as one kind of reference).
OK, I've seen this said a few times, and I have to ask: what do you mean
by this? I consider myself pretty decent at Python and other languages,
and I really don't get it.
OK, I've seen this said a few times, and I have to ask: what do you mean
by this? I consider myself pretty decent at Python and other languages,
and I really don't get it.
And many other languages have reference behavior and still call their
bindings "variables", e.g. Scheme.
Steven said:I think the point that Ben would like to make is that while "name
binding" is a specific kind of "variable", the word "variable" comes
with too much baggage from the old-school C, Pascal etc. style of
variables- are-named-memory-locations. Most of the time, the
differences are unimportant, but when they are important, if your
mental image is that Python "variables" (name bindings) are like C
or Pascal "variables" (memory locations), you're going to get
confused.
[...]And many other languages have reference behavior and still call
their bindings "variables", e.g. Scheme.
Yes, well in my opinion, a great deal of the terminology in use is
absolutely dire. E.g. both Ruby and Java have the exact same
parameter binding strategy as Python, only the Ruby people call
theirs "call by reference" and the Java people call theirs "call by
value", *both of which are identical*, and NEITHER of which are the
same thing that C and Pascal programmers will understand by call by
value *or* call by reference.
[snip]I don't get it either. To me the python-has-no-variables campaigners
seem confused. As far as I can see, Python can be seen in terms of
variables bound to (locations containing) values perfectly well, in a
way that should be quite familiar to people who come from Java (or
Lisp, Scheme like me).
I don't get it either. To me the python-has-no-variables campaigners
seem confused. As far as I can see, Python can be seen in terms of
variables bound to (locations containing) values perfectly well, in a
way that should be quite familiar to people who come from Java (or
Lisp, Scheme like me).
Well we don't want to turn this into a language comparison thread do we,
that might upset too many people but I can't remember ever writing a
method that took an Object as argument, you just can't do that much with
an Object.
Most developers are wrong
A very useful resource to read is "What To Know Before Debating Type
Systems", which was put on the internet, lost, then found and put back up
here:
http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/
[Snip discussion on names vs variables]
Does that sort things out, or just make things more confusing?
ChrisA
I would also avoid any distinction between an object and a
"reference" to an object, except as an implementation detail. It's not
helpful.
...
Perhaps those that come from the Java and Lisp world don't find the
name/value paradigm as helpful. Still, it seems silly to excoriate
people on the list for trying to explain python fundamentals in
several different ways. Sometimes explaining the same idea in
different words helps people understand the concept better.
Personally, when I was learning python I found the idea of python
having names and values (rather than variables and references) to
clear up a lot of my misconceptions of the python object model. I
think it's done the same for other people too, especially those who
come from the C world, where a variable is a named and typed location
in memory.
I definitely *wouldn't* say "Python
classes aren't really classes" -- even though (I assert) Python classes
are *far* further from Simula-style (/Java/C++) classes than Python
variables are from Java variables.
Whaaaa....?
How would you describe it then? To me, that distinction is absolutely
*fundamental* to understanding how languages like Python/Scheme/Java
work, because it tells you how to reason about aliasing behavior in an
unconvoluted way (which is essential to understanding how they work).
How would *you* suggest dealing with that issue?
*However*, this thread wasn't really prompted by someone just trying to
explain variables in different terms -- it was prompted by one of the
many comments you see from time-to-time that "Python doesn't have
variables – not as C or Java programmers would understand the term".
To me, saying "here's an alternative way to look at variables" is great,
but saying "Python doesn't have variables" is, IMO, at least as silly as
what Jussi said. To me, dancing around the issue just leads to more
confusing terminology and makes things worse.
(And this is reinforced by the fact that neither I nor Google seems to
have really seen "Python doesn't have classes" ever used, when that
statement is at least as true as "Python doesn't have variables".)
Well, there you go. There *is* something wrong with having six variables
called 'q'.
Sometimes you don't want only six variables called 'q' but a hundred
of them
def fac(q):
if q < 1 :
return 1
else:
return q * fac(q-1)
print(fac(100))
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.