Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:Python': 0.05; 'attribute': 0.05; 'classes,': 0.05; 'compiler': 0.05; 'reject': 0.05; 'say,': 0.05; 'class,': 0.07; 'classes.': 0.07; 'extent': 0.07; 'override': 0.07; 'prefix': 0.07; 'variables.': 0.07; 'python': 0.09; '"class"': 0.09; '*is*': 0.09; 'difference,': 0.09; 'globals': 0.09; 'variables,': 0.09; 'cc:addr:python-list': 0.10; 'language,': 0.11; "wouldn't": 0.11; 'aug': 0.13; ':-)': 0.13; 'do,': 0.15; 'slightly': 0.15; '"python': 0.16; "'c'": 0.16; "'c',": 0.16; '(more': 0.16; '*i*': 0.16; 'argument.': 0.16; 'attaching': 0.16; 'attributes.': 0.16; 'classes"': 0.16; 'dancing': 0.16; 'dislike': 0.16; 'driscoll': 0.16; 'enough.': 0.16; 'fail,': 0.16; 'filename:fname piece:signature': 0.16; 'imo,': 0.16; 'keyword.': 0.16; 'later).': 0.16; 'said.': 0.16; 'say.': 0.16; 'silly': 0.16; 'stuff,': 0.16; 'subject:Objects': 0.16; 'syntactic': 0.16; 'syntax.': 0.16; 'those,': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'utterly': 0.16; 'variable.': 0.16; 'worse.': 0.16; 'wrongly': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'instance': 0.17; 'thu,': 0.17; 'variables': 0.17; '(in': 0.18; 'saying': 0.18; '(not': 0.20; 'variable': 0.20; 'python?': 0.20; 'all,': 0.21; 'java': 0.21; 'not,': 0.21; 'explicit': 0.22; 'minor': 0.22; 'object.': 0.22; 'defined': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'references': 0.23; 'sets': 0.23; 'statement': 0.23; 'seems': 0.23; '(this': 0.24; 'cc:no real name:2**0': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'first,': 0.27; 'language.': 0.27; 'used,': 0.27; 'question': 0.27; 'c++': 0.27; 'functions.': 0.27; 'object,': 0.27; "doesn't": 0.28; "d'aprano": 0.29; 'interactions': 0.29; 'name?': 0.29; 'piece': 0.29; 'steven': 0.29; 'subject: [': 0.29; "they'll": 0.29; 'objects': 0.29; 'class': 0.29; "i'm": 0.29; 'maybe': 0.29; 'related': 0.30; 'classes': 0.30; 'keyword': 0.30; 'function': 0.30; 'sense': 0.31; 'point': 0.31; '(and': 0.32; 'implement': 0.32; 'could': 0.32; "aren't": 0.33; 'another': 0.33; 'that,': 0.34; 'wrong': 0.34; 'subject:]': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'really': 0.36; 'created': 0.36; 'but': 0.36; 'wanted': 0.36; 'data.': 0.36; "didn't": 0.36; 'method': 0.36; "i'll": 0.36; 'possible': 0.37; 'ok,': 0.37; 'does': 0.37; 'two': 0.37; '(for': 0.37; 'virtual': 0.37; 'rather': 0.37; 'different': 0.63; 'ever': 0.63; 'more': 0.63; 'charset:windows-1252': 0.65; 'realized': 0.71; 'sounds': 0.71; 'absolutely': 0.84; '*really*': 0.84; 'confusing': 0.84; 'irrelevant': 0.84; 'locals': 0.84 Date: Thu, 23 Aug 2012 14:22:08 -0500 From: Evan Driscoll User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.6esrpre) Gecko/20120714 Thunderbird/10.0.6 MIME-Version: 1.0 To: "Steven D'Aprano" Subject: Variables vs names [was: Objects in Python] References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> X-Enigmail-Version: 1.4 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig0EF9B3A494C578CA98B536BA" Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 155 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345749746 news.xs4all.nl 6865 [2001:888:2000:d::a6]:52573 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27761 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig0EF9B3A494C578CA98B536BA Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 08/23/2012 12:56 PM, Steven D'Aprano wrote: > On Thu, 23 Aug 2012 12:17:03 -0500, Evan Driscoll wrote: >=20 >> I definitely *wouldn't* say "Python >> classes aren't really classes" -- even though (I assert) Python classe= s >> are *far* further from Simula-style (/Java/C++) classes than Python >> variables are from Java variables. >=20 > Well, Python classes are first-class (pun not intended) objects in thei= r=20 > own right, and hence are data. Java and C++ classes are not, they are=20 > instructions to the compiler rather than data. >=20 > But other than that, what do you see as the difference between Python=20 > classes and Simula-style classes? So first, to some extent that's like saying "these two different things are different in this important way, but other than that, what's the difference?" :-) But there are some other differences. (Not all of these are strictly with classes per se, but I would say they all have strong interactions with the object system.) * Explicit 'self'. OK, this sounds just like a minor syntactic difference, and in some respect it is. (For some time I considered it an annoying piece of syntactic salt.) But it has significant interactions with other things which you can do, such as using a method as just a normal function ('type(c).f(c)' ~=3D 'c.f()') or attaching other functions to an instance or a class (more on that later). This is definitely my weakest argument. :-) * Fields. In Simula-style classes, you can tell easily what fields a class and its objects contain. In Python, that question from some point of view doesn't even make sense (in the absence of __slots__). Fields are a property of the *objects* rather than the class, and two objects of the same class don't necessarily have the same fields. Related to this point we have... * What it means for an object to have a particular class type. With Simula-style classes, if I have an object 'o' of class 'c', then I know that 'o' has the functions and fields defined by 'c'. Now, the virtual functions may have been overriden in base classes and stuff, and maydbe they'll always fail, but I at least know they're *there*. In Python, I know... well, nothing basically. As far as I know, it's possible to make it so that o's only relation to 'c' is what 'type(o)' and 'instanceof' say. (And maybe you can even override those, I dunno!) You can go through and add/remove/replace functions. Two different objects of the same class may have completely disjoint sets of attributes. > Given: >=20 > x =3D some_object() > y =3D x >=20 > I could say that x and y are the same object, rather than x and y are=20 > references to the same object. Huh, fair enough. >> To me, saying "here's an alternative way to look at variables" is grea= t, >> 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".) >=20 > I think you are utterly wrong here. >=20 > Python has classes. They are created by the "class" keyword. Whether=20 > those classes are identical to Java classes is irrelevant -- in Python,= =20 > these whatever-they-are-things are called "classes", and so Python has = > classes. >=20 > But Python does not have things called "variables". There is no=20 > "variable" keyword to create a variable. OK, let's make a new language. I'll call it 'Python--' because at least *I* wouldn't want to program in it. :-) In Python--, any time you use a name, you have to prefix it with the word 'variable': variable x =3D 4 print(variable x) Does Python-- have variables? Does Python? To me, the answer to those questions basically has to be the same -- after all, the new 'variable' keyword didn't really change the language, just have it a slightly different concrete syntax. Heck, if I wanted to implement Python--, the only thing I'd have to change in a Python implementation is the lexer! And if you say "no, Python-- doesn't have variables, it just has something that it wrongly calls variables", then it's no contradiction to say "Python doesn't have classes, it just has something that it wrongly calls classes." Think of it as duck-typing the term "variable". :-) To me, Python locals and globals look and quack like a variable. Incidentally, I also realized another reason I don't like the 'names' description. Take 'foo.bar'. (That is, the 'bar' attribute in object 'foo'.) Is 'foo.bar' a name? I'm not sure what the 'names' proponents would say, but to me both answers are problematic. I *really* dislike a 'no' answer because to me, 'foo.bar' absolutely *is* a name for the corresponding object. (This terminology has precedent.) But a 'yes' answer, if you also reject 'variable', means you no longer have an agreed-upon term for the names that are defined in the current scope -- and such a term is a really good thing to have! (I know, let's call them variables. :-)) Evan --------------enig0EF9B3A494C578CA98B536BA Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEVAwUBUDaC4AOzoR8eZTzgAQLtugf/bwqcJWHF/F3PmXRQJeA8sCGSf/T0tHOy cnHFgerCkO7+5f/TocEzHYCmII5E0mV0aK9LITv0mnYtFXubtZOXxH5RIZoSMs/4 J9+nvzszfABQm2zU26mC1HBk5xt8R36bL5dEm26916x9k8Q8mrbV6qlFw8TKB+xF Yia24Wee/4/5ljaqXIN5gQkMSNfRy2edN6VRlz2Et6Ksox3LC7BdeJkWqa5lezuK nG0ofqq9N5vQH80/eljNMlGErygWoI8ysB3x6pty5P8Ee48fxbeK1vGpJxFlt4i4 8dhDxUSW1hW2+AjlEw1GuVWyMJZ3m2KBfj5K9Xol9KXP9OnWn6pnNA== =ivzE -----END PGP SIGNATURE----- --------------enig0EF9B3A494C578CA98B536BA--