Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53350
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-08-31 05:57 -0700 |
| References | <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <ecd32f98-6ba8-4b1e-91d3-e0fd6a8034c3@googlegroups.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> |
| Message-ID | <ea5a462e-b3da-44cf-8697-fa07d381d3c5@googlegroups.com> (permalink) |
| Subject | Re: Encapsulation unpythonic? |
| From | Fabrice Pombet <fp2161@gmail.com> |
On Saturday, August 31, 2013 1:46:52 PM UTC+2, Steven D'Aprano wrote: > On Fri, 30 Aug 2013 23:07:47 -0700, Fabrice Pombet wrote: > > > > > well, look at that: > > > > > > a=(1,2) > > > a=2+3 ->a is an object and I have changed its type and value from > > > outside. > > > > Incorrect. You have not changed the type or value of any object. "a" is > > not an object, it is a *name*, and while you can change the object bound > > to the name, the objects remain unchanged. > > > > When you do this: > > > > x = 23 > > x = 42 > > > > the *object* 23 does not change, only the name binding changes. To do > > otherwise would cause all sorts of surprises: > > > > # THIS DOES NOT HAPPEN IN PYTHON > > # or any other language, as far as I am aware > > x = 23 > > y = x # y now has the value 23 > > x = 42 # change the value of the object ### NOT SO! ### > > print y > > => prints 42 > > > > Name binding (assignment) does not change objects. It changes the link > > between a name and the object, but the object remains untouched (unless > > it is unbound, and garbage collected). Assignment is not mutation. > > Assigning to a name does not modify the object that was previously bound. > > > > > > But even if you were right about changing the type and value of objects > > in place -- Python allows you to mutate lists and dicts in place, and > > even mutate the type of some objects, although not built-ins -- your > > understanding is still confused. Re-assignment (re-binding) of local > > variables is hardly a violation of encapsulation. But if it was, then > > Java and C++ have no encapsulation either, because you can re-assign to > > local variables inside a function too. > > > > If you want to see a language without encapsulation, you need to look at > > something like 1970s-style BASIC, a language where all variables are > > global, where there is no support for grouping related code into separate > > modules or files, where the closest thing to a function call is GOTO or > > GOSUB. > > > > Of course, languages can have *more* or *less* encapsulation than other > > languages. C lets you encapsulate related functions into a file, but it > > has no way of grouping data and functions together except loosely, in a > > file. C++ adds classes, which has more encapsulation since you can group > > functions and their data together. > > > > > > > > > As far as I am concerned this is one hell of an encapsulation > > > violation... Could you do this -strictly speaking- in Java or C++? > > > > Of course you could. All you need is a way to tell the compiler not to > > type-check the variable "a". Or more practically, some way to declare > > variable "a" as a reference to an untyped or generic value. C# has the > > dynamic keyword for this functionality. I don't know about Java or C++, > > but the JVM is certainly capable of implementing dynamic typing as there > > are various dynamically-typed languages built on top of the JVM, such as > > OpenXION and Cobra. > -- > > Steven Steve, I think that your definition of encapsulation is too wide to give a reasonable answer to the question at hand. If I understand you correctly, you are taking encapsulation as a language characteristic, rather than a principle. Plus, you seem to forget that encapsulation is an OOP principle, and, forgive me if I am wrong, does not apply normally to functions or languages like C. Please read Steve Holden's (in chaz') definition, and tell us whether you think that Python enforces strongly this principle, I think that would be a good basis for an agreement. My answer is no, it doesn't, but it allows you to abide by it if you want to. Unlike Java or C++ who would tend to do exactly the contrary (enforces it strictly, and (possibly?) allow you to discard it at times with a few jiffies (or not? I don't know))
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Encapsulation unpythonic? fsaldan1@gmail.com - 2013-08-17 05:26 -0700
Re: Encapsulation unpythonic? Skip Montanaro <skip@pobox.com> - 2013-08-17 07:54 -0500
Re: Encapsulation unpythonic? David <bouncingcats@gmail.com> - 2013-08-17 23:05 +1000
Re: Encapsulation unpythonic? Chris Angelico <rosuav@gmail.com> - 2013-08-17 16:50 +0100
Re: Encapsulation unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-17 16:17 +0000
Re: Encapsulation unpythonic? Joshua Landau <joshua@landau.ws> - 2013-08-18 18:15 +0100
Re: Encapsulation unpythonic? Steven D'Aprano <steve@pearwood.info> - 2013-08-19 07:05 +0000
Re: Encapsulation unpythonic? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-19 18:57 -0400
Re: Encapsulation unpythonic? random832@fastmail.us - 2013-08-21 12:52 -0400
Re: Encapsulation unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-22 02:06 +0000
Re: Encapsulation unpythonic? Ian Kelly <ian.g.kelly@gmail.com> - 2013-08-21 16:02 -0600
Re: Encapsulation unpythonic? Gary Herron <gary.herron@islandtraining.com> - 2013-08-17 13:16 -0700
Re: Encapsulation unpythonic? Terry Reedy <tjreedy@udel.edu> - 2013-08-17 17:22 -0400
Re: Encapsulation unpythonic? Chris Angelico <rosuav@gmail.com> - 2013-08-18 01:59 +0100
Re: Encapsulation unpythonic? chaz2cry@gmail.com - 2013-08-22 19:12 -0700
Re: Encapsulation unpythonic? Fabrice Pombet <fp2161@gmail.com> - 2013-08-30 10:43 -0700
Re: Encapsulation unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 02:35 +0000
Re: Encapsulation unpythonic? Fabrice Pombet <fp2161@gmail.com> - 2013-08-30 23:07 -0700
Re: Encapsulation unpythonic? Marco Buttu <marco.buttu@gmail.com> - 2013-08-31 08:49 +0200
Re: Encapsulation unpythonic? Gary Herron <gherron@digipen.edu> - 2013-08-31 00:03 -0700
Re: Encapsulation unpythonic? Fabrice Pombet <fp2161@gmail.com> - 2013-08-31 00:42 -0700
Re: Encapsulation unpythonic? Fabrice Pombet <fp2161@gmail.com> - 2013-08-31 01:00 -0700
Re: Encapsulation unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 11:46 +0000
Re: Encapsulation unpythonic? Ned Batchelder <ned@nedbatchelder.com> - 2013-08-31 08:41 -0400
Re: Encapsulation unpythonic? Fabrice Pombet <fp2161@gmail.com> - 2013-08-31 05:49 -0700
Re: Encapsulation unpythonic? Fabrice Pombet <fp2161@gmail.com> - 2013-08-31 05:57 -0700
Re: Encapsulation unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-01 08:10 +0000
Re: Encapsulation unpythonic? Chris Angelico <rosuav@gmail.com> - 2013-09-01 18:21 +1000
Re: Encapsulation unpythonic? Fabrice Pombet <fp2161@gmail.com> - 2013-09-01 03:09 -0700
Re: Encapsulation unpythonic? Ethan Furman <ethan@stoneleaf.us> - 2013-09-01 11:42 -0700
Re: Encapsulation unpythonic? Roy Smith <roy@panix.com> - 2013-09-01 15:13 -0400
Re: Encapsulation unpythonic? Ethan Furman <ethan@stoneleaf.us> - 2013-09-01 13:33 -0700
Re: Encapsulation unpythonic? Tim Delaney <timothy.c.delaney@gmail.com> - 2013-09-02 07:54 +1000
Re: Encapsulation unpythonic? Roy Smith <roy@panix.com> - 2013-09-01 18:02 -0400
Re: Encapsulation unpythonic? Ethan Furman <ethan@stoneleaf.us> - 2013-09-01 17:24 -0700
Re: Encapsulation unpythonic? Roy Smith <roy@panix.com> - 2013-09-01 20:59 -0400
Re: Encapsulation unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-02 02:57 +0000
Re: Encapsulation unpythonic? Ethan Furman <ethan@stoneleaf.us> - 2013-09-01 21:15 -0700
Re: Encapsulation unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-02 01:57 +0000
Re: Encapsulation unpythonic? Ben Finney <ben+python@benfinney.id.au> - 2013-09-02 09:32 +1000
Re: Encapsulation unpythonic? Roy Smith <roy@panix.com> - 2013-09-01 20:52 -0400
Re: Encapsulation unpythonic? "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2013-09-03 00:29 +0100
Re: Encapsulation unpythonic? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-09-03 22:41 -0400
Re: Encapsulation unpythonic? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-31 13:31 -0400
Re: Encapsulation unpythonic? Tim Delaney <timothy.c.delaney@gmail.com> - 2013-09-01 03:47 +1000
Re: Encapsulation unpythonic? 88888 Dihedral <dihedral88888@gmail.com> - 2013-09-02 14:43 -0700
csiph-web