0% found this document useful (0 votes)
3 views

Teaching_programming_through_problem_solving

This paper discusses the significance of teaching programming through problem solving in high school, advocating for the use of a simplified programming language, C AL, which is a C-like algorithmic language designed for beginners. The authors argue that traditional languages like C and Java are not suitable for introductory courses due to their complexity and low-level focus, while C AL aims to provide a clearer understanding of programming concepts. The paper outlines the design rationale, features, and syntax of C AL, emphasizing its educational benefits.

Uploaded by

Emin Kültürel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Teaching_programming_through_problem_solving

This paper discusses the significance of teaching programming through problem solving in high school, advocating for the use of a simplified programming language, C AL, which is a C-like algorithmic language designed for beginners. The authors argue that traditional languages like C and Java are not suitable for introductory courses due to their complexity and low-level focus, while C AL aims to provide a clearer understanding of programming concepts. The paper outlines the design rationale, features, and syntax of C AL, emphasizing its educational benefits.

Uploaded by

Emin Kültürel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Proceedings of the 2013 Federated Conference on

Computer Science and Information Systems pp. 1533–1536

Teaching Programming through Problem Solving:


The Role of the Programming Language
Nikolaos S. Papaspyrou Stathis Zachos
Email: [email protected] Email: [email protected]

School of Electrical and Computer Engineering


National Technical University of Athens
Polytechnioupoli, 15780 Zografou, Athens, Greece

Abstract—In this short paper, we advocate the importance of proper exposure to programming in high school (and this is
problem solving for teaching “Introduction to Programming”, the majority of our students). Thus, this goal translates to:
instead of merely teaching the syntax and semantics of a
• a quick educational introduction to self-evident program-
programming language. We focus on the role of the programming
language used for an introductory course. For this purpose we ming concepts and tools, without cryptic, hardware-
propose C AL, a C-like algorithmic language, which is essentially dependent and special purpose structures; but also
a well-defined and behaved subset of C with a small number of • fluency in a programming language which can be easily
modest, “educational” extensions. We present the design rationale extended and/or modified to a language that is currently
for C AL, its main features, syntax and illustrative examples.
useful in practice, without a total rethinking of the basic
I. I NTRODUCTION algorithmic techniques.
N THIS short paper, we present our experiences with teach- Our historic prototype for a self-evident educational program-
I ing programming through problem solving in the School of
Electrical and Computer Engineering of the National Technical
ming language is of course Pascal [10], whereas programming
languages that are currently useful in practice are of course C
University of Athens. We focus on the role of the programming [7], [5], C++ [9] and Java [2].
language for this purpose and describe the approach that we II. T HE ROLE OF THE L ANGUAGE
have taken. Let us begin with two observations: Since the 1950s, scores of different programming languages
1) In some students’ minds, algorithmic programming is have been designed and implemented and many more are yet
strangely enough an intellectual process that is not to come. Those with a relative experience in the field will agree
connected to everyday problem solving. that there is no such thing as “the best programming language”
2) Students often have no sense of what is good and what and this is what we need to explain to our students early
is bad in programming, even after taking a number of on. Some languages are better than others for some specific
courses on the design of algorithms and complexity. purpose and indeed: (a) some specific languages are almost
We believe that these are both due to the way we teach exclusively used for some specific purposes, and (b) for some
students how to program. Starting from secondary school, specific purposes people use almost exclusively some specific
students often begin by learning a Pascal-like programming languages.
language. They learn to use variables, assignments, control- For example, C [7], [5] is a very good language for systems
flow statements, arrays. They do not learn, however, because programming. It is a low-level language, offering programmers
we do not teach them early enough, what these should be the opportunity to directly interact with the hardware, but not
used for! Young children realize early that they need to solve the best language for numerical and scientific computing today.
problems; they are hungry and they want their parents to feed We believe that C is an inappropriate language for teaching
them, they want to play with that shiny car in the toy shop’s “Introduction to Programming”. Some of its characteristics are
window, etc. Later on, they learn to speak and use the language so low-level that tend to focus on the hardware, instead of
to communicate their needs. Children learn to speak after they on the algorithms. When you start learning how to program,
know what they want to say! Why do we teach programming you don’t need twelve different types for integer numbers
languages to students before they know what to use them for? (including characters and Boolean values) and three more for
The main goal of our proposal is a quick introduction to real (floating-point) numbers. You don’t need a for statement
programming for absolute beginners. Such an introduction so powerful that you can use it to implement a binary search
would be useful for teenagers in high-school, who may not algorithm in just one line. You don’t need to struggle to un-
continue to be programming specialists but who want to derstand the meaning of x = x++; (most people, including
support their literacy in mathematics by hands-on attractive some who teach C, think that it does something although
algorithmically solvable problems. It would also be useful to opinions vary when it comes to what exactly this is; the truth is
first-year university students who have (somehow) escaped a that this statement is illegal, or causes “undefined behaviour”

978-1-4673-4471-5/$25.00 c 2013, IEEE 1533


1534 PROCEEDINGS OF THE FEDCSIS. KRAKÓW, 2013

as the ANSI C standard puts it, because the value of variable III. T HE D ESIGN OF C AL
x changes twice between two successive sequence points). Disregarding some drawbacks, C is an adequate choice
Pascal [10], [6] is arguably one of the best programming for teaching “Introduction to Programming”, with emphasis
languages for teaching purposes. It is a concise, general on problem solving and algorithmic thinking. Its core is a
purpose language which supports a systematic, structured quite simple algorithmic language, easy to explain and use.
and algorithmic approach to problem solving. Programs in Moreover, it is a useful language to know, heavily used
Pascal are usually easy to read and understand with a clear in practice, either directly or indirectly, through a line of
structure that favours stepwise refinement. The language helps descendants that share a large part of its syntax and semantics
programmers to avoid programming mistakes and to be able (C++, Java, C#, etc.). A list of drawbacks:
to verify the correctness of their programs. On the other hand, • Its syntax and semantics is often cryptic and obfuscated;
Pascal is very little used today by software practitioners. e.g., allowing side-effects anywhere inside expressions.
Java and other object-oriented languages are also poor • The use of “declarators” (as in int*(f[3])(int);)
candidates for teaching “Introduction to Programming”. If the is counter-intuitive and hard to explain.
focus is on problem solving and algorithmic thinking, such • Non trivial library functions (e.g., printf and scanf)
languages add an unbearable level of noise. Using Java, the are required for beginners to write programs that input
only logical approach is to teach programming in a purely and output data. The corresponding header files must be
object-oriented fashion and this necessarily takes the focus #included. Pointers are required for scanf.
away from problem solving, although OOP might be a good • Before the simplest program is written, students must
choice for a second (e.g., data structures) course. see int main() and return 0; unless of course we
There is a trend towards Python, in the last few years. want to teach them to be sloppy from the first lecture...
Python is a relatively good candidate; its syntax is concise • The type system allows programmers to deliberately
and enforces proper indentation, it supports imperative and misuse data and to neglect declaring function prototypes.
object-oriented programming equally well, and it is widely Both are bad from an educational point of view.
used in the software industry. The drawbacks for Python are: We therefore base C AL on an appropriate “educational
(a) it is dynamically typed and requires very few declarations; subset” of C, which we extend with a number of macros,
this is bad if you want the students to detect programming library functions and one extra feature (call by reference)
errors early and to learn to program in a disciplined way; to suit the needs of our introductory course. The result is
(b) it is so high-level that students do not develop an intuition a language reminiscent of Pascal but with C notation. All
about how data are represented and how operations are im- extensions are written with uppercase letters (e.g., WRITE),
plemented; this is bad if you want the students to understand so that students immediately know if something that they have
the connection between the programming language and the learnt exists in C or is one of our educational extensions. The
underlying hardware; and (c) its data structures are so high- main characteristics of C AL, whose complete syntax is defined
level that algorithmic complexity issues are obscured by the in figure 1, are the following:
way data structures are implemented; e.g., in Python there are
• A program is organized as a set of modules, each consist-
no arrays, but there are lists and dictionaries; however, in a
ing of constant and type definitions, variable definitions,
data structure course, all three would need to be covered and
routine declarations, routine definitions and (optionally)
with three different implementations, requiring O(1), O(n)
the body of the main program, which must only be
and O(n log n) time for accessing an element, respectively.
present in one module. The visibility of module defini-
The second drawback (b) is also true for functional lan- tions is controlled with PRIVATE and extern.
guages, like Scheme, ML or Haskell, which are also very good • There are functions and procedures, defined with FUNC
from an educational point of view and are indeed used for and PROC respectively; the misleading type void is not
teaching “Introduction to Programming” in several Computer used. The main program begins with the special keyword
Science departments [8], [3], [1], [4]. PROGRAM.
All this said, we decided to design a new educational • The type system is simplified. There are types for
programming language for an introductory course in which Boolean values (bool, as in C99, with constants true
emphasis is on problem solving. However, this educational and false), integers (int), characters (char) and real
language will naturally evolve before the students’ eyes to numbers (REAL). There are also enumerations, structures
a full-scale programming language, useful later on. In the and unions, but these must be defined and given a name
next sections we describe C AL, a C-like algorithmic language, before they can be used. Arrays and pointers complete
starting from the design choices that we had to make, proceed- the picture of types. However, the syntax for declarators
ing with the syntax, the main characteristics of the language is very simplified in comparison with C; type synonyms
and concluding with a few examples.1 (typedef) can be used for defining, e.g., double point-
ers, arrays or pointers, pointers to arrays, etc.
1 An implementation of C AL , based on GCC and using macros, is available • Operators NOT, AND, OR and MOD are synonyms of C’s
from https://github.com/softlab-ntua/pazcal. (not so intuitive) standard operators !, &&, || and %.
NIKOLAOS S. PAPASPYROU, STATHIS ZACHOS: TEACHING PROGRAMMING THROUGH PROBLEM SOLVING 1535

hmodulei ::= ( hconst defi | htype defi )∗ ( hdeclarationi )∗ ( hdefinitioni )∗ [ hprogrami ]


hdeclarationi ::= [ “PRIVATE” | “extern” ] ( hvar defi | hroutine decli )
hdefinitioni ::= [ “PRIVATE” | “extern” ] hroutine defi
hconst defi ::= “const” htypei hdeclaratori “=” hinitializeri ( “,” hdeclaratori “=” hinitializeri )∗ “;”
htype defi ::= “typedef” htypei hdeclaratori ( “,” hdeclaratori )∗ “;” | henum defi | hstruct defi | hunion defi
henum defi ::= “enum” hidi “{” hidi ( “,” hidi )∗ “}” “;”
hstruct defi ::= “struct” hidi “{” ( htypei hdeclaratori ( “,” hdeclaratori )∗ “;” )∗ “}” “;”
hunion defi ::= “union” hidi “{” ( htypei hdeclaratori ( “,” hdeclaratori )∗ “;” )∗ “}” “;”
hvar defi ::= htypei hdeclaratori [ “=” hinitializeri ] ( “,” hdeclaratori [ “=” hinitializeri ] )∗ “;”
hroutine decli ::= hroutine headeri “;”
hroutine defi ::= hroutine headeri hblocki
hroutine headeri ::= ( “PROC” | “FUNC” htypei ) hidi “(” [ htypei hformali ( “,” htypei hformali )∗ ] “)”
hformali ::= hidi [ “[” “]” ] ( “[” hexpri “]” )∗ | “*” hidi | “&” hidi
htypei ::= “int” | “bool” | “char” | “REAL” | “enum” hidi | “struct” hidi | “union” hidi | hidi
hdeclaratori ::= hidi ( “[” hexpri “]” )∗ | “*” hidi
hinitializeri ::= hexpri | “{” hinitializeri ( “,” hinitializeri )∗ “}”
hprogrami ::= “PROGRAM” hidi “(” “)” hblocki
hblocki ::= “{” ( hlocal defi | hstmti )∗ “}”
hlocal defi ::= hconst defi | hvar defi
hstmti ::= “;” | hl valuei hassigni hexpri “;” | hl valuei ( “++” | “--” ) “;” | hwritei “(” [ hformati ( “,” hformati )∗ ] “)” “;”
| “FOR” “(” hidi “,” hrangei “)” hstmti | “while” “(” hexpri “)” hstmti | “do” hstmti “while” “(” hexpri “)” “;”
| “if” “(” hexpri “)” hstmti [ “else” hstmti ] | “break” “;” | “continue” “;” | “return” [ hexpri ] “;”
| hblocki | hcalli “;” | “switch” “(” hexpri “)” “{” ( ( “case” hexpri “:” )+ hclausei )∗ [ “default” “:” hclausei ] “}”
hassigni ::= “=” | “+=” | “-=” | “*=” | “/=” | “%=”
hrangei ::= hexpri ( “TO” | “DOWNTO” ) hexpri [ “STEP” hexpri ]
hclausei ::= ( hstmti )∗ ( “break” “;” | “NEXT” “;” )
hwritei ::= “WRITE” | “WRITELN” | “WRITESP” | “WRITESPLN”
hformati ::= hexpri | “FORM” “(” hexpri “,” hexpri [ “,” hexpri ] “)”
hexpri ::= hint-consti | hfloat-consti | hchar-consti | hstring-literali | “true” | “false” | “(” hexpri “)” | hl valuei | hcalli
| hunopi hexpri | hexpri hbinopi hexpri | “(” htypei “)” hexpri | “NULL” | “NEW” “(” htypei [ “,” hexpri ] “)”
hl valuei ::= hidi | hexpri “[” hexpri “]” | “*” hexpri | hexpri “.” hidi | hexpri “->” hidi
hunopi ::= “+” | “-” | “NOT” | “!”
hbinopi ::= “+” | “-” | “*” | “/” | “%” | “MOD” | “==” | “!=” | “<” | “>” | “<=” | “>=” | “&&” | “AND” | “||” | “OR”
hcalli ::= hidi “(” [ hexpri ( “,” hexpri )∗ ] “)”

Fig. 1. A context-free grammar defining the syntax of C AL in EBNF. Operator precedence and associativity are the same as in C.

• Assignment (simple or composite) is a statement. (Alas, • The switch statement is sanitized; case labels cannot
for compatibility purposes we have to give up the as- appear everywhere. Furthermore, clauses are required to
signment operator := and accept the commonly used =, end either with a break, or with the new keyword NEXT
which we would prefer not to confuse with the equality in order to explicitly proceed to the next clause.
operator known from mathematics.) There is just one • Four kinds of WRITE statements are used for the output
type of increment and decrement operators (postfix, e.g., of data, allowing any number of arguments of any type,
x++), used again as statements. Therefore, expression with a number of formatting options that are useful for
evaluation cannot contain direct side-effects. Also, we an introductory course. Library functions READ_INT,
omit bitwise operators and conditional expressions (?:). READ_REAL and getchar are used to input data.
• We omit the for statement, which is too general for our • The use of pointers has also been sanitized. The connec-
purposes, and replace it with a FOR statement following tion between pointers and arrays is still present, but it
the style of Pascal, mentioning the control variable and only allows the use of a pointer as an array; no pointer
a (precomputed) range of values that the control variable arithmetic is allowed and there is no “address of” operator
will take. Using FOR, the maximum number of iterations (&). Pointers are used for dynamic memory allocation;
is always finite and known before the loop starts execut- NEW and DELETE help students for this purpose (in the
ing; break and continue can be used to exit the loop spirit of C++, instead of malloc and free in C).
and proceed with the next iteration. • Call by reference is allowed, using the same notation that
1536 PROCEEDINGS OF THE FEDCSIS. KRAKÓW, 2013

C++ uses for references. l = q;


}
IV. I NTRODUCTION TO P ROGRAMMING USING C AL
Our course is based on the simplicity philosophy of the When grading, we reward the design of efficient algorithms
great teachers of the 1960s: Dijkstra, Hoare, and Wirth. We for solving problems such as the following:
only give some highlights for lack of space.
M AX S UM: Read a sequence of n integer numbers (positive,
• As early as in the second week, students are able to write
zero, or negative) and output the largest value of the sum of
simple programs that input, process and output data.
(arbitrarily many) consecutive numbers in the sequence.
PROGRAM area_of_circle ()
{ WRITE("Give the radius: "); We expect students who correctly solve this problem to
REAL r = READ_REAL(); come up with one of three general types of solutions, or
REAL a = 3.1415926 * r * r;
WRITELN("The area is: ", a); variations thereof. The first, is the obvious O(n3 ) algorithm:
} for all possible starts (i) and ends (j) of subsequences,
calculate the sum and find the largest. The second is the
• Control flow and combinatorial calculations. slightly less obvious O(n2 ) algorithm that, for every given
PROGRAM primes () start (i) avoids recomputing the sum of a subsequence from
{ int p; scratch but reuses the sums of smaller subsequences. Finally,
WRITELN(2); the third is a linear algorithm — O(n) time and requiring
FOR (p, 3 TO 1000 STEP 2)
{ int t = 3; O(1) memory — which works in a greedy fashion.
while (p MOD t != 0) t += 2;
if (p == t) WRITELN(p); PROGRAM maxsum_On ()
} { int n = READ_INT();
} int i, sofar = 0, best = 0;
FOR (i, 0 TO n-1)
{ int x = READ_INT();
• Structured programming: modules, functions and proce- sofar += x;
dures, parameter passing, stepwise refinement. if (sofar < 0) sofar = 0;
• Recursion. Euclid’s algorithm for the greatest common else if (sofar > best) best = sofar;
}
divisor is one of the examples that we use: WRITELN(best);
}
FUNC int gcd (int i, int j)
{ if (i==0 OR j==0) return i+j;
else if (i > j) return gcd(i MOD j, j); V. C ONCLUDING R EMARKS
else return gcd(i, j MOD i);
} We have presented C AL, a C-like algorithmic language
that we advocate for teaching “Introduction to Programming”
• Call by reference: e.g., in swap, useful for sorting. focusing on problem solving. We discussed the design of C AL,
PROC swap (int &x, int &y) which is essentially a controlled subset of C with some appro-
{ int t = x; x = y; y = t; } priate extensions. We would like to see C AL, or appropriate
subsets of it, as a vehicle to teach computer programming to
• Arrays: merge sort and quick sort, which are also exam- high-school students, making a bridge between mathematics
ples of recursion. and computer science in secondary education.
PROC merge (int a[], int fst, int mid, int lst);
R EFERENCES
PROC mergesort (int a[], int first, int last) [1] M. Felleisen, R. B. Findler, M. Flatt, and S. Krishnamurthi, How to
{ if (first >= last) return; Design Programs: An Introduction to Computing and Programming.
int mid = (first + last) / 2; MIT Press, 2001.
mergesort(a, first, mid); [2] J. Gosling, B. Joy, G. L. S. Jr., G. Bracha, and A. Buckley, The Java
mergesort(a, mid+1, last); Language Specification, java se 7 ed. Addison-Wesley, 2013.
merge(a, first, mid, last); [3] P. Hudak, The Haskell School of Expression: Learning Functional
} Programming through Multimedia. Cambridge University Press, 2000.
[4] G. Hutton, Programming in Haskell. Cambridge University Press, 2007.
• Dynamic data structures, such as linked lists and trees, [5] ISO/IEC 9899:2011 Standard, Information technology – Programming
e.g., in-situ reversal of a simply linked list. languages – C, International Organization for Standardization, 2011.
[6] K. Jensen and N. Wirth, Pascal user manual and report — ISO Pascal
struct node { int data; struct node *next; }; standard, 4th Edition. Springer, 1991.
typedef struct node *list; [7] B. W. Kernighan and D. M. Ritchie, The C Programming Language,
2nd ed. Englewood Cliffs, NJ: Prentice Hall, 1988.
PROC reverse (list &l) [8] L. C. Paulson, ML for the Working Programmer, 2nd ed. Cambridge
{ list q = NULL; University Press, 1996.
while (l != NULL) [9] B. Stroustrup, The C++ Programming Language, 3rd ed. Addison-
{ list p = l; Wesley, 1997.
l = p->next; p->next = q; q = p; [10] N. Wirth, “The programming language Pascal,” Acta Informatica, vol. 1,
} pp. 35–63, 1971.

You might also like