# Double underscore nomenclature in Python

**URL:** <https://www.ruby-forum.com/t/double-underscore-nomenclature-in-python/165449>\
**Category:** Ruby\
**Created:** [April 14, 2009, 2:05am UTC](https://www.ruby-forum.com/t/double-underscore-nomenclature-in-python/165449 "2009-04-14T02:05:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![toadkicker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@toadkicker](https://www.ruby-forum.com/u/toadkicker)\
**Post date:** [April 14, 2009, 2:05am UTC](https://www.ruby-forum.com/t/double-underscore-nomenclature-in-python/165449/1 "2009-04-14T02:05:22Z")

</div>

So, I’m stuck re-engineering some dreadful Python library code into  
Ruby (and I mean terrible, a mish-mash of different clashing  
programming paradigms – inheritance, delegation, etc. severely  
intertwined all over, ugghh), and I came across Python’s use of these  
double underscore methods ( **hook\_method**. I’m a Python virgin; so  
sue me. Never learned Perl, either).

I’m curious as to why Ruby unintentionally keeps these type of things  
less obvious. I’ve seen many questions on this group concerning #puts  
using an object’s #to\_s to display itself. Don’t get me wrong; it  
doesn’t bother me at all, but I’ve run across a few newbies that  
struggle with this type of “hidden” guru knowledge (It’s surely not  
hidden, but not easy to discover either; sort of like a live  
Architeuthis).

So, should one ingrain a style into the language (like the BeOS team  
very strongly suggested with its C++ coding practice guidelines), or  
keep it laid back and just be firm with people about reading the docs?

Todd

---

<div class="post-metadata">

**Author:** ![toadkicker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@toadkicker](https://www.ruby-forum.com/u/toadkicker)\
**Post date:** [April 14, 2009, 2:30pm UTC](https://www.ruby-forum.com/t/double-underscore-nomenclature-in-python/165449/2 "2009-04-14T14:30:59Z")

</div>

On Apr 13, 8:04 pm, Todd B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> doesn’t bother me at all, but I’ve run across a few newbies that  
> struggle with this type of “hidden” guru knowledge (It’s surely not  
> hidden, but not easy to discover either; sort of like a live  
> Architeuthis).

Python uses \_\_method\_name to denote private methods (not enforced,  
just a convention). Ruby has keywords ‘private’ and ‘protected’.

Python uses **method\_name** with leading and trailing underscores for  
special system functions with pre-defined behavior. Like **init** ()  
where ruby uses ‘initialize’.

Python has certain underscore methods for operator overloading; you  
define **add** () to overload ‘+’. Whereas in Ruby, you simply define  
the ‘+’ method.

I’m not sure how this equates to hidden guru knowledge. Ruby makes  
more sense to me in these situations.

– Mark.

---

<div class="post-metadata">

**Author:** ![toadkicker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@toadkicker](https://www.ruby-forum.com/u/toadkicker)\
**Post date:** [April 14, 2009, 2:43pm UTC](https://www.ruby-forum.com/t/double-underscore-nomenclature-in-python/165449/3 "2009-04-14T14:43:20Z")

</div>

2009/4/14 Mark T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > using an object’s #to\_s to display itself. Don’t get me wrong; it  
> > where ruby uses ‘initialize’.
> 
> Python has certain underscore methods for operator overloading; you  
> define **add** () to overload ‘+’. Whereas in Ruby, you simply define  
> the ‘+’ method.
> 
> I’m not sure how this equates to hidden guru knowledge. Ruby makes  
> more sense to me in these situations.

+1

Todd had a nice summary statement included in his first posting: “keep  
it laid back and just be firm with people about reading the docs”. 🙂

Kind regards

robert
