On Fri, Oct 26, 2012 at 5:58 AM, Mark Hackett <mark.hackett@metoffice.gov.uk> wrote:
On Friday 26 Oct 2012, Steven D'Aprano wrote:
On 26/10/12 20:22, Daniel Fetchinson wrote:
Hi folks,
Would it be a good idea to have a built-in list of strings containing the reserved identifiers of python such as 'assert', 'import', etc?
The reason I think this would be useful is that whenever I write a class with user defined methods I always have to exclude the reserved keywords. So for instance myinstance.mymethod( ) is okay but myinstance.assert( ) is not. In these cases I use the convention myinstance._assert( ), etc.
The usual convention is that leading underscores are private, and trailing underscores are used to avoid name clashes with reserved words.
So myinstance.assert_ rather than myinstance._assert, which would be considered "private, do not use".
One story I heard about development was a site that had included as an early C++ header had
#define private public
If users REALLY want to use a function you though was private, they will.
Convention works just as well without having people go to extreme lengths to avoid it (where their use case makes it beneficial).
I use it more as a guarantee. Any API that you mark as private can and will break in the future, and is not covered by any stability promise. If they really need to do some awfulness that my library can help out with, sure, they can hack up the private API, but they're on their own.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- Jasper