You are on page 1of 5

Introducing Thonny, a Python IDE for Learning

Programming

Aivar Annamaa
Institute of Computer Science
University of Tartu
aivar.annamaa@ut.ee

ABSTRACT user actions in detail sufficient for replaying the program-


Thonny is a new Python IDE for learning and teaching pro- ming process.
gramming that can make program visualization a natural According to the engagement level taxonomy developed in
part of the beginners’ workflow. Among its prominent fea- [13], Thonny supports controlled viewing of students’ own
tures are different ways of stepping through the code, step- content, because users can choose the granularity of each
by-step expression evaluation, intuitive visualization of the step during the program animation and they can animate
call stack and mode for explaining the concepts of references any Python 3 program.
and heap. It supports educational research by logging user Thonny has been successfully tested for one semester in
actions for replaying or analyzing the programming process. the context of a CS1 course at our university. It is free to
It is free to use and open for extension. use, open source, and developed with the goal of supporting
extensions written by third parties.
CCS Concepts
•Social and professional topics → CS1; •Software and 2. BACKGROUND
its engineering → Integrated and visual development For last 6 years we have been teaching Python based first
environments; programming course (CS1) in our university. During this
time we have met many hardworking students constantly
struggling with programming exercises or even failing the
Keywords course. There have been even more students who fail be-
Computing education, Programming, IDE, Python, Pro- cause they give up trying. Most of them seem to approach
gram animation, Program visualization programming tasks without clear understanding how each
part of their programs affects Python’s behavior at run-
1. INTRODUCTION time. After having success with hand-drawn visualizations
In order to successfully learn imperative programming, (eg. how call stack manages recursive calls), we started look-
students must learn to regard the program interpreter as ing for an automated program animation tool.
a machine and relate language constructs with the corre- In [13] Sorva et al. list four challenges which could be
sponding rules of this machine. Although these rules can be tackled by a program animation system. First, some novices
described verbally, for many students this is not sufficient, so tend to regard program constructs only as pieces of code
different tools have been developed for visualizing program without thinking about their runtime behavior. Seeing the
behavior at runtime. According to the terminology given in code become “alive” during program animation could help
[13], we call these program animation systems. them create the connections between static and dynamic
Thonny is a new beginner-friendly Python IDE we de- aspects of a program.
veloped in University of Tartu. Besides standard program Second problem is that beginners often attribute human-
construction and execution capabilities, it has comprehen- like reasoning power to program interpreter, failing to see
sive support for program animation. It has features to il- it as a machine with bounded capabilities and clear rules.
lustrate the concepts of variables, control flow, expression Program animation systems present the program runtime
evaluation, function calls, recursion, references and heap, via a notional machine [2], and demonstrate that it is only
objects (including classes and functions as values), compos- able to make clearly defined steps according to relatively
ite data (lists, dictionaries and sets) and file IO. It can log simple rules.
Even when the student acknowledges the interpreter as
Permission to make digital or hard copies of all or part of this work for personal or just a machine, misconceptions about the precise meaning of
classroom use is granted without fee provided that copies are not made or distributed
for profit or commercial advantage and that copies bear this notice and the full citation program constructs are easy to develop when the mechanics
on the first page. Copyrights for components of this work owned by others than the of the runtime system is hidden from the user.
author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or Finally, students with correct understanding of the pro-
republish, to post on servers or to redistribute to lists, requires prior specific permission
and/or a fee. Request permissions from permissions@acm.org. gram semantics may still struggle with program tracing, be-
Koli Calling 2015, November 19 - 22, 2015, Koli, Finland cause of cognitive effort required for keeping track of pro-
c 2015 Copyright held by the owner/author(s). Publication rights licensed to ACM.
gram state. Program animation systems can help reducing
ISBN 978-1-4503-4020-5/15/11. . . $15.00 the load here by externalizing program state representations.
DOI: http://dx.doi.org/10.1145/2828959.2828969 We have met all these problems in our practice and we

117
Figure 1: Thonny in stepping mode

believe Thonny can help with all of these. We describe our


approach in Section 4.
In their survey Sorva et al. conclude that program anima-
tion systems tend to have positive impact on learning pro-
gramming, but are often short-lived research prototypes, not
suitable for widespread use [13]. They suggest that success-
ful program animation tool should integrate content creation
and animation features, be able to adapt to their users’ grow- Figure 2: Different output formatting in the shell
ing knowledge and have sustainable development model.
With Thonny, our goal has been to offer single environ-
ment which integrates all the tools necessary for first pro-
gramming course. Each of these has been designed with be-
ginners in mind, unlike similar features in professional IDE- In basic usage, our aim is to cover all the functionality
s, which aim for greatest user performance and require much offered by Python’s standard graphical environment, IDLE.
steeper learning curve. Thonny allows gradual introduction Thonny’s editor supports standard IDE features like syntax
of different features in order to keep the user interface as coloring, code completion, parentheses matching, automatic
simple as possible in the beginning. indentation, block indentation / de-indentation, block com-
While we believe the features built into Thonny will suffice menting and uncommenting. It is possible to switch between
for most introductory programming courses, we acknowl- several files opened under different tabs. For easier file man-
edge that different instructors and researchers have different agement, it is possible to open a file browser view as present
interests and preferences, therefore we made Thonny open in many professional IDE-s.
source and we embrace enhancements and extensions. The shell includes some minor enhancements compared
to IDLE’s shell. First, it is always shown below the edi-
tor. We believe this makes the user experience smoother
3. BASIC USAGE and encourages using the shell for small experiments more
Thonny is free software – both free to use and open source. often. Second, as seen in Figure 2, the text corresponding
Installers and installation instructions are provided for Win- to program input/output is formatted differently compared
dows, Mac OS and Linux [1]. to the results of direct expression evaluation. This reminds
On first run the window with an empty editor and a users that automatic printing of the value of an expression
Python shell is shown, other features can be enabled from is a special feature of the shell and in scripts one needs to
the View menu as required. request printing explicitly.

118
Surprisingly, stepping through the evaluation of an expres-
sion is not common in professional IDE-s. It is supported
by some program animation systems [10, 11, 14], but unlike
Thonny, these systems reserve a separate pane for evaluat-
ing the expressions. According to Mayer, putting related
Figure 3: Thonny in the middle of evaluating an items closer to each other reduces the cognitive load for in-
expression terpreting them [8]. We believe the same principle applies
here and expression evaluation closer to the original source
creates smoother user experience.
4. PROGRAM ANIMATION
Program animation – visualization of programs’ run- 4.4 Function calls
time concepts – has been the main motivation for creating After evaluating the last argument in a function call, the
Thonny. In this section we describe the features supporting whole call expression gets focused again. If the user now
it. chooses to step into, Thonny opens a small window for exe-
cuting the function body 1.
4.1 Variables Here stepping works just like on program’s top level. If
After the students have become comfortable with another function call is stepped into, a new window is cre-
Thonny’s basic features, we ask them to open the variables ated and execution is continued there. After executing the
view containing a two-column table with names and values return statement or last statement of the function, the win-
of global variables. The entries are added and updated auto- dow is destroyed and original call expression gets replaced
matically. This approach is similar to several other systems by the return value.
[12, 11]. Some program animation systems display variables Professional IDE-s usually have a separate view listing
as labeled boxes [14, 9, 10]. For Thonny we chose the table, the frames of call stack and reuse code editor for animating
because this makes it easy to explain how Python looks up the steps inside the function. This might be optimal for
the value of a variable. users who already know how function calls work, but for
beginners this scheme can be confusing. We have seen many
4.2 Statement stepping students who fail to understand recursion because they try
Executing the program in stepping mode begins by auto- visualize recursive calls as jumps in the source code without
matically highlighting the first statement. understanding that each call creates a new context. We
Highlighted statement can be executed with single key believe Thonny’s way of presenting each stack frame in a
press which invokes the command “Step over”. This executes separate window, with its own code view and local variables
the whole statement even if it is a compound (eg. while table, is more suitable for beginners. Similar approach is
loop). After updating variables table and shell, the next used in VisMod [5] and Ville [12].
statement is highlighted automatically.
If the same key is pressed with modifier key (Control in 4.5 Object inspector
Windows), Thonny executes the command “Step into” and Selecting “Object inspector” in View menu opens a view
tries to highlight the first child of current statement (eg. showing details (type, attributes, etc.) about the value cur-
loop condition). If current construct doesn’t have children, rently selected in a variables table. For string objects the
it is executed and next construct is selected. inspector presents a text box showing the content of the
If the user double-clicks on a code line, the program ani- string – this reduces confusion about character escaping re-
mation will be fast forwarded to this line. This is our sub- quired by Python syntax. For collections (lists, sets and dic-
stitute for breakpoints. tionaries) it shows the table with collection’s elements. For
In most systems statement stepping is implemented with function objects it shows the source code of the function.
the granularity of code line, but we believe operating on For text file handles the content of the file and the current
statements makes more sense when learning the connec- position in the file are shown – this helps understanding the
tions between program static structure and runtime behav- side effects of file manipulation methods.
ior. The choice between “Step into” and “Step over” is present
in most IDE-s but only in the context of function calls. We 4.6 Values in heap
believe allowing stepping into or over any compound con- As long as students are using only immutable data types,
struct is good for illustrating the nested structure of a pro- like integers or strings, Python instructors are free to ignore
gram. For the sake of simplicity, though, we use only “Step the complex issue of references and shared data. With lists
into” during our first stepping demonstrations, and other mutable types this issue needs to be addressed.
For explaining the concept of references and heap, Thonny
4.3 Expression evaluation offers another mode of visualizing memory. When “Show val-
When “Step into” is issued on an expression, Thonny ues in heap” is enabled in View menu, the values in variable
opens a small box hovering above the original expression, tables get replaced by the ID-s of corresponding objects and
showing the copy of the expression. Figure 3 shows Thonny another table titled “Heap” appears, which maps ID-s to val-
in the middle of evaluating the expression 2*a + a**2. In ues, as seen in Figure 4. This makes it easy to demonstrate
this box “Step into” works like in statement level by select- that y = x only copies the ID given in x to y. Value rep-
ing the first child of current expression. “Step over” replaces resentations are replaced with ID-s also in shell, expression
current expression with its value. evaluation box and attributes in object inspector.
After the whole expression gets evaluated, the box is hid- There are many program animation systems [4, 10, 11, 9,
den and the focus goes back to the statement level. 3] which display references as arrows between objects. We

119
Python’s built-in tracing facilities. In order to provide
tracer precise information about current position in code
and to allow more fine-grained steps, marker nodes are
added to program syntax tree before compiling and exe-
cuting it. For each statement we add 2 dummy statement
nodes, one to be executed just before and the other just af-
ter the original statement. The code in these marker state-
ments provides the tracer information about the location
of the original statement, whether the statement has chil-
dren, etc. Similarly, each expression is complemented with
two marker expressions, one to notify tracer that certain
expression is just to be evaluated and other to fetch the
value of the expression. Basically, each (sub)expression e
becomes after(before(info), e), where before and after are
marker functions and info is information about the location
and other features of the expression e.
Inspired by Java-based BlueJ’s [6] extension system we
included a simple plug-in system in Thonny, which allows
writing third party extensions without modifying the main
code. For validating this system, several features in Thonny
are implemented as plug-ins.

7. USAGE EXPERIENCE
Thonny has been used for one semester in the CS1 course
in University of Tartu. The course had 280 participants,
half of them were first year CS students, other half con-
Figure 4: Variables, heap and object inspector in sisted mostly of students from related fields (mathematics,
heap mode statistics, IT).
In selected lectures we used Thonny’s stepping mode for
demonstrating the principles of variables, control flow, ex-
acknowledge this might be more intuitive way for introduc-
pression evaluation, function calls, recursion and shared mu-
ing the notions of dependency and sharing, but it doesn’t
table data. Quick polls at the end of those lectures revealed
scale well to many objects and complex data structures.
that majority of the students (usually more than 70%))
However, we will consider adding an additional view for vi-
thought Thonny helped them understand these principles.
sualizing the connections between objects graphically.
We encouraged students to use Thonny by themselves,
but also warned that at the moment it is not as stable as
5. USER ACTION LOGGING IDLE, our official environment. At least 70 students in-
For each usage session Thonny creates a log file containing stalled Thonny on their computers and tried to use it. In
descriptions of the actions performed by the user. These the labs Thonny was equally popular among weaker and
actions include loading and saving files, modifications to the stronger students. We didn’t offer any support materials
program text (paste can be distinguished from typed text), for using program animation features – demonstrations in
program executions, writes into and reads from program’s the lectures were sufficient to get interested students able to
standard streams, stepping commands, losing and gaining trace their programs with Thonny.
the focus of Thonny window, etc. Each action gets recorded Before one of the midterms we offered students extra credit
together with its time stamp. if they solve the programming exercises in Thonny, answer
The collected information can be used to replay the whole couple of questions and send us the log files describing their
process of program construction and the activities in the actions during the midterm. We got logs and responses from
shell. For this Thonny provides a separate window where 44 students. Most of the students said Thonny helped them
one can choose a log file and see the events replayed in se- in debugging their programs and gave them advantage over
lected speed. IDLE users during the midterm (the rest were mostly an-
noyed by a bug in code editor that was fixed later). Many
students mentioned that they liked that Thonny keeps editor
6. IMPLEMENTATION and shell in the same window.
Thonny is written in Python 3. The source code is avail- We haven’t used Thonny action logs for any serious anal-
able under GPLv3 license at [1]. ysis yet, but for proof of the concept we created a small
At runtime Thonny uses two processes – the GUI front- summary on the logs collected during the midterm. From
end based on Tkinter framework, and the back-end for run- this data we learned, for example, that one third of the pro-
ning user code. At the moment both processes need Python gram executions generated error messages of which one third
3.2 or later, but it’s not difficult to add support for older were syntax errors and that only 14 students out of 44 had
Python versions in the back-end. used Python shell for executing statements or evaluating ex-
Unlike some systems which support limited subset of tar- pressions. We also replayed some of the logs in Thonny and
get language features, eg. [14], Thonny supports all Python discovered some curious working patterns we hadn’t noticed
3 programs. To achieve this, its stepping mode relies on during the labs.

120
8. FUTURE WORK 2(1):57–73, 1986.
Among the specific features we plan to implement soon are [3] J. H. Cross II, T. D. Hendrix, J. Jain, and L. A.
visualization of raising, propagating and catching exceptions Barowski. Dynamic object viewers for data structures.
and features for explaining principles of Python’s module ACM SIGCSE Bulletin, 39(1):4–8, 2007.
system. After completing these, Thonny can be used for [4] P. J. Guo. Online python tutor: Embeddable
visualizing all Python’s core concepts. web-based program visualization for cs education. In
A prototype already exists which allows Python programs Proceeding of the 44th ACM technical symposium on
to be constructed by dragging and dropping code blocks in Computer science education, pages 579–584. ACM,
the style of Scratch [7], hopefully this can be integrated with 2013.
Thonny soon. [5] R. Jiménez-Peris, M. Patino-Martinez, and
Other possible directions we see for Thonny are integra- J. Pacios-Martı́nez. Vismod: a beginner-friendly
tion with an automatic feedback service, filters for uncaught programming environment. In Symposium on Applied
exceptions trying to reformulate the problem in beginner- Computing: Proceedings of the 1999 ACM symposium
friendly way, different static analyses which help locate the on Applied computing, volume 28, pages 115–120,
mistakes in the code and automatically generated quizzes 1999.
for testing users’ understanding of their programs. [6] M. Kölling, B. Quig, A. Patterson, and J. Rosenberg.
We also hope other instructors and researchers find The bluej system and its pedagogy. Computer Science
Thonny’s plug-ins system suitable for extending Thonny’s Education, 13(4):249–268, 2003.
capabilities in directions important for them. [7] J. Maloney, M. Resnick, N. Rusk, B. Silverman, and
In parallel with enhancing Thonny, we plan to conduct E. Eastmond. The scratch programming language and
experiments and surveys to evaluate its effect to learning. environment. ACM Transactions on Computing
Education (TOCE), 10(4):16, 2010.
9. CONCLUSION [8] R. E. Mayer. Multimedia Learning. Cambridge
In this paper we described Thonny, a new Python IDE University Press, 4 2001.
for learning programming. Besides standard program con- [9] J. Moons and C. De Backer. The design and pilot
struction tools it includes several program animation tools evaluation of an interactive learning environment for
capable of visualizing core concepts of imperative program- introductory programming influenced by cognitive
ming (including variables, control flow, expression evalua- load theory and constructivism. Comput. Educ.,
tion, function calls, references and heap). Some of these 60(1):368–384, Jan. 2013.
features are novel (support for commands “Step into” and [10] A. Moreno, N. Myller, E. Sutinen, and M. Ben-Ari.
“Step over” on all levels of the program tree) or little used Visualizing programs with jeliot 3. In Proceedings of
in earlier systems (representing stack frames as cascading the working conference on Advanced visual interfaces,
windows). Unlike some systems with similar capabilities, it pages 373–376. ACM, 2004.
supports all Python 3 programs. It can be used as a tool for [11] T. S. Norvell and M. P. Bruce-Lockhart. Taking the
collecting data about the process of programming. hood off the computer: Program animation with the
During a semester of using Thonny in the context of first teaching machine. In Canadian Electrical and
programming course in our university we received encour- Computer Engineering Conference, Halifax, Nova
aging feedback from the students – they thought program Scotia, 2000.
animations presented with Thonny helped them learn new [12] T. Rajala, M.-J. Laakso, E. Kaila, and T. Salakoski.
programming constructs. Majority of the students using Ville: A language-independent program visualization
Thonny during a midterm said it helped them with debug- tool. In Proceedings of the Seventh Baltic Sea
ging. Thonny’s user interface is suitable for beginners – Conference on Computing Education Research -
most of the students who decided to install Thonny on their Volume 88, Koli Calling ’07, pages 151–159,
own computers were able to use its features without further Darlinghurst, Australia, Australia, 2007. Australian
assistance. Computer Society, Inc.
By rethinking standard approaches to program animation [13] J. Sorva, V. Karavirta, and L. Malmi. A review of
we have managed to make basic program animation accessi- generic program visualization systems for introductory
ble to total beginners. At the same time, Thonny can grow programming education. Trans. Comput. Educ.,
with its users – there are several layers of advanced fea- 13(4):15:1–15:64, Nov. 2013.
tures to be enabled on demand. By integrating animation [14] J. Sorva and T. Sirkiä. Uuhistle: A software tool for
tools with program construction tools, we created an envi- visual program simulation. In Proceedings of the 10th
ronment covering the needs of most instructors and students Koli Calling International Conference on Computing
in Python-based introductory programming courses. Education Research, Koli Calling ’10, pages 49–54,
Thonny is open source and free to use. It has potential for New York, NY, USA, 2010. ACM.
becoming a useful platform for Python-based tools related
to learning and teaching programming.

10. REFERENCES
[1] Thonny source code repository and installers.
https://bitbucket.org/plas/thonny/.
[2] B. D. Boulay. Some difficulties of learning to program.
Journal of Educational Computing Research,

121

You might also like