Using the Raspberry Pi in introductory programming

The problem with computer science is that while the computing field has moved in leaps and bounds over the past 30 years, many institutions are still approaching introductory programming in the same way that it was tackled 30 years ago. Or maybe worse. For years good programming languages designed for teaching programming were forsaken for the latest and greatest languages. Languages like Java and C were never meant to be used to teach programming concepts – but that rant is for another post. While programming languages became bloated, computers themselves have come to resemble black boxes, with students having little notion of what really happens in the “guts” of a system. The realm of the command line, the use of shell scripts, and processing languages such as awk have drifted off into the mists of time. In a matter of a decade society has become mobile-centric with respect to computing devices. Traditional introductory programming courses have focused on the use of desktop to teach students the art of programming. The problem with such traditional approaches is that they do not invite exploration, or motivate interest. What has been lost in the last 20 years? – the art of tinkering with machines. Yet the idea of exploration cannot be readily achieved by trying to develop “apps” in an introductory curricula either – such a process requires a broad understanding of the process of software development. Introductory programming is about learning the basic tenets of programming: problem solving, algorithm design, programming language constructs, syntax, debugging, testing, usability, etc. Is there a happy medium? Maybe – the Raspberry Pi.

Rpi

The Raspberry Pi

A credit-card sized computer (well marginally bigger – it won’t fit in your wallet), is inexpensive and provides a platform for students to start exploring the “machine” – it’s basically a processor board with a bunch of peripheral connections – if students want a case they have to buy one – or make one themselves. They have to learn how to interact with the device, both through physically connecting it to I/O devices and through building simple devices which can be controlled through the GPIO interface. Students also have to explore the lower level of the machine – the command line interface. By tinkering with the Pi, they gain a better understanding of the inner working of the machine.

rpi_chip

The heart of the Pi

We have introduced the Raspberry Pi as the system used in both of our first year programming classes at the School of Computer Science at the University of Guelph. The first programming course, has an enrolment of over 700 students, and may be one of the largest applications of the Raspberry Pi in an introductory class in all of North America.

rpi_gpio

The GPIO interface

Here’s a preliminary version of a paper we recently published: Making Programs With The Raspberry Pi

Citation information: Wirth, M., McCuaig, J., “Making programs with the Raspberry Pi“, in Western Canadian Conference Computing Education, May 2–3, 2014, Richmond, BC, Canada (published by ACM).

Optimization in real-world apps

When you design a program, the primary concern is how accurately and reliably it runs. Programs exist to perform some task, not to run in the shortest possible period of time. If the task cannot be completed, or completed inaccurately, then having it run fast is a waste of time. In addition, efficiency is a feature that can be added; accuracy is not. An accurate yet inefficient program can be optimized and made more efficient; the same is not true for an unreliable fast program. Inaccurate programs are useless, no matter how fast they run. Forget about how efficient a program is—unlessthere is cause to be efficient. Program efficiency is vital in real-world applications, particularly in the context of speed and resources being consumed.

The problem with code today is that it runs too fast. Thirty years ago algorithms could be compared, and students got a feel for how different algorithms functioned – from the perspective of resources consumed and speed. This obviously had an impact on mid 1980s systems such PCs running the 80386 chip with a speed of 12-40 MHz, or the Apple Mac Plus at 8 MHz. You had to write somewhat efficient code or it would take *ages* to run. Okay, so now all machines are fast right, so who cares about optimization? Well machines are faster, but there is also way more data to contend with. A 1MP image takes way less time to process than a 20MP image. HD video takes a lot more power to stream. Inefficient algorithms eat more processor power which in turn eats more battery juice. It’s a vicious cycle. Consider this – you’re on summer holidays, the weather is hot, and the sky is kind-of hazy – not really conducive to taking great pictures. The solution of course is a filter that removes the haze from the image via post-processing on the camera. This is a great idea, but if the filter takes 1-2 minutes to run it will not be effective. If you run this off-camera it may be less of a deal, but a filter like this on camera should likely run in 5-10 seconds. It doesn’t matter how good the algorithm is, people want it to run in a reasonable time-frame.

inefficient algorithms ⇒ more processor time ⇒ battery drain ⇒ reduced mobile device battery life

Computer Science presentations for schools

Over the past few years I have given a number of talks at schools in the Greater Toronto Area. The talks are usually geared towards high-school computer-science classes, but I can also tailor the presentations to grades 5-8. Below is a list of current presentations:

enhance IT!
– Explores the technology of crime shows on TV from a computer science perspective – Does “zoom-in” really work on surveillance camera footage? Is it really possible to identify a person using facial recognition?
(grades 9-12)

The Art of Recursion
– Explores the grim and murky side of recursion. Why Fibonacci and the Towers of Hanoi are evil, visual recursive algorithms, and interesting recursive algorithm.
(grades 11-12)

Testing, testing, 1,2,3
 Explores the notion of software testing, why things fail, and why testing is an important step in producing effective software.
(grades 11-12)

Software Time Travelling
 Explores the role of legacy software in our modern society. How have programming languages like Cobol, Fortran and Ada helped shape the world of software. Are they still being used? Are they any good?
(grades 11-12)

The Use of Things
 The art of interacting with the machine – any machine. Explores the world of human interaction with things – the good, and the not-so-well designed.
(grades 9-12)

A Career in Computer Science 
– Explores the potential for a career in computer science. What is computer science? Does it mean I have to sit in a cubicle and write code all day?
(grades 8-10)

What is Computing?
– Explores the world of computing, and what it means from a day-to-day perspective. How computers have integrated themselves into our lives.
(grades 5-7)