Beruflich Dokumente
Kultur Dokumente
of the
Introductory Programming Course
Abhiram Ranade
IIT Bombay
Pedagogy
Where we are
“If you want to build a ship, don’t drum up people together to collect wood and
don’t assign them tasks and work, but rather teach them to long for the endless
immensity of the sea.”
– Antoine de Saint-Exupery
Teachers report that students respond better if they explain the motivation clearly.
Some educational principles (2)
How learning is assimilated:
I New learning must be reconciled with prior knowledge.
Prior knowledge:
I Mathematics: Arithmetic, algebra, geometry, calculus, statistics.
Details must be taught, but they must not overwhelm the principles/essensce.
On the first day, students are most fresh, most energetic, and possessing their most
positive attitude.
We must rise to the occasion and provide them excitement and challenge!
Put forward your best foot – exhibit the best features of your subject and get them
to actively participate.
The Challenge: students havent learned anything; how will they understand
interesting ideas? And participate??
Textbook
Even the best teachers will not always connect to all students.
I Student does not follow teacher’s accent.
I Student is absent.
Assign reading from the book so that students learn to become independent learners.
Later in life they will only have to books to learn from!
The teacher does not have to do all the work – let the book help you.
Summary
I Motivation is needed and it should come from the students’ world.
Motivation = “We want to write a program to do ...”
I Use programming examples from math and science, and even fun and art, to
have synergy with the prior knowledge, and career goals of our students.
I In the era of cellphones, graphical input and output are very important if the
students are to take us seriously.
I Graphics is important also for science and math visualization.
I Keep the focus on understanding computations and their structure, rather than
language syntax.
I The language will be learned with minimal effort if there are exciting motivating
programs to be written.
I Get to interesting programming examples on day 1.
I Use a good textbook.
Scaffolding
Scaffolding
Scaffolding: “Additional material that we teach in order to help teach the main
material”
I Scaffolding should have minimal cognitive load.
I Graphical input
Motivation:
I repeat + graphics allow us to write interesting programs from day 1.
forward(100);
right(90);
forward(100);
right(90);
forward(100);
main_program{
turtleSim();
repeat(4){
forward(100); right(90);
}
}
Most students understand without explanation; explain after letting them guess.
Another day 1 program
main_program{
turtleSim();
repeat(10){
repeat(4){
forward(100); right(90);
}
right(10);
}
wait(10);
}
1. Control flow
2. Elementary iteration, including nested iteration
3. Basic ideas of syntax, spaces, indentation
4. Importance of observing patterns in what is to be accomplished, and expressing
them using repeat
Do not write 100 statements to draw a 100 sided polygon!
Very important activity while designing programs!
Essence of programming?
Last activity for day 1: Show movie of what is possible using graphics.
Homework for day 1:
I Draw a two dimensional grid.
I Draw a circle (as limit of n sided polygon).
I Draw 5 cornered star.
Requires some high school geometry.
Note: most programming needs domain knowledge.
Students know the required geometry, but we might as well remind them of the
important ideas, as a part of the homework statement.
I “If the turtle starts at a certain orientation and at the end has the same
orientation, it must have turned through a multiple of 360 degrees.”
Will help in drawing stars.
I “If you change the angle gradually the path traced by the turtle will look lie an
arc.” Will help in drawing circles.
Students will be happy to do the homeworks they will be eager to see how the turtle
will move. They want to feel the power.
Topic 1 b: How computers solve problems
I We would like students to believe that computers are very useful.
I Some interesting computations should be explained at popular science level.
Candidate examples: Image processing, Text processing, Weather prediction.
“The number of children is the number of girls plus the number of boys. How many
children are there if there are seven girls and five boys?” [Sim11]
int chlidren, boys, girls;
children = boys + girls; // children "box" gets formula
boys = 5; girls = 7;
Students will remember concepts better if they are used for doing interesting things.
int i=10;
repeat(10){forward(i); right(90); i = i + 10;}
I Useful to show some full programs and ask students to modify those.
Discussion about design needed when we discuss the first non-trivial program.
I Our choice: Calculate e by summing series Chapter 4, [Ran14]
I Needs only repeat and assignment statements. Language complexity will not
overwhelm design considerations.
I Should be taught in a leisurely manner. Next
I Students appreciate the slow development.
Program Design (continued)
Our recipe for program design (Discussed last week)
I Understand problem: create input output examples.
I Understand how you would solve the problem manually.
I State what values you calculate in each iteration.
In ith iteration ith term ti of series is calculated...
I Make your program mirror the manual computation.
Statement of what happens in iteration i : Plan
Stating plans is very important for debugging.
I Identify what variables you will need.
A variable to hold each value that needs to be remembered.
Emphasize the distinction between what to compute and how to compute it.
What: Plan. States what values will be calculated.
How: Code that does the computation. Comes later.
Program design issues should continue to get discussed throughout the course.
I Students should be frequently reminded to design manual algorithms before
writing programs.
I Writing down precise plans for all important loops should be expected.
I Plans should be like invariants, and they should contain all the information
required to see that the program is correct.
Should not demand formal proof of correctness.
I When you find students debugging code in labs, see if they have written a plan.
Remind them that this will help in debugging.
I Likewise for every function it is important to clearly state what it is supposed
to do, before writing the function – also useful in debugging.
Topic 4: Coordinate based graphics:
Creation, Manipulation, Graphical input
Circle c1(200,225,25);
// c1 = circle. center at (200,225), r = 25
Rectangle r1(200,200,50,70);
// center coordinates, width, height
r1.right(45); // rotate 45 degrees
c1.move(10,20); // move by 10,20 in x,y directions
int z = getClick();
// z = 65536 * x coordinate of cursor + y coordinate
Educational goals acheived: Implicit introduction to constructor and member access
syntax. Practice with repetition, which will be needed to do interesting animations.
Excitement value: Elementary animation can be done.
Will provide examples/programming problems for weeks to come
Topic 4 example 1: Projectile motion
initCanvas("Projectile motion", 500,500); // start 2d graphics
nr − qs ps − qr
m= c=
np − q 2 np − q 2
xi2 , q =
P P P P
where p = i i xi , r = i xi yi , and s = i yi .
p += x*x;
q += x;
r += x*y;
s += y;
}
double m = (n*r - q*s)/(n*p - q*q);
double c = (p*s - q*r)/(n*p - q*q);
Line l(0,c, 500, 500*m+c);
The if statement
All lectures should begin by stating the motivation for what will be taught
“Here is a problem you cannot program with what you already know.”
Then teach whatever language feature that is needed for the program.
Explains why local variables in calling and called functions can have the same name
Chapter 9 [Ran14]
I Structural recursion
Chapter 10 [Ran14]
Structural recursion
Structural recursion is more known to student, e.g. family trees.
“Write a program that reads a number j and finds the oldest ancestor of i.”
“Write a program that reads a number j and finds the number of descendants of i.”
I Many such relationship questions can be asked.
I Students will be able to solve them, while getting practice with index
manipulation and recursive thinking.
Index calculation:
I A[i] calculated in constant time.
Brief discussion:
I Multidimensional arrays, representing matrices.
I If you do not introduce string class your students will continue to use null
terminated strings.
Experience: Even the weakest student understands turtle movements and repeat.
Concluding remarks