Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51868

Re: Correct Way to Write in Python

References <daaa64d5-3366-48b4-980c-cd91a440aa90@googlegroups.com> <51fcbd58$0$30000$c3e8da3$5496439d@news.astraweb.com> <e9fb4f84-6b19-42ef-8f78-cc46e204e3f3@googlegroups.com>
Date 2013-08-03 17:21 +0100
Subject Re: Correct Way to Write in Python
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.162.1375546877.1251.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Aug 3, 2013 at 4:59 PM, Sagar Varule <punk.sagar@gmail.com> wrote:
> Your explanation for private and public access modifier was awesome as I was having harding time finding why we dont have access modifier for python....Thanks a lot

It's a huge saving in time and effort. The C++ convention is: Make
everything private, then hand-write getters and setters for them all,
just in case you want to put extra code onto them. (I don't know C#
but it seems to be pretty much the same.) The Python convention is:
We're all consenting adults. Make stuff public, then if you need to
add code to something, make a @property that simulates the old
behaviour.

Personally, I've started to adopt the Python style in my C++ code as
well. I use struct instead of class, avoid making anything private,
and document the things that must not be done - for instance, I
created a class that had one particular pointer that must never be
advanced other than by the provided member function, but may be
retarded. No reason to fiddle with member privacy even there.

(The same technique has benefit in a quite different area, too:
separation of code and data. Not in C++, but I have systems that let
me load new code into a running process, and there it's extremely
helpful to just do everything as a simple structure, and then the new
code can slide in and work with the old data structure, happily
extending it with whatever it now needs. Again, everything's public.)

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Correct Way to Write in Python punk.sagar@gmail.com - 2013-08-02 23:18 -0700
  Re: Correct Way to Write in Python Peter Otten <__peter__@web.de> - 2013-08-03 08:47 +0200
    Re: Correct Way to Write in Python Sagar Varule <punk.sagar@gmail.com> - 2013-08-03 00:09 -0700
      Re: Correct Way to Write in Python Peter Otten <__peter__@web.de> - 2013-08-03 11:04 +0200
        Re: Correct Way to Write in Python Sagar Varule <punk.sagar@gmail.com> - 2013-08-03 09:07 -0700
  Re: Correct Way to Write in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-03 08:20 +0000
    Re: Correct Way to Write in Python Sagar Varule <punk.sagar@gmail.com> - 2013-08-03 08:59 -0700
      Re: Correct Way to Write in Python Chris Angelico <rosuav@gmail.com> - 2013-08-03 17:21 +0100

csiph-web