Decorators: an outsider's perspective

Chas Emerick cemerick at snowtide.com
Sun Aug 15 21:27:27 EDT 2004


On Aug 15, 2004, at 11:55 AM, Paul Morrow wrote:

>> Ouch.  Sorry, the arguments going into a function shouldn't have 
>> **anything** to do with the nature of that function.  Overloading 
>> their existence, lack thereof, or their names as a way of describing 
>> the function they are hung off of seems like a horrible way to go.  
>> (Not to mention the fact that, at least conceptually, it is also 
>> violating that action-at-a-distance guideline...)
>
> That reminds me of how I once thought about using indentation as a 
> means of denoting code blocks.  How idiotic I thought that was.  Now I 
> realize the elegance, beauty, 'genius' in that.
>
> Because of the conventions widely used (in Python) today, the name of 
> a method's first formal parameter *does* indicate the type of method.  
> If you use 'self' as the name of your first parameter, the majority of 
> us will assume that that this is an instance method.  If you don't use 
> 'self', we will assume that it is not an instance method (unless you 
> use 'this', and we happen to be familiar with languages where that 
> stands for the instance at hand, but then that is not the recommended 
> practice).  So you see, when you write a method, you are telling us 
> something about it's type (or what type it isn't).  You are 
> overloading the semantics of the first parameter.
>
> Why don't we all just acknowledge that we are doing this?  Why don't 
> we all just admit that a well written instance method uses 'self' as 
> its first argument.  And well written static or class methods (as well 
> as plain ol' functions) don't use 'self'.
>
> If we strive for well written (clear) code, we follow these 
> conventions.  These conventions convey meaning as to the type of 
> method.  Therefore, explicitly stating the type of method is both 
> superfluous and a potential source of confusion.
>
> I believe that the problem many of us have with ideas like this is 
> that no other even semi-popular languages do this.  But does that make 
> it wrong?  Is our use of indentation wrong?

I think you have the direction of causation reversed here.  Python 
programmers don't use 'self' as the first argument to indicate an 
instance method, they/we (again, I worry how much cred I have as a 
python programmer yet :-) use 'self' *because* a method is an instance 
method.  I know you'd like the reverse to become a 
standard/convention...that's a respectable position, but not a 
particularly practical one since a soon-to-be-standard method for 
defining a function's type is on its way that just happens to be 
generalized enough to be useful in tons of other contexts.

I think the source of my gut reaction to the proposal you've advanced 
(aside from the conceptual action-at-a-distance violation that I 
already cited) is my past experience with Hungarian notation, where the 
name of a variable indicates its type.  The comparison isn't totally 
clean cut because of the special peculiarities of Hn, but I think the 
folly that it represents is a clear warning to stay away from taking 
type information based on naming conventions.

I won't discuss the virtues or drawbacks of whitespace-as-structure, 
since that's been hacked to death 1433 times already.  However, I will 
say that python's usage of whitespace kept me away from seriously 
trying it for almost a year.  Now, that's absolutely my fault, and 
isn't representative of the technical ability of python.  However, if 
continued rapid uptake of python by new users is important, I would 
suggest that using the success of whitespace-as-structure in 'the 
market' is not the greatest reference for a proposal.

- Chas Emerick




More information about the Python-list mailing list