Double underscores -- ugly?

Jason tenax.raccoon at gmail.com
Tue Feb 19 09:37:13 EST 2008


On Feb 18, 3:28 pm, benhoyt <benh... at gmail.com> wrote:
> Hi guys,
>
> I've been using Python for some time now, and am very impressed with
> its lack of red tape and its clean syntax -- both probably due to the
> BDFL's ability to know when to say "no".
>
> Most of the things that "got me" initially have been addressed in
> recent versions of Python, or are being addressed in Python 3000. But
> it looks like the double underscores are staying as is. This is
> probably a good thing unless there are better alternatives, but ...
>
> Is it just me that thinks "__init__" is rather ugly? Not to mention
> "if __name__ == '__main__': ..."?
>
> I realise that double underscores make the language conceptually
> cleaner in many ways (because fancy syntax and operator overloading
> are just handled by methods), but they don't *look* nice.
>
> A solution could be as simple as syntactic sugar that converted to
> double underscores behind the scenes. A couple of ideas that come to
> my mind (though these have their problems too):
>
> def ~init(self):  # shows it's special, but too like a C++ destructor
> def +init(self):  # a bit too additive :-)
> defop add(self, other):  # or this, equivalent to "def __add__"
> def operator add(self, other):  # new keyword, and a bit wordy
>
> Has anyone thought about alternatives? Is there a previous discussion
> on this I can look up?
>
> Cheers,
> Ben.

Hmm.  I must be the only person who doesn't think the double
underscores are ugly.  To me, they seem to provide plenty of attention
to the special methods, but still appear clean due to their almost
white-space-like nature.  Given the use of underscores to indicate
italics in plain-text, the special methods seem (to me) to have extra
emphasis.

I don't print my code often, so that's a caveat, and I came from a C/C+
+ background.

I agree with Ben, that your suggestions don't particularly stand out.
They might stand out if the editor you used supported syntax
highlighting.  Personally, I find the examples with the plus and tilde
(+, ~) to be more noisy and ugly than the underscores.

Think of the underscores as a serene white-space day, with a simple
black road that takes you to the special name.  Or, you can wonder
what I'm smoking when I code.... *grin*

  --Jason



More information about the Python-list mailing list