For the instructor

This book contains all the example programs used in my CoderDojo class to teach Python programming. The primary goal of the class is to teach programming using action games to make learning more interesting. Some of the examples are entirely focused on introducing new language concepts or showing how the Raylib API works, but most are a mixture of both.

The intention is that each program in the example chapters is brief, complete and introduces only one or two new concepts.

  • The programs are short so that students can feasibly type them in during the class. Typing for themselves is very valuable for beginners, because it helps them learn to type, and to type precisely without mistakes (which show up as syntax errors). Even if it takes them a while, they should feel proud when they type a program correctly in the end! 1

  • No-one actually knows how best to teach coding, so there are a variety of approaches, but some studies have shown students enjoy doing purely syntactic practises, and those who do them go on to do better when learning semantics.

  • Initially, each program is complete to avoid the confusion caused by worksheets that tell a student to add lines to a program piecemeal. If they make an error or omit a step they may never recover and not produce a working program. Also being complete and separate means the whole class can be told to skip to the same program and it won’t matter so much that some of them didn’t complete all the prior programs. The more advanced chapters do use the piecemeal approach but always include a complete listing of the end result.

  • Introducing ideas one or two at a time allows the students to learn mostly through doing and observing the output of each program rather than memorizing. To this end the order of the programs within each chapter has been carefully selected. The chapter ordering is looser and it is possible to skip back and forth between chapters. If the text quizzes or the Python fundamentals are boring the students, skip ahead to the graphical games, then come back to the earlier examples when necessary.

This is a practical approach, and so the programs are the core of it. In the first edition they were all of it. In this edition explanatory text has been added, but for those who don’t have the patience to read, this is can be skipped. The code cannot.

Following each program are some ideas for how students can modify the program. Hopefully they will go further and modify these programs into their own unique games! The difficulty of these suggestions varies, to accommodate students of different age and ability.

This book is suitable for self-teaching by a motivated learner, but does not attempt to be comprehensive or give detailed explanations because it is intended to be used in a class with an instructor who will fill in the gaps as needed by the students.

The second edition

I discovered two important things from feedback from the first edition:

  1. It’s not possible to learn coding with only a single lesson each week. Therefore if that is all we have, the time is better spent inspiring interest in the subject rather than memorizing syntax or wrapping their heads around abstract concepts. Those who are motivated to learn more in their own time will require more syntax and concepts, of course, and hence the Fundamentals chapter has been greatly expanded for their use.

  2. Many students wanted to create larger games than the simple examples given in the first edition. It was always the intention that they absorb the knowledge from the examples and then go on to greater larger games of their own but some will require more hand-holding.

Therefore there are four new chapters of tutorial style examples. These are intended to be done in class, with the initial code file given to the students to save time. They are intended to create a sense of accomplishment as each subsequent modifcation improves the game, and also to allow lots of scope for student creativity and customisation.

As noted above, tutorials can become confusing, but I hope the class instructors can resolve any issues.

The third edition

The library used in this book has been switched from Pygame to Raylib. The initial motivation for this was to allow the addition of 3d graphics, which are the main new addition to the book.

But there are other advantages. It turns out that the ‘zero boilerplate’ approach, in the sense of making the program as short as it can possibly be, is not actually most conducive to learning. Sometimes being explicit rather than implicit is good.

So the Raylib programs are usually a couple of lines longer, but they expose the student to more of what is going on in the computer and I hope provide an easier transition into using a ‘real’ API, without being dependent on training wheels.

1

For writing essays nowadays people can use voice input and touch-screen input, but for programming the majority of programmers still type on a keyboard. There’s no sign of this changing in the immediate future, so practising keyboard skills now is still very important for the future. Students can practise at home with a program such as TuxType. That being said, many programs contain similar code, so it’s also a useful skill for them be able to copy and paste from their other programs.