{ "metadata": { "name": "", "signature": "sha256:f8aad6752f850f3da58198596604ec62ee67c75f525ce1755e253fe4845daf27" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Soapbox" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "While learning python is great, I'd even more like to give you a bit of programming skills. Here, I'll mention a few of the lesser virtues that will make you a good programmer." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Read** \u2013 Reading is the most important skill for *writing* programs.\n", "\n", "*Read error messages* \u2013 Good error messages actually tell you what's wrong. If you don't understand them, try to get an understanding. That's one of the cases when it's a good idea to google an error message. *Do not* blindly edit until an error message goes away.\n", "\n", "*Read documentation* \u2013 Python's library documentation (http://docs.python.org, or the python-doc package on most open system for local usage) is fairly good and readable. Before you use a module, skim over its docs, before you use a function, have a look there (and see below for ipython's ?). Refuse the temptation to guess.\n", "\n", "*Read other people's code* \u2013 Programming is non-obvious. Just as you have to read novels to write *good* texts, read and try to understand code passed to you (or perhaps just library code, which tends to be \u201egood\u201d in one way or another). The least it will do is show you what not to do if you'd like other people to understand your program." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Plan** what you write, i.e., think a bit about what you want to write. Putting it into a little text doesn't hurt at all (we'll see later how sentences of that text could become functions). But be aware that you probably thought wrong and to *throw away* prototypes early. Programming is non-obvious, in particular with hard problems, you won't get it right the first time. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Think** before copying code. So, I can't keep you from blindly googling error messages and code snippets. There's actually some serious expertise on stackoverflow (though I still mourn the equivalent but open structure of usenet). But at least try to *understand* what the snippet is and does before pasting it. And whether it actually fits your problem." ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "The Zen of Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "About the best text ever written on the philosophy of programming is built right into your python interpreter:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import this" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The Zen of Python, by Tim Peters\n", "\n", "Beautiful is better than ugly.\n", "Explicit is better than implicit.\n", "Simple is better than complex.\n", "Complex is better than complicated.\n", "Flat is better than nested.\n", "Sparse is better than dense.\n", "Readability counts.\n", "Special cases aren't special enough to break the rules.\n", "Although practicality beats purity.\n", "Errors should never pass silently.\n", "Unless explicitly silenced.\n", "In the face of ambiguity, refuse the temptation to guess.\n", "There should be one-- and preferably only one --obvious way to do it.\n", "Although that way may not be obvious at first unless you're Dutch.\n", "Now is better than never.\n", "Although never is often better than *right* now.\n", "If the implementation is hard to explain, it's a bad idea.\n", "If the implementation is easy to explain, it may be a good idea.\n", "Namespaces are one honking great idea -- let's do more of those!\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you understand all that Tim says there a year from now, that'd be success for me" ] } ], "metadata": {} } ] }