Preface

Welcome to Python programming with Strype! In this book, you will learn the fundamentals of programming in Python, using the Strype programming environment. The goals of this book are two-fold.

First, we want readers to learn fundamental programming principles. After working through this book, you will have acquired quite a thorough understanding of how programming works, how to structure programs, and what makes good programming practice. We will use Python as the language for doing so, and along the way you will learn a lot about Python programming. However, Python itself is not the main goal, and we do not attempt to teach all of Python’s constructs. Rather, Python is a means to discuss programming principles more generally, and much of what you learn here will transfer directly to programming in other languages.

Second – and equally important – we want readers to experience the joy and thrill that programming can bring you. We are aware that readers who have not programmed before may frown at this statement, and question whether the words "programming" and "joy" can go together in the same sentence. But they really can!

This book emphasises creativity – the making of things. In each chapter, we will challenge you to add your own ideas, to extend what we show you, to create programs that are truly your own. There is real joy when a programmer sees one of their own creations working for the first time. Everyone who has programmed has experienced this, and we very much want you to experience this feeling as well.

A note for learners: How to use this book

There are many ways to read this book. You could read it sequentially, from beginning to end, and everything in between. Or you can jump around, dip in and out, look forward, and come back when you are missing something.

The main thing is: be curious. With the sequence of the chapters in this book, we are suggesting what we think is a sensible order of activities, but we also realise that everyone’s starting point is different. Concentrate on what interests you.

One thing, however, is crucial: Make sure to do the exercises and the practical work while you read this book. You will not get much out of the book without doing so. Programming is a contact sport: you will not become a programmer just by reading about it. This book tries to put you in a position where you can actively do some programming tasks, but it is only in the actual doing that you will learn.

You may wonder: Is it still worth going to the trouble of learning all this when AI is here and could do it for me? The answer is very definitely: Yes, it is still worth doing it! To work with AI properly, we need to understand, in detail, what the AI has written. And for that you need to be able to program. You will never become a good programmer – even with AI – if you cannot read and write the code yourself. So for the purpose of this book, we recommend that you do not use AI to write your code (although you may at times use it to explain the concepts). Only by reading, writing and struggling through yourself can you truly learn.

While you do the programming activities: be patient. The early chapters of the book start with easy tasks, but they get more difficult later on.

Spend a good amount of time with each topic. Extending the suggested projects will help you understand more. Add your own ideas, until you feel comfortable at each stage.

As you move through the book – whether it is in sequence or by jumping back and forth – pay attention to the concept summaries at the end of the chapters, and do not be afraid to go back to sections you have previously completed.

A note for teachers: Pedagogy

Pedagogy is the term for the art of teaching. The authors of this book have many years of experience in teaching programming, and this experience has shaped the approach of this text. This book follows a carefully designed pedagogy based on worked examples, scaffolding, a spiral approach and working from the concrete to the abstract.

Worked examples are used throughout, and all concepts are introduced and practiced via concrete projects. Emphasis is placed not only on the end product – the finished program – but also on the process of developing it.

Many textbooks follow a common pattern: A problem is presented, a solution is shown, and then the constructs used in that solution are explained. This is a terrible approach. It creates the illusion that a good programmer goes in one step from reading the problem description to writing down a fully working solution. This is not how programming works.

A result of this approach often is that learners who struggle with finding the right solution, or with making it work quickly, think they are failing. They react by developing a self-image of "I am not a good programmer" and "programming is just not for me".

The fact that we all work in small steps, try things out, run into problems, backtrack, try something different, and slowly work our way to a solution seems to be one of the best kept secrets in programming.

This is a shame.

In this book, we show not only the product, but the process of programming. With each project, we go through several phases of extension and refinement. Learners experience the process, and can follow along. We use a process of scaffolding to provide meaningful context while keeping learners focussed on the topic at hand, and fading of the scaffold and guidance over time.

At the same time, the examples are selected to be open-ended and extendable, so that learners are encouraged to take each example further in a direction of their own interest. Each chapter includes suggestions to do more.

We also use a spiral approach. When we first encounter a construct, we do not try to explain or understand everything about it. We learn what is necessary at that point, and then refine our understanding later. We come back to the concept in a different context, and then again later still – and in each iteration we deepen our understanding.

This is a more natural and useful approach to understanding programming. Firstly, many programming constructs are circularly dependent on each other, and there is no linear sequence in which everything can be explained only by backwards reference. But more importantly, when books try to explain everything about any given concept at once (think, for example: types) learners cannot usually distinguish what is needed at that moment ("what do I need to know right now?") from what is there only for completeness’s sake. The important is buried in the detail, and learning is made harder.

The spiral approach serves to break this linear form, iterate over concepts several times, and lead to a deeper understanding.

Strype

The other obvious difference of this book is the use of the Strype environment.

Strype is a browser-based educational Python development environment designed specifically for novice learners. It is free to use, and anyone can use it instantly – no creation of accounts is needed. Strype uses a frame-based editor: frame-based editing is an interaction style that combines the best of both worlds of block-based and text-based editing. It provides the discoverability and some of the error avoidance of blocks, but at the same time gives you the power and expressiveness of a full, professional language. Some of the friction of getting your programs to run is removed, and you achieve results more quickly and with less frustration. The use of Strype, and its integration in this book, are absolutely fundamental to our approach.

As we stated above, our firm goal is to make the first experience of programming engaging, fun and creative. One way to do so, for example, is the early use of graphics and animation. Yet animated graphics are much too complicated for novices to use in most Python environments.

Strype is designed to make this approach simple, painless and possible. We can create a graphic in a single line of code, and animate it in just a few lines more. The effect of program statements becomes immediately visible on screen in a way that no "Hello world" program can ever manage, and learners can observe their program execute.

The technology and the pedagogy used in this book were developed in tandem, with environment design strongly guided by our pedagogical principles. The result is a package of software, examples and explanation that is seamlessly integrated, and enables learners to achieve more satisfying results than they might with other systems.

Overall, we strongly believe that this helps the most important aspect of all: motivation. We hope to spark our readers' curiosity, to leave you wanting to read on, to continue to learn, because you have caught the programming bug just like we have.

We hope that you will see not only how programming works, but also why you might be interested in it, and what it can do for you.

The book sequence

This book is the first volume in a sequence of books, which take the reader from a complete novice, with no prior knowledge assumed, to quite sophisticated programs. You can work with this volume on its own – it forms a coherent unit – or you can go on to study the other volumes as well. Each volume is self-contained, but the sequence builds up to higher skill levels.

Creative Python Programming with Strype

Cover of Vol 1

Volume 1 – Getting started with Python

This first volume is the one you are reading now. It takes you from the very beginning – knowing very little or nothing at all about programming – to the point of being able to write quite sophisticated programs. Part of this is learning how to create an interactive graphical game.

The activities in this volume are very carefully constructed and sequenced to teach you many general and fundamental programming concepts and constructs. Additional projects encourage you to try out what you learned and apply it in other contexts. At the end, you will have a good understanding of all of the important fundamental concepts of programming.

Cover of Vol 2

Volume 2 – Working with data

In this book, we start to work more seriously with large amounts of data. The reader learns, for example, how to write programs to analyse text, and we develop projects to analyse whole books to gain some insight about them.

In the process, we learn a lot about text processing, and about working with lists. In fact, with the exercises in this book you will become quite fluent in list processing, and understand how to use Python lists to solve all sorts of problems, from analysing data to manipulating sound.

Cover of Vol 3

Volume 3 – Structuring data

This volume builds on the previous one and dips into even more interesting projects. We learn how to use a greater variety of data structures, such as tuples and dictionaries in addition to lists, and how to combine these to model more interesting data. We do not only analyse data sources, but we also take a look at generating text, in a way a text prediction algorithm might do. In the process, we will even gain a basic understanding of the inner workings of large language models (LLMs) when we write a simple version of an algorithm that is at the core of these systems.

Acknowledgements

We wish to thank Pierre Weill-Tessier for his work on the implementation of Strype. Pierre is, together with the authors of this book, a core member of the team that designed and implemented the Strype software. His work is present in many details of the system, and with that, he has contributed greatly to the outcome of this project.

We are also indebted to Pete Dring, who provided feedback on an early draft of this book. Pete’s feedback has helped to improve this book in many places. His comments were thoughtful, detailed and specific, and the book is better because of them.