Re: Question about idiomatic use of _ and private stuff.

Discussion in 'Python' started by Troy Melhase, Feb 23, 2007.

  1. Troy Melhase

    Troy Melhase Guest

    > Why do people sometimes use one leading underscore?

    Many folks like to use the single leading underscore to emphasize that
    the attribute isn't part of the normal way to use the class or
    instance.

    It's bad style in my opinion, but I'm probably in the minority.
     
    Troy Melhase, Feb 23, 2007
    #1
    1. Advertising

  2. Troy Melhase

    James Stroud Guest

    Troy Melhase wrote:
    >> Why do people sometimes use one leading underscore?

    >
    >
    > Many folks like to use the single leading underscore to emphasize that
    > the attribute isn't part of the normal way to use the class or
    > instance.
    >
    > It's bad style in my opinion, but I'm probably in the minority.


    I've increasingly found that leading underscores are unnecessary as well
    if not using a "magic" attribute with the bounding double underscores.
     
    James Stroud, Feb 23, 2007
    #2
    1. Advertising

  3. Troy Melhase

    Chris Mellon Guest

    On 2/23/07, James Stroud <> wrote:
    > Troy Melhase wrote:
    > >> Why do people sometimes use one leading underscore?

    > >
    > >
    > > Many folks like to use the single leading underscore to emphasize that
    > > the attribute isn't part of the normal way to use the class or
    > > instance.
    > >
    > > It's bad style in my opinion, but I'm probably in the minority.

    >
    > I've increasingly found that leading underscores are unnecessary as well
    > if not using a "magic" attribute with the bounding double underscores.
    > --


    I use the single underscore a lot and should use it more. It indicates
    something that you shouldn't look at unless you understand and are
    willing to bind yourself to the class internals.

    For example, I have a network interface that buffers data as it's
    being parsed. The internal buffer is a list named _buffer, and messing
    with the buffer is a good way to break the parser.

    There's an exterior interface, which is a guaranteed consistent buffer
    called "message", but (even for me, the author) it's easy to get
    confused about which one is the safe, public attribute and which one
    is private. The underscore disambiguates.
     
    Chris Mellon, Feb 23, 2007
    #3
  4. Troy Melhase a écrit :
    >> Why do people sometimes use one leading underscore?

    >
    >
    > Many folks like to use the single leading underscore to emphasize that
    > the attribute isn't part of the normal way to use the class or
    > instance.
    >
    > It's bad style in my opinion, but I'm probably in the minority.


    You are, definitively. While it's not technically part of the language
    syntax, you can practically consider it as such.
     
    Bruno Desthuilliers, Feb 25, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp
    Replies:
    19
    Views:
    798
    Daniel T.
    Feb 4, 2004
  2. Jeremy Bowers
    Replies:
    3
    Views:
    517
    Steven Bethard
    Jan 24, 2005
  3. Steven W. Orr
    Replies:
    4
    Views:
    281
    Bruno Desthuilliers
    Feb 27, 2007
  4. Steven W. Orr
    Replies:
    2
    Views:
    254
    goodwolf
    Feb 24, 2007
  5. jaems

    some stuff private

    jaems, Mar 19, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    263
    Cowboy \(Gregory A. Beamer\)
    Mar 19, 2008
Loading...

Share This Page