324
votes

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:


Recommended Print Books for teaching beginners

2
  • I don't understand why this should be closed. At least 295 users have found this question (and the 92 answers) to be helpful enough to up-vote it, with 290 going so far as to consider it one of their favorites. The question resulted in a very useful aggregation of teaching resources. It hasn't really resulted in 'arguments' or 'debates', but really a lot of great advice about how to address one of the difficult 'human factors' in programming. I think closing a question like this is draconian and detrimental to the StackOverflow community. Sep 17, 2011 at 17:58
  • @JustinStandard Have you considered converting your edits to several of the answers to comments? E.g. here, here, and here Oct 18, 2011 at 14:14

86 Answers 86

118
votes

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
3
  • This is a great guide. Personally, I cannot code my way out of a paper bag (I'd like to see someone do that in real life, actually), so this looks like a good guide for teaching myself too.
    – keyofnight
    Mar 8, 2010 at 1:28
  • This is a very good answer. My only objection is that Tetris not a good choice for a first or second game. At that level, the collision detection can be a hard problem - it's great if they can solve it.
    – phkahler
    Jul 11, 2010 at 22:30
  • @phkahler I see your point, but I believe Tetris is interesting because there are so many OSS/demo implementation you can analize before and after writing your code. Jul 29, 2010 at 18:43
30
votes

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.

1
  • I came to know of it through Randy Pausch's last lecture. The reasoning behind this project blew my mind. Aug 26, 2011 at 7:46
28
votes

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.

1
  • Actually, you don't fully manage the memory in C. You get to have malloc, etc, and free manage it for you. You just have to tell the system when you want more memory and when you're done with memory that you've been using.
    – compman
    Jul 24, 2011 at 0:52
15
votes

A good python course is MIT's A Gentle Introduction to Programming Using Python. It's all free online, and you don't have to be an MIT uberstudent to understand it.

Edit [Justin Standard]

This course uses this free online book: How To Think Like a Computer Scientist
I'm definitely finding it quite useful.

12
votes

Python package VPython -- 3D Programming for Ordinary Mortal (video tutorial).

Code example:

from visual import *

floor = box (pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue)
ball = sphere (pos=(0,4,0), radius=1, color=color.red)
ball.velocity = vector(0,-1,0)
dt = 0.01

while 1:
    rate (100)
    ball.pos = ball.pos + ball.velocity*dt
    if ball.y < ball.radius:
        ball.velocity.y = -ball.velocity.y
    else:
        ball.velocity.y = ball.velocity.y - 9.8*dt

VPython bouncing ball http://vpython.org/bounce.gif

1
  • Good for just after they've learned the basic concepts. Creating visuals is a great way to motivate people to learn programming.
    – phkahler
    Jul 11, 2010 at 22:32
12
votes

Begin with Turtle graphics in Python.

I would use the turtle graphics which comes standard with Python. It is visual, simple and you could use this environment to introduce many programming concepts like iteration and procedure calls before getting too far into syntax. Consider the following interactive session in python:

>>> from turtle import *
>>> setup()
>>> title("turtle test")
>>> clear()
>>>
>>> #DRAW A SQUARE
>>> down()        #pen down
>>> forward(50)   #move forward 50 units
>>> right(90)     #turn right 90 degrees
>>> forward(50)
>>> right(90)
>>> forward(50)
>>> right(90)
>>> forward(50)
>>>
>>> #INTRODUCE ITERATION TO SIMPLIFY SQUARE CODE
>>> clear()
>>> for i in range(4):
        forward(50)
        right(90)
>>>
>>> #INTRODUCE PROCEDURES   
>>> def square(length):
        down()
        for i in range(4):
            forward(length)
            right(90)
>>>
>>> #HAVE STUDENTS PREDICT WHAT THIS WILL DRAW
>>> for i in range(50):
        up()
        left(90)
        forward(25)
        square(i)
>>>
>>> #NOW HAVE THE STUDENTS WRITE CODE TO DRAW
>>> #A SQUARE 'TUNNEL' (I.E. CONCENTRIC SQUARES
>>> #GETTING SMALLER AND SMALLER).
>>>
>>> #AFTER THAT, MAKE THE TUNNEL ROTATE BY HAVING
>>> #EACH SUCCESSIVE SQUARE TILTED

In trying to accomplish the last two assignments, they will have many failed attempts, but the failures will be visually interesting and they'll learn quickly as they try to figure out why it didn't draw what they expected.

1
11
votes

The key thing is that the person in question needs to have some problem that they want solving. If you don't have a program that you want to write (and something sensible and well-defined, not "I want to write the next Quake!") then you can't learn to program, because you have nothing to motivate you. I mean, you could read a book and have a rough understanding of a language's syntax and semantics, but until you have a program that you want written you'll never grasp the nettle.

If that impetus exists then everything else is just minor details.

1
  • The best way to learn any technical subject, I think, is by learning to solve small, incremental problems.
    – cbednarski
    Jul 22, 2010 at 16:04
8
votes

I don't know if anyone has mentioned this here, yet, but You might want to check out Zed Shaw's Learn Python the Hard Way

Hope this Helps

0
7
votes

http://tryruby.hobix.com/">Try Ruby (In Your Browser)

1
  • Nice! It seems easy and powerful to use Ruby
    – Luc M
    Nov 1, 2008 at 19:42
5
votes

This is a fantastic book which my little brothers used to learn:

http://pine.fm/LearnToProgram/

Of course, the most important thing is to start on a real, useful program of some kind IMMEDIATELY after finishing the book.

4
votes

If he's interested, aren't the minor details the good parts? Using python, you've already cut the GUI off of it so that confusion is gone. Why not pick a project, a game or something, and implement it. The classic hi-lo number guessing game can be simply implemented from the command line in 20-30 lines of code (depending on language of course) and gives you variables, conditions, loops, and user input.

1
4
votes

I'd just let him write tons of code. Let him drive in everything you guys do, and just be available to answer questions.

Believe it or not, after a few months of writings tons of crappy code, he'll start to get the idea and start writing better programs. At that point, you can get bogged down in details (memory, etc), and also talk about general design principles.

I've heard that what separates the great artists from the mediocre ones, is that every time they practice, they improve on something, no matter how small. Let your brother practice, and he'll improve every time he sits down at the keyboard.

Edit: [Justin Standard]

Esteban, this reminds me of a recent coding horror post, and I do think you are right. But I think its still worthwhile to find methods to guide his practice. No question, I want him writing as much code as he knows how to do. Thats one reason I'm asking for sample projects.

1
  • Yes, I know which post you're talking about Justin. Reading it reminded me how most of the things I've learned have come from trying and learning from my own mistakes. I really can't emphasize enought the importance of learning by doing! Sep 8, 2008 at 3:49
2
votes

First of all, start out like everyone else does: with a Hello World program. It's simple, and it gives them a basic feel for the layout of a program. Try and remember back to when you were first programming, and how difficult some of the concepts were - start simple.

After Hello World, move on to creating some basic variables, arithmetic, then onto boolean logic and if/else statements. If you've got one of your old programming textbooks, check out some of the early examples and have him run through those. Just don't try to introduce too much all at once, or it will be overwhelming and confusing.

2
votes

Something you should be very mindful of while teaching your brother to program is for him not to rely too heavily on you. Often when I find myself helping others they will begin to think of me as answer book to all of their questions and instead of experimenting to find an answer they simply ask me. Often the best teacher is experimentation and every time your brother has a question like "What will happen if I add 2 to a string?" you should tell him to try it out and see for himself. Also I have noticed that when I cannot get a concept through to someone, it helps to see some sample code where we can look at each segment individually and explain it piece by piece. As a side note people new to programming often have trouble with the idea of object oriented programming, they will say they understand it when you teach it to them but will not get a clear concept of it until actually implementing it.

2
votes

I used to teach programming and your brother has one main advantage over most of my students he wants to learn :)

If you decide to go with C a friend has a site that has the sort of programs those of use from older generations remember as basic type-ins. The more complex of them use ncurses which sort of negates their use as a teaching aid somewhat but some of them are tiny little things and you can learn loads without being taught to.

Personally I think Python and Ruby would make great first languages.

EDIT: list of beginner programming assignments appeared overnight might be just what you are looking for.

2
votes

It really depends on your brother's learning style. Many people learn faster by getting their hands dirty & just getting into it, crystallising the concepts and the big picture as they progress and build their knowledge.

Me, I prefer to start with the big picture and drill down into the nitty-gritty. The first thing I wanted to know was how it all fits together then all that Object-oriented gobbledygook, then about classes & instances and so-on. I like to know the underlying concepts and a bit of theory before I learn the syntax. I had a bit of an advantage because I wrote some games in BASIC 20 years ago but nothing much since.

Perhaps it is useful to shadow a production process by starting with an overall mission statement, then a plan and/or flowchart, then elaborate into some pseudo code (leaning towards the syntax you will ultimately use) before actually writing the code.

The golden rule here is to suss out your student's leaning style.

2
votes

If your brother has access to iTunes, he can download video lectures of an introductory computer science course given by Richard Buckland at the University of New South Wales. He's an engaging instructor and covers fundamentals of computing and the C language. If nothing else, tell your brother to play the vids in the background and some concepts might sink in through osmosis. :)

COMP1917 Higher Computing - 2008 Session 1 http://deimos3.apple.com/WebObjects/Core.woa/Browse/unsw.edu.au.1504975442.01504975444

If the link doesn't work, here's a path:

Home -> iTunes U --> Engineering --> COMP1917 Higher Computing - 2008 Session 1

2
votes

there's a wikibook that is pretty good for learning python.

I don't know how the wikibooks are for other languages, but I personally learned python from the wikibook as it was in Feb 2007

ps - if you're unfamiliar with wikibooks, it's basically the wikipedia version of book authoring. it's sort of hard to describe, but if you check out a few of the books on there you'll see how it works

2
votes

I think Python is a great idea. I would give him a few basic assignments to do on his own and tell him that any dead ends he hits can probably be resolved by a trip to google. For me, at least, solving a problem on my own always made it stick better than someone telling me the solution.

Some possible projects (in no particular order):

  • Coin flip simulator. Let the user input a desired number of trials for the coin flipping. Execute it and display the results along with the percentage for heads or tails.

  • Make a temperature converter with a menu that takes user input to choose which kind of conversion the user wants to do. After choosing the conversion and doing it, it should return to the main menu.

    Here's an example of an extended converter with the same idea: http://pastebin.org/6541

  • Make a program that takes a numeric input and displays the letter grade it would translate to. It'll end up evaluating the input against if and elif statements to find where it fits.

  • Make a simple quiz that goes through several multiple choice or fill in the blank questions. At the end it will display how the user did. He can pick any questions he wants.

  • Take an input of some (presumably large) number of pennies and convert it into bigger denominations. For example, 149 pennies = 1 dollar, 1 quarter, 2 dimes, and 4 pennies.

  • Create a simple list manager. Be able to add/delete lists and add/delete entries in those lists. Here's an example of a christmas list manager: http://pastebin.org/6543

  • Create a program that will build and then test whether entered numbers form a magic square (with a 2D array). Here's some sample code, but it should really print out the square at each step in order to show where the user is in terms of buliding the square: http://pastebin.org/6544

I would also suggest doing some stuff with xTurtle or another graphics module to mix things up and keep him from getting boring. Of course, this is very much practice programming and not the scripting that a lot of people would really be using python for, but the examples I gave are pretty much directly taken from when I was learning via python and it worked out great for me. Good luck!

2
votes

Just make it fun !

Amazingly Scala might be the easiest if you try Kojo

2
votes

If your brother likes puzzles, I would recommend Python Challenge. I wouldn't use it as a formal teaching tool in a 1 on 1 tutorial, but it's something he can do when you're not together to challenge himself and have some fun.

2
votes

After going through a few free e-books, I found the best book for learning to program was Head First Programming published by O'Reily Press. It uses Python as the language and gives you programs to work on from the very start. They are all more interesting that 'Hello World'. It's well worth the money I spent on it, and since it's been out for a bit you may be able to find a cheaper used copy on Ebay or Amazon.

1
vote

If you want to teach the basics of programming, without being language specific, there is an application called Scratch that was created in MIT. It's designed to help people develop programming skills. As users create Scratch projects, they learn to create conditions, loops, etc. There is a also a community of scratch projects, form which projects can be downloaded - that way you can explore other people's programs and see how they were built.

1
vote

I think that once he has the basics (variables, loops, etc) down you should try to help him find something specific that he is interested in and help him learn the necessities to make it happen. I know that I am much more inclined and motivated to do something if it's of interest to me. Also, make sure to let him struggle though some of the tougher problems, nothing is more satisfying than the moment you figure it out on your own.

1
vote

I was taught by learning how to solve problems in a language agnostic way using flowcharts and PDL (Program Design Language). After a couple weeks of that, I learned to convert the PDL I had written to a language. I am glad I learned that way because I have spent the majority of my years programming, solving problems without being tied to a language. What language I use has always been an implementation detail and not part of the design.

Having to solve the problem by breaking it down into it's basic steps is a key skill. I think it is one of the things that separates those that can program from those that can't.

As far as how you tackle the order of concepts of a language I believe the easiest way is to decide that is to have a project in mind and tackle the concepts as they are needed. This lets you apply them as they are needed on something that you are interested in doing. When learning a language it is good to have several simple projects in mind and a few with progressive complexity. Deciding on those will help you map out the concepts that are needed and their order.

1
vote

I would recommend also watching some screencasts - they are generally created in context of a specific technology not a language, though if there's Python code displayed, that'll do :). The point is - they're created by some good programmers and watching how good programmers program is a good thing. You and your brother could do some peer programming as well, that might be an even better idea. Just don't forget to explain WHY you do something this way and not that way. I think the best way to learn programming is from good examples and try not to even see the bad ones.

1
vote

Robert Read wrote a useful guide, How to be a Programmer, which covers a wide area of programming issues that a beginner would find helpful.

Not the answer you're looking for? Browse other questions tagged or ask your own question.