Double underscores -- ugly?

Ben Finney bignose+hates-spam at benfinney.id.au
Mon Feb 18 18:39:10 EST 2008


benhoyt <benhoyt at gmail.com> writes:

> 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.

That's a good thing, in that it draws attention to the names. The
convention is by design: these names will be treated specially, so
they should stand out visually to the reader.

> 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

None of these, IMO, meet the "needs to stand out" requirement met by
double-underscore names.

They also introduce special cases for the language parser (and thus
for the reader to understand how the language will be parsed), whereas
double-underscore names work without any special syntax handling.

-- 
 \           “Holy contributing to the delinquency of minors, Batman!” |
  `\                                                            —Robin |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list