[CentralOH] Most important Python techniques?
eric at intellovations.com
Tue May 15 20:29:20 CEST 2012
> We're experimenting with offering our Computer Science I class in
> Python rather than Java next year at Muskingum University.
> I'd like to get suggestions from people who know Python better than I
> do about the most important Pythonic techniques to learn.
> But if you were teaching someone new to Python, what would you
> make sure you taught them above all else?
This is an intro to computer science class, so I assume these are
people fairly new to computer science. List comprehensions and
extended slicing have to be my favorite Pythonic techniques (others
may say generators or metaclasses), but I don't think that's
important, and you can be a successful Python programmer without
knowing anything about that.
The key to what makes Python a *great* language is you can get stuff
done quickly, with little boilerplate, and the constructs are readable
and make sense compared to many languages. You can read and
understand the code you wrote six months ago.
With that said, you've had a successful CS 101 class if students can
get stuff done that they need to do quickly and easily. Python
enables that, but how? Here are what I think are the top two things
to teach above all else:
1. Interactivity. Not a day goes by that I don't fire up the Python
interactive shell to do a quick calculation, parse, or some other
thing. Interactivity allows you to "play around" with code and data.
When I'm writing a new web scraper, I'll load up the html page via
lxml in the shell (python is built in obviously, but ipython has some
nice features like tab-completion, easy help, etc.), and play around
with different searches, xpaths, etc. to find out how best to pull out
what I need.
2. Libraries. Sure, at some point you want to teach the fundamentals
(i.e. sorting algorithms and such) but that can wait along with
machine language, Von Neumann architectures, turing completeness, big
O, etc. What should really be taught in CS 101 is how to translate
from what you need done into working code. For most things, there is
already going to be a library out there does most or all of what they
need. Teach them how to find those libraries (google searching,
examples, etc.) and how to install them (pip, etc.). Learning how to
navigate through libraries to find what you need rather than building
it yourself is more fundamental than knowing what big O means. Give
them a taste for the amazing amount of stuff that's out there, like
PIL, or pygame, or lxml, or requests, that will show them that
whatever cool, fun, interesting, helpful idea they have, they'll be
able to see it through.
In the end it isn't so much about the language, as it is about getting
things done. I grew up on the VIC-20 and C64 BASIC, which is
interactive, and while it didn't have much in the way of libraries, it
was accessible the way libraries make things today. I couldn't parse
xml on my VIC-20, but I could change the color of a pixel on the
screen very easily. That's what is missing today with computers: they
are powerful beasts that will bend to your bidding, but they aren't
interactive or accessible. Instead, they are just Facebook terminals.
That's what Python brings to the table. It helps you solve problems.
And that's really, fundamentally, what CS is all about.
More information about the CentralOH