Table Of ContentA ‘must-read’ for students embarking on their first major projects, and any teacher
stepping up to the challenge of teaching Computing at school. This is not just a book
about programming, more a template for teaching. Karl Beecher speaks in plain English.
Incisive insight and practical advice, standing independent of the Python exemplars
used, predicated as it is on a holistic understanding of the subject terrain.
Roger Davies, Director of IT, Queen Elizabeth School, and Editor,
Computing At School, Tenderfoot Training Project
I really enjoyed this book - it bridges the gap between the very practical, but perhaps
narrow, field of computer programming with the real world problems that computer sci-
entists might need to solve. The issue with encouraging young people to learn ‘coding’
is that they often struggle to understand how and when to use specific concepts and
ideas. The underlying principles and real world applications are essential, and much
harder to put across, than remembering the syntax for an IF statement. The discussions
are presented in a readable format that would be suitable for bright GCSE students and
should be essential reading for all A Level computer scientists.
With the shift in focus at GCSE and A Level alike, from ‘programming’ to ‘computational
thinking’, explanations and examples of abstraction, decomposition and generalisation,
along with modelling, logic and efficiency are both engaging and useful.
Mark Clarkson , Subject Leader and CAS Master Teacher
Computational Thinking is a sprint through the theoretical underpinnings of computa-
tion through to their application and the creation of software. The thirteen chapters
start with an explanation of what is computational thinking, move through logical and
algorithmic thinking, abstraction and modelling, to then focus on how to apply these
concepts. The middle set of chapters cover how to create software with a focus on
object-oriented solutions with a relatively short discussion on testing. Python is used as
the programming language to demonstrate the use of the various techniques introduced
in the early chapters but it would be straight forward to convert the examples to other
similar languages such as Java, C#, etc. The final chapter provides a guided example
based on the creation of a computer-controlled home automation system. Each chapter
has a set of exercises to work through and model answers for these are supplied in an
appendix.
This is a very good overview of a very large field. While all of the topics are deserving of
their own book the strength of this book is the explanation and demonstration of their
close relationships. This book is an excellent complement to the many books on the
Raspberry Pi and Python programming because it starts to explain some of the theoreti-
cal underpinnings. The seasoned software developer should not be discouraged by the
beginner’s guide sub-title as this is also a good refresher on some of the basics.
Colin Smythe, Dunelm Services Limited, Principal Consultant
A scholarly book albeit written from a pragmatic perspective distilling the knowledge
and expertise of an experienced software developer into a form that is accessible for
beginners. It’s engaging exercises and comprehensive references make it an invaluable
learning resource. I would recommend it to anyone who wishes to gain an understand-
ing of computational thinking and best practice in modern software development.
Professor Cornelia Boldyreff, University of Greenwich
This book will prove an excellent companion to more general texts on Computing, espe-
cially for teachers who are new to the subject. And with exercises at the end of each
chapter, there is much to challenge students also. Highly recommended.
Terry Freedman, independent education technology writer and consultant,
and publisher of the ICT and Computing in Education
website at www.ictineducation.org
COMPUTATIONAL THINKING
BCS, THE CHARTERED INSTITUTE FOR IT
BCS, The Chartered Institute for IT, champions the global IT profession and the interests
of individuals engaged in that profession for the benefit of all. We promote wider social
and economic progress through the advancement of information technology science
and practice. We bring together industry, academics, practitioners and government to
share knowledge, promote new thinking, inform the design of new curricula, shape
public policy and inform the public.
Our vision is to be a world-class organisation for IT. Our 75,000-strong membership
includes practitioners, businesses, academics and students in the UK and internationally.
We deliver a range of professional development tools for practitioners and employees.
A leading IT qualification body, we offer a range of widely recognised qualifications.
Further Information
BCS, The Chartered Institute for IT,
First Floor, Block D,
North Star House, North Star Avenue,
Swindon, SN2 1FA, UK.
T +44 (0) 1793 417 424
F +44 (0) 1793 417 444
www.bcs.org/contact
http://shop.bcs.org/
COMPUTATIONAL THINKING
A beginner’s guide to problem-
solving and programming
Karl Beecher
© BCS Learning & Development Ltd 2017
The right of the author to be identified as author of this work has been asserted by him in accordance with sections
77 and 78 of the Copyright, Designs and Patents Act 1988.
All rights reserved. Apart from any fair dealing for the purposes of research or private study, or criticism or review,
as permitted by the Copyright Designs and Patents Act 1988, no part of this publication may be reproduced, stored
or transmitted in any form or by any means, except with the prior permission in writing of the publisher, or in the
case of reprographic reproduction, in accordance with the terms of the licences issued by the Copyright Licensing
Agency. Enquiries for permission to reproduce material outside those terms should be directed to the publisher.
All trademarks, registered names etc. acknowledged in this publication are the property of their respective
owners.
BCS and the BCS logo are the registered trademarks of the British Computer Society, charity number 292786
(BCS).
Published by BCS Learning & Development Ltd, a wholly owned subsidiary of BCS, The Chartered Institute for IT,
First Floor, Block D, North Star House, North Star Avenue, Swindon, SN2 1FA, UK.
www.bcs.org
Paperback ISBN: 978-1-78017-36-41
PDF ISBN-13: 978-1-78017-36-58
EPUB ISBN-13: 978-1-78017-36-65
Kindle ISBN-13: 978-1-78017-36-72
British Cataloguing in Publication Data.
A CIP catalogue record for this book is available at the British Library.
Disclaimer:
The views expressed in this book are those of the author and do not necessarily reflect the views of the
Institute or BCS Learning & Development Ltd except where explicitly stated as such. Although every care
has been taken by the author and BCS Learning & Development Ltd in the preparation of the publication, no
warranty is given by the author or BCS Learning & Development Ltd as publisher as to the accuracy or com-
pleteness of the information contained within it and neither the author nor BCS Learning & Development Ltd
shall be responsible or liable for any loss or damage whatsoever arising by virtue of such information or any
instructions or advice contained within this publication or by any of the aforementioned.
Typeset by Lapiz Digital Services, Chennai, India.
vi
CONTENTS
List of figures and tables xi
Author xiv
Acknowledgements xv
Glosary xvi
INTRODUCTION: WHY STUDY COMPUTATIONAL THINKING? 1
PART I COMPUTATIONAL THINKING 5
1. WHAT IS COMPUTATIONAL THINKING? 7
Objectives 7
What is computational thinking? 7
How is computational thinking used? 9
Disclaimers 11
Summary 13
Exercises 13
2. LOGICAL AND ALGORITHMIC THINKING 14
Objectives 14
Approach 14
Logical thinking 15
Algorithmic thinking 25
‘Gotchas’ 30
Summary 36
Exercises 37
3. PROBLEM-SOLVING AND DECOMPOSITION 39
Objectives 39
Where to start 39
Defining the problem 40
Devising a solution: Something to keep in mind 42
Decomposition 43
Other effective strategies 47
Patterns and generalisation 50
Summary 54
Exercises 55
4. ABSTRACTION AND MODELLING 57
Objectives 57
Abstraction 57
vii
CONTENTS
Modeling 64
Summary 74
Exercises 74
5. ANTICIPATING AND DEALING WITH ERRORS 76
Objectives 76
Coming to terms with bugs 76
Designing out the bugs 77
Mitigating errors 80
Testing 82
Debugging 85
You can’t have everything: Deciding which errors to fix 88
Summary 90
Exercises 90
6. EVALUATING A SOLUTION 92
Objectives 92
Solution evaluation 92
Is it correct? 93
Is it efficient? 94
Is it elegant? 97
Is it usable? 99
Trade-offs 101
Summary 104
Exercises 105
PART II COMPUTATIONAL THINKING IN SOFTWARE DEVELOPMENT 107
7. TUTORIAL FOR PYTHON BEGINNERS 109
Objectives 109
Introducing Python 109
First steps 109
Basic types 110
Basic operations 111
Functions 112
Comments 113
Summary 113
Exercises 113
8. EFFECTIVE BUILDING BLOCKS 115
Objectives 115
Logic 115
Basic algorithmic constructs 116
Program state 124
More advanced constructs 131
Summary 137
Exercises 138
9. ORGANISING YOUR CODE 139
Objectives 139
Recap 139
viii
CONTENTS
Introducing tkinter 140
Separating concerns 141
Defining information scope 145
Using modules 150
Packages 157
Summary 159
Exercises 160
10. USING ABSTRACTIONS AND PATTERNS 162
Objectives 162
Finding patterns in programs 162
Abstractions in programming 164
Built-in types 165
Creating your own types 166
Ready-made patterns 175
Summary 182
Exercises 182
11. EFFECTIVE MODELLING 184
Objectives 184
Recap 184
Entities 186
Relationships 189
Processes 194
Usage 196
General advice 199
Summary 201
Exercises 201
12. TESTING AND EVALUATING PROGRAMS 203
Objectives 203
Introduction to program testing and evaluation 203
Anticipating bugs 203
Verification and validation 209
Testing the parts 210
Testing the whole 214
Debugging 219
Summary 225
Exercises 225
13. A GUIDED EXAMPLE 227
Problem definition 227
Problem decomposition 228
Finding patterns 229
Form generalisations and abstractions 232
Models 233
Annotated source code 237
Testing 243
Opportunities for improvement 246
ix