[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

double underscore nomenclature in Python

Todd Benson

4/14/2009 12:05:00 AM

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

2 Answers

Mark Thomas

4/14/2009 12:28:00 PM

0

On Apr 13, 8:04 pm, Todd Benson <caduce...@gmail.com> wrote:
> 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).

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.

Robert Klemme

4/14/2009 12:43:00 PM

0

2009/4/14 Mark Thomas <mark@thomaszone.com>:
> On Apr 13, 8:04=A0pm, Todd Benson <caduce...@gmail.com> wrote:
>> 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__. =A0I'm a Python virgin; so
>> sue me. =A0Never learned Perl, either).
>>
>> I'm curious as to why Ruby unintentionally keeps these type of things
>> less obvious. =A0I've seen many questions on this group concerning #puts
>> using an object's #to_s to display itself. =A0Don'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).
>
> 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.

+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


--=20
remember.guy do |as, often| as.you_can - without end