[Baypiggies] A mini-decorator workshop

Glen Jarvis glen at glenjarvis.com
Sat Jul 24 01:52:44 CEST 2010


I really had a good time at the talk last night. There were some *good*
questions and lots of interests -- that's always fun.

I am *very* interested in helping everyone get past this first hurdle.

If there is demand, I will hold a 2-3 hour FREE hands-on workshop over the
same material (assuming we can all agree on a date, time and location).

Please be aware that the scope of what I'm talking about is still within
what was presented. Therefore, we won't be going into, for example, the
introspection that is used in attrs. It's easy enough, but not the purpose
of the talk/workshop. We won't talk about class decorators, etc.

This first level idea is "How do I use decorators," -- not how do I write my
own or even how these decorators work internally (although we can certainly
dip our toes in at the very end of the workshop). We can also expand on how
to use decorators before the pie syntax was included in Python - as that's
still in the scope of *using* decorators.

If we have questions outside this scope, I will plead ignorance (which may
actually be true; but maybe not) and move to the next subject.

Now that I've firmly set your expectation on scope, if there's interest in
doing this, we can put together a small get together one evening after work.
Because I already have materials prepared, this won't take any lead-time to
set-up.

Note that this will give us more time. So, I can ask you to, for example:

* Write a function that takes two arguments. The first argument should only
be an integer. But, the second argument can either be an integer or a float.
Enforce this through assertions. Code should be PEP-8 compliant.
* The above, but pick one of the four decorators we discussed to do the same
thing, instead. We can then have a discussion on why a person would choose
the first (above) or this approach to do the same task. (Or some may argue
that we are pre-optimizing and we shouldn't make such restrictions on
functions unless absolutely necessary (and I would agree).
* (Other similar exercises with some of the other three decorators we have
distributed and discussed)
* Write a function that takes as its arguments two functions (we'll call f1,
and f2). Within the body of the function, call f1 and f2. Demonstrate how we
see pass functions around like any object
* Create a function that wraps another function
* etc.

If you can already do all of the above, you'd probably be bored silly and
shouldn't attend this workshop. We'll advance to deeper levels over time --
just not at this meeting.

The format would be in two portions: An introduction (same spiel as last
night), and self-paced assignments/workshop. We would take more time to work
on the example exercises. And, you would work on the examples while while we
wait for questions to help you when you get stuck.

Because this is self paced (after my initial spiel), people will finish at
different times. I can imagine we'll finish in 3 hours or less -- some much
quicker than others.

Let me know if you're interested and I'll give you a 10% discount on the
already FREE workshop ;)  This offer expires 1 week (i.e., if no one
responds by then, I'm moving on to something else)...


Cheers,



Glen
-- 
Whatever you can do or imagine, begin it;
boldness has beauty, magic, and power in it.

-- Goethe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100723/07945783/attachment.html>


More information about the Baypiggies mailing list