Best ways to teach a beginner to program?

Original Question

I am currently engaged in teaching my brother to program. He is a total beginner, but very smart. (And he actually wants to learn). I've noticed that some of our sessions have gotten bogged down in minor details, and I don't feel I've been very organized. (But the answers to this post have helped a lot.)

What can I do better to teach him effectively? Is there a logical order that I can use to run through concept by concept? Are there complexities I should avoid till later?

The language we are working with is Python, but advice in any language is welcome.


How to Help

If you have good ones please add the following in your answer:

  • Beginner Exercises and Project Ideas
  • Resources for teaching beginners
  • Screencasts / blog posts / free e-books
  • Print books that are good for beginners
  • Please describe the resource with a link to it so I can take a look. I want everyone to know that I have definitely been using some of these ideas. Your submissions will be aggregated in this post.


    Online Resources for teaching beginners:

  • A Gentle Introduction to Programming Using Python
  • How to Think Like a Computer Scientist
  • Alice: a 3d program for beginners
  • Scratch (A system to develop programming skills)
  • How To Design Programs
  • Structure and Interpretation of Computer Programs
  • Learn To Program
  • Robert Read's How To Be a Programmer
  • Microsoft XNA
  • Spawning the Next Generation of Hackers
  • COMP1917 Higher Computing lectures by Richard Buckland (requires iTunes)
  • Dive into Python
  • Python Wikibook
  • Project Euler - sample problems (mostly mathematical)
  • pygame - an easy python library for creating games
  • Invent Your Own Computer Games With Python
  • Foundations of Programming for a next step beyond basics.
  • Squeak by Example
  • Snake Wrangling For Kids (It's not just for kids!)

  • Recommended Print Books for teaching beginners

  • Accelerated C++
  • Python Programming for the Absolute Beginner
  • Code by Charles Petzold
  • Python Programming: An Introduction to Computer Science 2nd Edition

  • I've had to work with several beginner (never wrote a line of code) programmers, and I'll be doing an after school workshop with high school students this fall. This is the closest thing I've got to documentation. It's still a work in progress, but I hope it helps.

    1) FizzBuzz. Start with command line programs. You can write some fun games, or tools, very quickly, and you learn all of the language features very quickly without having to learn the GUI tools first. These early apps should be simple enough that you won't need to use any real debugging tools to make them work.

    If nothing else things like FizzBuzz are good projects. Your first few apps should not have to deal with DBs, file system, configuration, ect. These are concepts which just confuse most people, and when you're just learning the syntax and basic framework features you really don't need more complexity.

    Some projects:

  • Hello World!
  • Take the year of my birth, and calculate my age (just (now - then) no month corrections). (simple math, input, output)
  • Ask for a direction(Up, down, left, right), then tell the user their fate (fall in a hole, find a cake, ect). (Boolean logic)
  • FizzBuzz, but count once every second. (Loops, timers, and more logic)
  • Depending on their age some really like an app which calls the users a random insult at some interval. (Loops, arrays, timers, and random if you make the interval random)
  • 2) Simple Project Once they have a good grasp of language features, you can start a project(simple, fun games work good.). You should try to have the first project be able to be completed within 6-12 hours. Don't spend time to architect it early. Let them design it even if it sucks. If it falls apart, talk about what happened and why it failed, then pick another topic and start again.

    This is where you start introducing the debugging capabilities of your tools. Even if you can see the problem by reading the code you should teach them how to use the tools, and then show them how you could see it. That serves the dual purpose of teaching the debugging tools and teaching how to ID errors without tools.

    Once, or if, the project gets functional you can use it to introduce refactoring tools. Its good if you can then expand the project with some simple features which you never planned for. This usually means refactoring and significant debugging, since very few people write even half decent code their first time.

    Some projects:

  • Hangman game
  • Experimenting with robotics(Vex and Mindstorms are options)
  • 3) Real Project Start a real project which may take some time. Use proper source control, and make a point to have a schedule. Run this project like a real project, if nothing else its good experience having to deal with the tools.

    Obviously you need to adjust this for each person. The most important thing I've found is to make even the first simple apps apply to what the person is interested in.

    Some projects:

  • Tetris
  • Text file based blog engine
  • More advanced robotics work

  • You could try using Alice. It's a 3D program designed for use in introductory programming classes.

    The two biggest obstacles for new programmers are often:

  • syntax errors
  • motivation (writing something meaningful and fun rather than contrived)
  • Alice uses a drag and drop interface for constructing programs, avoiding the possibility of syntax errors. Alice lets you construct 3D worlds and have your code control (simple) 3D characters and animation, which is usually a lot more interesting than implementing linked lists.

    Experienced programmers may look down at Alice as a toy and scoff at dragging and dropping lines of code, but research shows that this approach works.

    Disclaimer: I worked on Alice.


    I recommend Logo (aka the turtle) to get the basic concepts down. It provides a good sandbox with immediate graphical feedback, and you can demostrate loops, variables, functions, conditionals, etc. This page provides an excellent tutorial.

    After Logo, move to Python or Ruby. I recommend Python, as it's based on ABC, which was invented for the purpose of teaching programming.

    When teaching programming, I must second EHaskins's suggestion of simple projects and then complex projects. The best way to learn is to start with a definite outcome and a measurable milestone. It keeps the lessons focused, allows the student to build skills and then build on those skills, and gives the student something to show off to friends. Don't underestimate the power of having something to show for one's work.

    Theoretically, you can stick with Python, as Python can do almost anything. It's a good vehicle to teach object-oriented programming and (most) algorithms. You can run Python in interactive mode like a command line to get a feel for how it works, or run whole scripts at once. You can run your scripts interpreted on the fly, or compile them into binaries. There are thousands of modules to extend the functionality. You can make a graphical calculator like the one bundled with Windows, or you can make an IRC client, or anything else.

    XKCD describes Python's power a little better: "You're flying! How?" "Python!"

    You can move to C# or Java after that, though they don't offer much that Python doesn't already have. The benefit of these is that they use C-style syntax, which many (dare I say most?) languages use. You don't need to worry about memory management yet, but you can get used to having a bit more freedom and less handholding from the language interpreter. Python enforces whitespace and indenting, which is nice most of the time but not always. C# and Java let you manage your own whitespace while remaining strongly-typed.

    From there, the standard is C or C++. The freedom in these languages is almost existential. You are now in charge of your own memory management. There is no garbage collection to help you. This is where you teach the really advanced algorithms (like mergesort and quicksort). This is where you learn why "segmentation fault" is a curse word. This is where you download the source code of the Linux kernel and gaze into the Abyss. Start by writing a circular buffer and a stack for string manipulation. Then work your way up.

    链接地址: http://www.djcxy.com/p/9202.html

    上一篇: Python中的类方法是什么?

    下一篇: 教新手入门的最佳方法?