Wandering Thoughts archives


The Python language tutorial is a gem

One of the things that my recent experience learning JavaScript has made me realize (or at least reminded me) is that the Python language tutorial is a gem. Specifically it's clearly a gem starting at section 3, An Informal Introduction to Python.

What the tutorial excels at is getting someone who already knows programming up to speed in Python very fast. It doesn't try to teach you everything (although it covers quite a lot) and it assumes that you can pick things up on the fly (eg, a certain amount of syntax only appears in the examples), but if you can keep up you can absorb a significant amount of Python in a few pages. Someone who really finishes the tutorial will have easily learned enough Python to do quite a lot of useful work. Oh, and the tutorial does all of this without glossing over complexities; the tutorial may not cover everything, but what it covers it covers accurately.

(The fastest way to get me to distrust any language introduction is to tell me something that I know is not true. I ran into several quick introductions to JavaScript that over-simplified its peculiar ===, for example.)

At a pragmatic level what the tutorial really is, where it's important, is that it's a great tool for turning general programmers into Python programmers; it makes it easy, almost effortless, to take a look in. If you have a not too large problem that you think Python might be the answer for, you can read the tutorial and know one way or another in an hour or two. In the process you'll have picked up enough to get a feel for the language and whether or not you particularly like it.

But pragmatism isn't everything. Beyond its usefulness for recruiting, the tutorial is simply a gem of teaching. Somehow it has managed to boil things down just right; it knows what to leave out, what to elide, and what to put into examples and let you follow along. If you look at it objectively the tutorial makes a an awful lot of courageous assumptions about what the reader can follow, but I firmly believe that it gets them right. Its boldness and willingness to assume intelligent interest on the reader's part is refreshing.

(Although I don't know the history of the tutorial, I salute the kind of authorial courage that I suspect it took to not make the tutorial slower, more verbose, and more timid. There's always an urge to put in an extended explanation just in case part of the audience didn't get it or didn't have the background you expected.)

Oh, and on a side note, one of the things that tutorial is also great for is quickly coming up to speed on major new Python features. I started on Python in the 1.5 era, and I'm pretty sure that I learned list comprehensions, generator expressions, and a few other things from reading new sections of the tutorial.

It vaguely boggles me that so few other languages seem to try to have any equivalent of the Python tutorial. In today's environment, many people who already know programming in general will be trying to pick up your language specifically; what they want is exactly this sort of quick tutorial to bring them up to speed. Yet I've barely seen any attempts in the various languages I've looked at over the years, even though it probably wouldn't be all that difficult to take the Python tutorial and rewrite the specific syntax details for your own language.

(This whole issue was brought to mind partly by not finding anything like this for JavaScript, even for the basic language. I found some crude, flawed attempts but none that I thought were half as good as the Python tutorial.)

python/PythonTutorialGem written at 22:47:08; Add Comment

My two approaches to learning (programming) languages

Since I just learned enough JavaScript to do something, I've been thinking about how I get to the point with a programming language where I can do something useful in it. There are two major patterns that I can recognize in my past, which I will call the surgical strike and assembling a construction kit.

In the surgical strike, I focus on learning just enough of the new language (and its libraries) to write the little program that I want. Surgical strikes work best in 'obvious' languages without dangerous surprises, ones that are similar to things I already know, and on relatively simple problems that the languages are good at dealing with. I've started learning a whole lot of languages through surgical strikes, including both Perl and Python.

(For example my first Python program was a quite simple 20-line script to scan a directory and generate a lilo.conf that corresponded to what kernels were there. Yes, this was quite a while ago.)

In the assembling a construction kit approach I spend a bunch of time learning much of the language (and its environment and libraries) in order to build up a 'construction kit' of how to use the language in my area. Only once I've assembled my kit can I actually tackle my real problem and write code. The construction kit approach is what I resort to when I'm faced with a complex environment, a novel language, or a problem that the language is not tuned for. I learned JavaScript (and JQuery) almost entirely this way, because it was clear to me that browser JavaScript is an inherently complex environment and any attempt at a surgical strike would probably produce a horrible mess of hacks.

The advantage of the surgical strike is that it gets me results fast, both solving my immediate problem and giving me firm evidence that I'm getting somewhere with the language. The drawback is that each step doesn't get me very far; it can take a lot of surgical strikes before I actually really know a language (and generally I will stop trying to do surgical strikes at some point and just thoroughly learn the remaining stuff).

The drawback of assembling a construction kit is that there is a lot of slogging before I feel I've actually achieved anything. I at least find it somewhat demotivating to spend a bunch of time reading through (eg) JavaScript and JQuery resources without actually doing anything real; sure, I've read things but that's not actual, visible progress. It's just a slog. The advantage of building a construction kit is that once I've assembled the kit I can suddenly make a lot of progress quite fast because there's a lot I can now build with very little further learning. Once it starts happening this is very motivating and makes a great payoff for all of my prior slogging.

The two are different experiences for me. I wouldn't call one better or worse, although it's easier to stay motivated with surgical strikes.

(Of course one can do things as a hybrid approach, for example assembling a construction kit with the base language and then mostly taking a surgical strike approach with some package or library you need to use. I sort of did this with the JQuery side of my JavaScript learning.)

programming/LearningLanguagesTwoWays written at 02:13:06; Add Comment

Page tools: See As Normal.
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.