3 2095
Michele Simionato wrote: "Mike C. Fletcher" <mc******@roger s.com> wrote in message news:<ma******* *************** ************@py thon.org>...
Slides from my PyGTA presentation on Tuesday, focusing mostly on why/where you would want to use meta-classes, are available in PDF format:
http://members.rogers.com/mcfletch/p...etaclasses.pdf
I gave a look at your transparancies and they are very good, indeed.
Thanks.
Still, there a couple of minor points I think could be improved, for the sake of metaclass newbies (I am in a nitpick mood today ;)
Rassin-frassin... ;) :)
1) On page 26 you say:
Note: In Python 2.2.3, the meta-class object's __call__ is not called by the metaclass hook, the interpreter calls __new__, then __init__ directly
That's correct (and true in 2.3 too), still there is a way to get the metaclass hook to call __call__: it involves meta-metaclasses ;)
Good thing this didn't occur to me before I gave the presentation, it
already ran 2 hours instead of 20 minutes :) . I'd been thinking Guido
was just messing with people's minds when he said the meta-class was
called. My bad.
....
in this example MetaMeta.__call __ is a meta-metamethod, which is accessible to Meta, but not to its instance C; therefore you can modify the C __call__ (and Meta.__call__ too, if you wish) method independently from MetaMeta.__cal l__, avoiding name clashes.
Probably have to cover this a good long way through the presentation, or
it'll just lose people who are just beginning to get comfortable with
metaclasses and metamethods. See if I've got this right:
Class-declaration ends
Interpreter finds declared metaclass (via whichever method)
Interpreter looks for a __call__ method in type( metaclass
).__dict__ .(skipping the dictionary of metaclass due to "special"-ness
of the name __call__)
Interpreter executes type(metaclass) .__call__( classname, bases,
dictionary )
Assert: It does this due to the "special method-name lookup" exception
for new-style types: special methods are looked up in the type without
lookup in the instance dictionary.
Hmm, definitely not something to cover early in the presentation...
especially when most users haven't yet discovered the special-names
exception (most programmers still haven't discovered the new features of
Python 2.2 (hence my metaclass presentation)). If I were writing a "for
dummies" book that would definitely have to be a "technical aside".
2) On page 30 you say that you can modify the dictionary both in __new__ and in __init__. This is true, but not obviously true. In __new__ you can simply change "dic", in __init__ this would not work:
....
You can modify the dict only indirectly, with something like cls.spam='egg' .
Yes, wishful thinking on my part ;) . Back to that old "there's no hook
to set an attribute in the dictionary of a class without going through
the descriptors mechanism" problem. I should have explicitly noted that
you can modify *attributes* of the class object inside __init__, instead
of describing the process as modifying as the dictionary of the class.
(Done now). Challenge is that people will then get away from mentally
modelling the class as a dictionary with some extra fields.
For the rest, excellent presentation!
Thanks again. We seemed to get through it without any heads exploding,
and hopefully everyone in the audience now understands them at least
well enough to be able to guage when/if then need them, and what's going
on under the covers if a meta-programmer is using them to provide
services in some library.
You forgot to mention Alex Martelli's presentation:
http://www.strakt.com/dev_talks.html
Well, hard to forget something you've never heard about before ;) .
Seems like a slightly more involved presentation, targetted more at
people trying to create metaclasses (i.e. for meta-programmers).
I tried to pitch more at the level of "should you use them", or "why
would you use them and when", or "what's going on when someone creates a
meta-class and it shows up in the library I'm using" (i.e. the audience
being primarily (non-meta) programmers). That seems to be the area that
doesn't get discussed as often when discussing metaclasses.
Anyway, thanks for the feedback, tweaked slides now available from the
same location.
Enjoy,
Mike
_______________ _______________ _________
Mike C. Fletcher
Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/
Mike C. Fletcher wrote:
... metaclasses and metamethods. See if I've got this right:
Class-declaration ends Interpreter finds declared metaclass (via whichever method) Interpreter looks for a __call__ method in type( metaclass ).__dict__ .(skipping the dictionary of metaclass due to "special"-ness of the name __call__) Interpreter executes type(metaclass) .__call__( classname, bases, dictionary )
Almost, but what gets executed is:
type(metaclass) .__call__(metac lass, classname, bases, dictionary)
i.e., the unbound-method type(metaclass) .__call__ *DOES* get the mandatory
first argument 'metaclass', of course.
Assert: It does this due to the "special method-name lookup" exception for new-style types: special methods are looked up in the type without lookup in the instance dictionary.
Yep. Exactly like *ANY* situation of foo(args) turns into:
type(foo).__cal l__(foo, args)
(except when foo is an instance of a classic-class, where for reasons
of backwards compatibility foo.__call__(ar gs) happens instead).
Hmm, definitely not something to cover early in the presentation... especially when most users haven't yet discovered the special-names exception (most programmers still haven't discovered the new features of Python 2.2 (hence my metaclass presentation)). If I were writing a "for dummies" book that would definitely have to be a "technical aside".
I think that understanding what "foo(args)" means is VASTLY more
important than grasping metaclasses, for (by far) most practical
programming tasks. The so-called "special-names exception" (which
is not an exception at all but a perfectly general rule -- on the
contrary, the exception is the behavior of classic-class instances:-)
should be clear to the listeners, otherwise they'll get their
knickers in a serious twist trying to make any real use of what
they learn about metaclasses. E.g., that metaclass.__cal l__ is what
determines what it means to call the CLASS, etc, etc. You forgot to mention Alex Martelli's presentation:
http://www.strakt.com/dev_talks.html Well, hard to forget something you've never heard about before ;) . Seems like a slightly more involved presentation, targetted more at people trying to create metaclasses (i.e. for meta-programmers).
It's more of a _presentation_ -- just the slides with the
highlights -- while yours is more like an _article_ -- much more
useful as standalone material, because you've got so much text on
each slide (but by the same token, not ideal for projection;-).
I tried to pitch more at the level of "should you use them", or "why would you use them and when", or "what's going on when someone creates a meta-class and it shows up in the library I'm using" (i.e. the audience being primarily (non-meta) programmers). That seems to be the area that doesn't get discussed as often when discussing metaclasses.
Actually, I do target "why would you use them and when", though you
do that much more widely (mine was a 45-minutes presentation, yours
a 2-hours one, I believe, just from amount of material you have on
your slides), trying to distinguish between canonical uses (quite good)
and non-canonical ones (tempting but IMHO best avoided -- it did seem
to me that Guido, who was in the audience as I presented this at
Europython, broadly agreed, and he did even explicitly bless the
convention of using 'mcl' for a first-method-argument that is a
metaclass, just as 'cls' is used for one that is a class and 'self'
for one that is an instance).
Alex This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris Stiles |
last post by:
Hi --
Some time ago I attended a course (run by Island Training I think) where
the instructor used some 'written in python' to project a
slideshow/presentation over a network onto multiple laptops simultaneously -
so each attendee could follow the course. As I recall it included basic
animation as well as the standard text bullet points.
I've looked at the usual sources (freshmeat et al) and can't find anything
like this, does this...
|
by: Michele Simionato |
last post by:
> Hello, my name is Skip and I am metaclass-unaware. I've been programming in
> Python for about ten years and I have yet to write a metaclass. At first I
> thought it was just that metaclasses were new to the language, but now as
> more and more people use them and proclaim their widespread benefits, I have
> come to realize that through years of abuse my brain has become addicted to
> classic classes.
I began using Python since...
|
by: Jean-François Doyon |
last post by:
Hello,
I'm using MetaClasses to create classes.
How do I make these new classes "globally" available?
I probably just have to assign them to something magic, but I can't seem to
figure out which one.
if I do:
|
by: Bredal Jensen |
last post by:
Hello,
Ar some point in my web pages , i need to present a power point
presentation.
Any ideas about the various way of doing this are welcome.
Many thanks in advance
JB
|
by: apm |
last post by:
Hi all
I wonder whether there is a Python module that allows to present slides
with built-in Python effects. The presentation could be specified in an
XML file and presented by a Python program that allows some kind of
scripting to add nice effects and demonstrate live execution of code
within the slides.
Is such a thing available? The packages I found that come closest are
Bruce and Emersion, but they both don't really fit my bill ;-)
| |
by: Sensei76 |
last post by:
Hello, I have the following problem and I do not know how to accomplish this.
I have an (existing) powerpoint presentation that should be displayed not
within its own window, but within a control of my own form.
So I added a reference to the Microsoft PowerPoint Object Library and tried
to run a slideshow of the presentation. For this I am using those classes
like PowerPoint.Application, PowerPoint.Presentation, PowerPoint.Slides, ......
|
by: Alan Isaac |
last post by:
Forman's book is out of print.
Is there a good substitute?
Thanks,
Alan Isaac
|
by: =?Utf-8?B?d2lsbG5wb2s=?= |
last post by:
Hello everyone. I have a PowerPoint Presentation that is 218 slides that
includes animated gifs and sounds and everything. Currently they are online
where the user will have to download the files to thier computer to view the
presentation. I need a way to maybe embed the presentation into a webpage so
that it can just be viewed online without having to download all the files to
the local PC. I have already tried countless conversion...
|
by: Dököll |
last post by:
Greetings, and salutations!
Hope you can help me...
I started to finally begin a process in powerpoint which I think should help my son with his ABCs and 123s.
I created some slides, most of which will have buttons. In testing one button, (before running wild and consider job well done)... I decided to test it lo and behold, slides are mute, no movement.
I tried all available options, it looks like the slides are not reacting to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |