osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

newb question about @property


Steve D'Aprano wrote:
> On Sun, 1 Oct 2017 05:46 pm, Bill wrote:
>
>> If you were going to show non-Python users, say science undergraduates
>> and faculty, that Python is an interesting tool (in 45 minutes), would
>> one delve into descriptors?
> Hell no :-)
Oops, I see I used the word "descriptor", where I meant "decorator" (at 
least newb is still in the subject line).   I don't even know what a 
descriptor is yet--I know a bit more about meta-classes! %-) So, on your 
list, I'm basically up to the leading edge of (5), writing decorators. 
But my previous programming experience helped me to blast through (1) to 
(4).  Going forward, it appears the walkway will be a little steeper.  I 
do appreciate your list as it improves my perspective.

 From the point of view of getting others to be interested, I'm not sure 
*classes* and object oriented design/thinking do it.  I think they are 
more of an acquired taste... Functions, on the other hand, are easy to 
like, I think--especially in Python.


>
> I think there's a hierarchy of difficulty/complexity/mind-bogglingness in
> Python. From least complex to most:
>
> - Using Python in an imperative fashion, as in simple scripts.
>
> - Writing your own functions.
>
> - Writing your own classes.
>
> - Writing generators.
>
> - Using decorators, including property.
>
> - Writing your own decorators.
>
> - Writing your own descriptors.
>
> - Writing your own metaclasses (a.k.a. "the killer joke").
>
> I wouldn't touch the last three in a beginner's class, not unless they already
> had a significant amount of programming experience.
>
>
>
>> I am thinking maybe. Here is what I am
>> thinking at this moment: trivial applications (probably), list
>> comprehensions (definitely), generators (maybe briefly). Whatever I
>> would discuss, I think ending with descriptors could be a strong finish.
> That depends on whether your aim is to confuse them or not :-)
>
> I don't think the descriptor protocol is something you'll be able to explain in
> five or ten minutes. *Using* descriptors like property, sure, that's fine.
>
>
>> But I'm certainly not merely interested for the sake of my talk, I
>> obtain some satisfaction in learning how things work.  If you can
>> suggest any references for descriptors which you think are good, I would
>> be interested.
> The definitive explanation of descriptors is here:
>
> https://docs.python.org/3/howto/descriptor.html

Thanks!

Bill
>
>
>