[Sugar-devel] Correct use of leading underscores in Python?

Jim Simmons nicestep at gmail.com
Tue Jul 21 10:18:39 EDT 2009


Martin,

The comparison to Java is a good one.  I program in Java for a living
and find that I tend to think of my Activity  logic in Java terms then
translate the concept to Python.  I do the same thing with pygtk and
Java Swing.  Last night I removed most of the leading underscores from
my code.  I'll gradually start putting some back in where it makes
sense, using the private/protected criteria as a guide.  I know the
the copied code I was using was not resulting in code that followed
best practices.

Thanks again,

James Simmons


> IMO:
>
> - one leading underscore is "private" ("weak internal use") or, in
>  the context of inheritance, like java's "protected" (private to a
>  class and its subclasses but can be / is expected to be overridden).
>
> - two leading underscores is "extra private" ("strong internal use")
>  or, in the context of inheritance, like java's "private" (private to
>  a class and not visible to subclasses without good,
>  you-better-know-why-you're-thumbing-your-nose-at-name-mangling
>  reasons).
>
>> So when do you use leading underscores to name something?  Or do you
>> ever use them?
>
> They're used a lot by python code.  One should almost certainly be
> using them in code that's used by other code.
>
>> Thanks,
>>
>> James Simmons
>
> Martin
>


More information about the Sugar-devel mailing list