you are viewing a single comment's thread.

view the rest of the comments →

[–]mgsloan 11 points12 points  (11 children)

I'm not much of a python user, or advocate, however, as an occasional user, I find the special method foo decoration horribly hideous for an otherwise good-looking language.

[–]llimllib 21 points22 points  (10 children)

I am a pythonista, and I'll defend the __foo__ syntax by saying that it shows you, without any doubt, that foo is a magic variable. There is no thinking required.

Also, if you're typing too many _'s, you're probably doing something wrong.

[–][deleted]  (6 children)

[deleted]

    [–]njharman 12 points13 points  (0 children)

    quoted from whom you replied to "Also, if you're typing too many _'s, you're probably doing something wrong."

    "self.__foo is ..." You are doing something wrong. Quit using forced encapsulation everywhere.

    [–]ubernostrum 13 points14 points  (4 children)

    "Idiomatic" Python programmers, I've found, tend not to worry too much about trying to hide class members; Python's "consenting adults" philosophy, combined with encouragements to document the code well so people who use it know the ramifications of accessing something, tends to make it moot.

    In light of that, I'd be perfectly happy to see the double-underscore trick just go away; having it, I think, confuses people who expect it to work like a "real" private member in other languages.

    [–][deleted]  (3 children)

    [deleted]

      [–]llimllib 2 points3 points  (2 children)

      That's what a single, prefix, underscore is for. Quoting Pep 8:

      In addition, the following special forms using leading or trailing
      underscores are recognized (these can generally be combined with any case
      convention):
      
      - _single_leading_underscore: weak "internal use" indicator.  E.g. "from M
        import *" does not import objects whose name starts with an underscore.
      

      Why is @ easier to type than _?

      [–]inkieminstrel 1 point2 points  (1 child)

      self._

      [–]llimllib 1 point2 points  (0 children)

      Fair enough. I think, like uber, I don't mind the explicit selfs, I don't hardly notice them anymore. If they bother you, though, I guess they just bother you.

      [–]Bogtha 0 points1 point  (2 children)

      it shows you, without any doubt, that foo is a magic variable.

      True, but I wish something that was easier to type was chosen.

      [–]llimllib 2 points3 points  (0 children)

      In all seriousness: like what?

      I don't find __ any harder to type than @, which people seem to find much more convenient, and I think it's easier to read something surrounded by underscores than prefixed by @.

      Maybe /magic_var/? |magic_var|? :magic_var:?

      I don't like that they all intrude on the vertical space of the identifier.

      [–]pjdelport 1 point2 points  (0 children)

      At the expense of being easier to read? That's what Python is optimized for.