Functional Programming in Python - A Sampler (Cliff)
Functional programming languages make big promises
Makes it easy to write robust, modular, decoupled code
They’re easy to test (since output is solely dependent on input)
They make programming fun
Do they deliver?
Didn’t find it worth the switching costs, personally.
Has a problem with the no I/O thing
I don’t think he gets the “no state” thing; there’s no mutable, shared state,
not no state at all.
Hallmarks of Functional Code
Functions are first-class objects
Functions are typically very small
Various Places that Functional Idioms Can Be Useful
He’s using templating as an example of how to use partials; that’s
interesting. I’m going to have to look into this.
Interesting point about Python 3’s crazy argument ordering options and
partials (how does partial application work with some of the wilder ones?)
Maybe use Python in a more functional style
Admits he doesn’t do this currently, so it’s aspirational
Use list comprehensions more
Isolating I/O looks like a good idea
Closures, decorators, and partials are a yes
Still doesn’t like recursion
Random observations by me
I didn’t realize iPython Notebook had presentation capabilities; I’m going to
have to play with that.
GNU Radio and Python (Andrew Henshaw)
According to Andrew, it’s more him showing off instead of demonstrating
GNU Radio is for signal processing
It’s a C++ kernel wrapped in beautiful Python goodness
Software-defined radio is apparently a big thing, lately
Apparently, hardware has gotten fast enough that software Digital
Signal Processing (DSP)
is fast enough to replace dedicated hardware, which brings all the
standard flexibility wins that software tends to provide over dedicated
There’s some crazy $20 dongle that can work as a receiver for just about
every frequency band you could want, and feed it into software-defined radio
Fancy: you can draw a dataflow diagram to define your
That’s pretty awesome: assuming I didn’t miss anything, he just ran
a touch-tone dialer program, in Python, generated from his fancy-pants
dataflow diagram. It was a 7.
The gremlins are out in full force (technical presentations are like crack
for these things); his GUI example with a volume slider suddenly stopped
working despite working earlier.
My computer’s battery is now toast, so you’ll have to talk to him if you want
the details of the presentation/demo.
When it comes to text editing, it doesn’t get much better than
vim—and by extension, MacVim. If this
is the first time you’ve heard of vim, or the first time you’ve
seriously considered using it, please stop now and go read
Coming Home to Vim, by Steve Losh1. That
captures the Zen of Vim better than anything else I’ve read.
If you’re still around (or back), then congratulations: you have great
taste in editors. Now on to one of the most irritating things about
vim: getting your vim all tricked out with just the right set of
plugins, color schemes, and keybindings, then getting stuck on a remote
server somewhere with a vanilla version of vim, or maybe even a
different vi clone, like nvi. Enter bcvi.
bcvi is a clever little tool that basically copies the file you want
to edit to your machine, invokes gvim on it, then copies it back when
you are done. Presto: you get to edit in the comforts of your own,
highly optimized vim environment.
All you need to do to get bcvi is install it via CPAN;
it even comes with a couple of helper commands to give you handy shell
aliases, etc. But if you’re running OSX , oh-my-zsh
(if you’re not, go read Steve’s My Extravagant Zsh Prompt
for a good explanation of just how awesome it can be), and MacVim, then
there are a couple of things that you’ll probably want to do.
As an aside, you might want to update CPAN so it stops nagging you every
time you try to install something. The default perl that ships with
OSX is under /usr/bin, so upgrading CPAN is going to require sudo.
It’s also rather old. If you’d rather, you can simply install a current
perl via Homebrew. This will get you up-to-date and allow
you to upgrade CPAN without needing sudo. You could also look into
local::lib, which I’ve used with success on servers.
The instructions I used (NOTE: some of these are probably unique to my
box, but I don’t have a spare handy to test) are:
$ brew tap homebrew/dupes
$ brew install perl
$ brew link --overwrite perl
With that out of the way, here’s how to get started with bcvi on a Mac:
Install bcvi. This is as simple as install App::BCVI from the
To make bcvi use MacVim (or possibly even work, if you don’t have
an X-based version of vim), you need to symlink gvim to mvim.
Since I have my mvim situated in /usr/local/bin, that’s where I
put the gvim symlink to it, as well.
Get those lovely aliases. Execute bcvi --add-aliases. NOTE: This
only adds them to .bashrc, so if you’re using ZSH, you need to copy
and paste them to your .zshrc.
Start the listener process. This is as simple as
bcvi --listener &, but I would never remember to type this until
the first time I tried to use bcvi and it errored out. Instead, I
use a launchd job. You can get it from
this BitBucket repo. If you’ve never used
launchd jobs before, instructions are included in the README.
Install bcvi on the remote servers where you’d like to use it using
bcvi --install hostname. This will install bcvi in $HOME/bin, so
permissions shouldn’t be a problem.
Finally, I like to add an alias so I don’t have to type
bcvi --wrap-ssh -- hostname every time I connect to a server and
want to have access to bcvi. I added the following to my .zshrc:
alias ssh-bcvi='bcvi --wrap-ssh --'
At this point, you should be able to ssh-bcvi to your remote server,
find the file you need to edit, and vi filename to edit it in the
comfort of your own vim.
Back to flipping out…
As a matter of fact, just go read everything Steve writes. I steal ideas from him all the time.↩
Fun gotcha: A trailing , will often create you a tuple, usually when
you really don’t want one. If you start seeing complaints about
mismatches in the number of arguments, it’s a good idea to look for
What really frustrates me is when I try to get clever and do something
like this only to find out that Python isn’t creating me a tuple in
this particular instance (for whatever reason).
A/B Testing with Cleaver (Ryan Petrello)
Didn’t use Visual Website Optimizer, Google Analytics, Optimizely, etc.
because they wanted a Python-based solution that targeted developers,
Found plenty of solutions, but they were all opinionated (to the point
of requiring specific frameworks). This might not be a show-stopper
for me, because tight integration usually means less config to mess
They wound up creating Cleaver (MIT licensed?), which
only requires WSGI, basically.
Basically, you use WSGI middleware to add tracking.
It has a number of pluggable backends to store the experiment data.
You can add a weight to the tuple, easy-peasy. Does not currently
support functions, but he seems confident it can be extended fairly
Comes bundled with a lightweight web UI for viewing the results.
It’s cool. I wonder how much of the statistical heavy lifting it does
(statistical power, significance, correlation with other changes, etc.)
Ryan says: They don’t do power, but it does do significance.
I missed this discussion while I was reading the README (curses!),
but I believe the control is just the first option.
### Simple Calculator Applications Using Bottle.py and Google App Engine
Lots of introductory material explaining how analytics works, some of the
problems you need to solve to make it work, etc.
Google App Engine (GAE) is a Platform as
a Service (PaaS).
You can get started for free.
You get to run on Google’s infrastructure.
You run on Google’s infrastructure:
You get BigTable, and (this is apparently new) some sort of MySQL in the
cloud thing. No traditional RDBMS.
Short-lived requests; they will kill your request if you take more than 60
seconds or so. They have at least added something called a “back-end
instance” that works around this, at the expense of the auto-scaling feature.
No writes to the filesystem.
No arbitrary access, e.g., FTP.
You’re pretty tied to GAE.
How did we do last month? ()
### or Fun with date.date, timedelta
### or dateutil to the rescue
Ever start trying to do something useful with dates in Python? It sucked, huh.
Time to write some boilerplate code! But wait! Surely Someone Has Already Solved This (SSHAST). Enter dateutil.