Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'c++,': 0.07; 'class,': 0.07; 'explanation': 0.09; 'function,': 0.09; 'structure,': 0.09; 'python': 0.11; '4:59': 0.16; '@property': 0.16; 'behaviour.': 0.16; 'fiddle': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'modifier': 0.16; 'personally,': 0.16; 'public,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'seems': 0.21; '(the': 0.22; 'aug': 0.22; 'load': 0.23; 'effort.': 0.24; 'instance,': 0.24; 'pointer': 0.24; 'helpful': 0.24; "i've": 0.25; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'extending': 0.31; 'struct': 0.31; 'class': 0.32; 'there.': 0.32; 'stuff': 0.32; "we're": 0.32; 'quite': 0.32; 'running': 0.33; 'style': 0.33; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'c++': 0.36; 'done': 0.36; 'awesome': 0.38; 'convention': 0.38; 'process,': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'extremely': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'new': 0.61; 'privacy': 0.61; 'simple': 0.61; 'advanced': 0.63; 'making': 0.63; 'different': 0.65; 'dont': 0.67; 'benefit': 0.68; 'saving': 0.69; "everything's": 0.84; 'adopt': 0.91; 'technique': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=bEFI/2mBBAmeyHURZGOTrkWwteb4ffqjtD1Fl9q8+uo=; b=Lxvk+C4no9wvq/t4e5e4mHt8GQrlFLuxbJdFMh56ofSL5KdXWqq0O/9NoE1WdV+ct6 l5/uBT2t1eMFXLak+dOod7tv/bIplSWMu1YiZlmwBvaUcbEfdzyC/sLjnsgKFvbPeqx9 b9Hz28mgyeRgwQWaBemfmVH7qVq9Hw5ZfOmD/KpY1sGByJnyFchTdqgAQdwqGhm2ZwLu gY0g+2km6OQMD39L+/pwcx7RX3bB3NjobbM86IZhho6MvT99muGxnNfbD44Fv4UCo9kK OvOaXH0cUQQMy8ylaKCYiw1Q69Busx34us39IB9E4iQH3TOr9Ji69IM15atJo9NdKzh4 eqLw== MIME-Version: 1.0 X-Received: by 10.59.9.69 with SMTP id dq5mr3514563ved.87.1375546867791; Sat, 03 Aug 2013 09:21:07 -0700 (PDT) In-Reply-To: References: <51fcbd58$0$30000$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 3 Aug 2013 17:21:07 +0100 Subject: Re: Correct Way to Write in Python From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375546877 news.xs4all.nl 15962 [2001:888:2000:d::a6]:40720 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51868 On Sat, Aug 3, 2013 at 4:59 PM, Sagar Varule 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