Multiple Paradigms in CS1 - CS2

Multiple Paradigms in CS1-CS2: A discussion

Eyal G.

Open University Seminar

Contents

1 - 26

Multiple Paradigms in CS1 - CS2

1 Introduction...... 3

2 Overview...... 3

3 CS1 – CS2 objectives...... 3

4 Different programming languages and paradigms...... 4

4.1 Brief evaluations of languages...... 4

4.2 The first programming paradigm and language dilemma...... 6

5 Language choices and their outcomes...... 7

5.1 Paradigm Shift...... 7

5.2 Assessing the ripple effect of CS1 language choice...... 8

6 Introducing different approaches for teaching...... 9

6.1 Programming-first approach weaknesses...... 9

6.2 Design approach...... 9

6.3 Different paradigms and languages...... 12

6.4 Different paradigms – Only one programming language...... 14

6.5 The use of laboratory...... 16

7 Studies of the comprehension of students for different paradigms...... 18

7.1 Research introduction...... 18

7.2 Background...... 18

7.3 Research questions...... 19

7.4 Research methodology and description...... 19

7.5 Results...... 20

7.6 Discussion and conclusion...... 23

8 Ideas and thoughts...... 24

9 Conclusion and discussion...... 25

1 - 26

Multiple Paradigms in CS1 - CS2

1

2Introduction

In this paper I want to raise a question about a method for teaching the CS1-CS2 courses. The question is not about which paradigm to teach. It is not about the consequences of teaching a particular language over the other. The subject in question is can we think of a different approach for teaching, an approach that uses multiple paradigms and programming languages for teaching the introductory courses? I focused mainly on the imperative and object-oriented paradigms.

I wanted to focus on the introductory courses because of my own personal experience. My introductory course was based on Pascal (the imperative paradigm). I had a good experience on how to implement algorithms and data structures in the following course (CS2) using the imperative paradigm. Later on I had a course in C. Needless to say that it was in the imperative paradigm. By that time, I believed in that way of thinking. My first acquaintance with the object-oriented paradigm was only when I started working as a programmer. It was very difficult for me to switch to object-oriented thinking. Today I have a few years of experience in programming in the “real world”. I mainly program in Java but also in other languages such as C.

I feel that my imperative basis was very good and helpful for my career. On the other hand, the basis of the object-oriented was very poor. During the years I managed to learn better OO concepts, yet with lack of good foundations.

Could I have had a different foundation, one that gives basis for the imperative paradigm as well as the object-oriented? When I began looking for a subject, I was interested in whether there is any curriculum that introduces a multiple-paradigm approach. The results surprised me.

It was very difficult to find papers about multiple-paradigms teaching. Was this idea ever considered? The lack of materials was another reason for choosing this subject. I wanted to see if this idea is realistic.

3Overview

The first part of the paper summarizes the CS1-CS2 objectives, the main characteristics of the different programming languages and paradigms and the consequences of choosing one over the other.

The next part introduces different approaches for teaching paradigms and programming languages; multiple languages and paradigms, one language – multiple paradigms and the use of laboratories. It has a chapter that describes a study of the students' comprehension of the different paradigms.

The last part concludes opinions of different authors regarding the question of multiple paradigms, as well as my own personal opinion.

4CS1 – CS2 objectives

In order to decide what paradigm and programming language to teach, or even if we should teach two or more paradigms, first we should understand the introductory courses objectives.

In this section I will present different objectives found in many papers. Generally, the objectives can be divided to the tools we want to give to the students, the students’ understanding of what Computer Science really is, the future effect of the courses and the students' comprehension of a program.

Reinfelds [15] says that a typical course should include in two semesters the study of algorithms for searching, sorting, backtracking, recursion, hashing and parsing. It should also include data structures such as arrays, records, lists, queues, stacks and trees. We can call these elements the items for the student's toolbox.

Alphonce & Ventura [1] bring a new goal for the courses sequence, which is giving the students a thorough grounding in OO design as well as an appreciation for the importance of a good programming practice.

Dingle & Zander [5] look for the effect of deciding which programming language and what paradigm to teach. They found that in recent years, unlike back in the old days, there is a demand to use a language with significant market share. They add that teaching a specific skill (program in language X) should not replace teaching core concepts of programming. It is also important how easily a student learn the language, the language features that help understanding the fundamental concepts, and the features that help the novice to become a competent programmer.

CC2001 [9, c. 7]

Chapter 7.5 describes the expectations of the introductory curriculum. It mentions that introductory computer science experience should expose the students to the design, construction and application of computer system. It must also introduce some of the central intellectual aspects of the discipline. When we view computer science as a discipline, it is important to look beyond its popular conception as a tool but to consider its conceptual foundations. Upon what principles does it stand? What new concepts does it bring to the realm of knowledge? What kinds of questions do computer scientists ask? What modes of thought and mental disciplines do they bring to bear on problems? According to the paper, it is possible to develop introductory courses that accomplish the following goals:

Introduces students to a set of fundamental computer science concepts.

Facilitates the development of cognitive models for these concepts.

Encourages students to develop the skills necessary to apply the conceptual knowledge.

Facilitates transfer by students from two-year colleges into four-year programs by establishing clearly defined outcomes and content equivalences.

Summarize

To summarize the objectives, the introductory courses should give the students:

  • A basic toolbox, which will contain basic algorithms and data-structures (Example: Searching and stack).
  • A good programming practice rather than just implementation of the fundamental concepts.
  • Good foundations for the industry market.
  • Core concepts of programming.
  • An exposure to design and construction of large applications.
  • Top-down design understanding.
  • Different ways approaching and solving problems, as well as the ability to identify a problem type and its method for solution.

5Different programming languages and paradigms

To teach multiple paradigms, we should know the different characteristics of the languages and paradigms, as well as the difference between them. This chapter summarizes the basics taken from several articles.

5.1Brief evaluations of languages

The following section is taken from Dingle & Zander [5] article about assessing the ripple effect of the CS1 language choice.

5.1.1Procedural Languages

Pascal

Pascal was developed as a teaching tool. Its strong typing and clear distinction between functions and procedures ease the introduction to programming. The concept of indirection is supported through pointer and provides a foundation for the study of memory management.

It was never intended that Pascal should be used in the industry and nowadays it’s a disadvantage. Although students should be able to teach themselves any language once they know the basics, they and employers still want to have an employable skill in CS1. This attitude sometimes conflicts with pedagogical views.

The transition to another language should be primarily syntactical. Pascal prepares students well for this. In relation to basic language components, the transition to a new language can proceed smoothly. Lack of OO and the use of global variables are deficiencies that may hinder the transition to object-oriented language.

C

Since C was introduced, it had a tremendous impact on the world of programming. It has small and powerful grammar. It provides manipulation of data at both high and low levels. However, it has a weak typing, no boolean type and lots of implicit casting. The spell flexibility is confusing for the novice programmer. C’s compact and flexible coding scheme leads to clever, but un-maintainable, code. (Example: while (*s++ = *t++) ;)

C’s I/O is marginal in terms of use and clarity, a significant drawback since it is a critical part in CS1. String and arrays are not easy to use as well. Another negative is the restriction to pass by value parameters. In C, one must introduce pointers prematurely or delay parameter passing in CS1. Neither approach is optimal.

C does not pave the way for a smooth transition to other languages or concepts. Missing in C is the idea of distinguishing incorrect or useless code from uncompilable code. Students cannot learn a second language in a primarily independent fashion.

5.1.2Object-Oriented Languages

The tenets of object-oriented programming, abstraction and information hiding can be easily worked into fundamentals in CS1. With an object-oriented language, it is possible to start with the traditional structured programming approach or introduce objects first. There is an unhealthy desire to want to cover all OOP in CS1. Coverage dedicated to advanced OO concepts takes time away from the fundamental topics of typing, control structures, functionality, etc.

C++

One cannot talk of C++ without talking of C. It offers better I/O than C. It offers pass by reference and by value, pointers, exceptions and classes. Some say that C++ is strongly typed, but only with respect to the default static typing. Otherwise, C++ is weakly typed like C.

The interaction of C++ and C provide some problems. Memory allocation is different. The danger lies in mixing both ways of allocating memory. For example, the C++ delete will not release memory allocated by malloc.

The biggest problem with C++ is its complexity. The volume of its syntax and multiple uses of keywords easily lead to confusion.

C++ provides the Standard Template Library, which can be used effectively in CS2, and gives a stronger notion of typing than C. The transition from C++ to other languages is typically smoother simply because if students have somewhat ‘mastered’ C++, learning another language is perceived to be an easier task.

Java

Java has ‘invaded’ to the application area of its intended use. Students can easily and quickly write visually appealing applets and thus feel good with it. It offers better constructs than C++. It has easy to use String and arrays with bound checking. The language can be used to emphasize the importance of GUI.

Its I/O is horrendous; everything is read as a string. This requires exception using, which is a problem. It's very difficult to teach that at the beginning of the CS1 course, but it is also hard to wait with it until the end of the course. The problem can be overcome by using a utility library for I/O.

Another annoyance is the inconsistent treatment of data; everything is an object except primitives. Pass an object means pass by reference, which means changeable, and this is confusing because primitives are passed by values, which means unchangeable. Java syntax has the same problems of clarity and complexity as C and C++.

Java control inheritance and provides a common Object base. It has a built-in concurrency features. These topics are not relative to fundamentals of CS1.

The internal memory management of the JVM (using the garbage collector) removes the responsibility for memory management from the programmer. Student do not have to concern for their object memory management. However, it may be beneficial for students to learn the basic tenets of memory management early on.

The biggest problem is the lack of pointer using. Without pointers, students don’t get the opportunity to truly understand indirection and addressing. A delayed introduction of pointers minimize the repetition students receive causing negative impact.

The transition from Java to C++ is more difficult than vice versa. If the OO concepts are not well taught, students may leave CS1 without concrete understanding of what a class means semantically.

5.2The first programming paradigm and language dilemma

W. V. Quine [13] said ”One frequently hears it urged that deep differences of language carry with them ultimate differences in the way one thinks, or looks upon the world.” This is called the Sapir-Whorf Hypothesis.

I will “translate” that to my words: A person's way of thinking is based on the language he speaks. This is exactly the same for the programming language.

Brilliant & Wiseman [3] say that the importance of nonprocedural programming paradigm has become much more accepted. This has complicated the problem of choosing a vehicle for teaching programming to beginners. There is an increasing consensus that students should be introduced to both object oriented technology and functional programming at some point in the undergraduate curriculum

Their research has revealed some papers describing the benefits and/or problems associated with teaching a particular language and/or paradigm to beginners, but no comprehensive discussion of the issues and alternatives.

To understand better they made a survey in other universities regarding their experience on whatever paradigm and language they were using. Below is summarizing of what they have found, together with more sources that describe the paradigms.

5.2.1The imperative paradigm

The most important factor for most respondents of the survey was the fact that most commercial software was still being developed using this paradigm. Some mentioned the needs of non-majors taking the introductory programming course. Many of the respondents cited the most compelling reason to continue teaching the procedural paradigm, their conviction that it is still the pedagogically superior alternative!

Luker [11] mentions that most “production programming” is carried out in high-level procedural languages.

We should also remember that most other paradigms have built-in imperative programming constructs. On the other hand, the imperative programming languages usually imply the need to focus on the syntax and the particular characteristics of the language.

5.2.2The object-oriented paradigm

As the object oriented paradigm (OOP) has gained mainstream acceptance in the computer science community, its introduction into the undergraduate curriculum has become an issue. One report said that the paradigm shift is difficult only in one direction, from procedural to object-oriented. Another mentioned that “Despite claims that object-oriented problem solving is more natural, I found that the new mindset did not come naturally to students with ingrained notions of problem solving from a procedural perspective.”

Those teaching OOP indicated somewhat fewer student difficulties in switching to other paradigms than those teaching the PP.

Bruce [4] adds that it has become clear that there are important advantages to the object-oriented paradigm, especially in terms of composition and reuse of code. He also mentions the difficulty to switch to object-oriented way of designing algorithms. Bruce [4] says that object-oriented can help adding different areas of computer science. The object-oriented paradigm would make it easier for the instructor to provide simulators that can be modified by the students. Thus students can build their programming skills while learning about other areas of computer science via emulators. Moreover, the use of inheritance will require students to read other programmers' code, making it easier for them to write good code themselves.

Luker [11] claims that writing software in terms of objects results in code which is a much more natural description of the job in hand, more faithful to the structure of the problem.

The object-oriented paradigm allows using it as a design medium. Another benefit is that the model of the cooperating objects is intuitively close to human experience. An important note is that object orientation is the most popular paradigm in the industry.

On the other hand, object-oriented paradigm will create the need to add more subjects to the CS1 curriculum.

6Language choices and their outcomes

6.1Paradigm Shift

“Think of a paradigm-shift as a change from one way of thinking to another. It's a revolution, a transformation, a sort of metamorphosis. It just does not happen, but rather it is driven by agents of change.” (Taken from what is paradigm shift?[8])

In his book, Fowler [6] explains paradigm-shift as: "In general the OO style is to use a lot of little objects with a lot of little methods that give us a lot of plug points for overriding and variation. This style is very confusing to people used to long procedures; indeed, this change is heart of the paradigm shift of object orientation. It's something that's very difficult to teach. It seems that the only way to really understand it is to work in an OO environment with strongly distributed control for a while....” (p.56)

When Luker [11] wrote his article he foresaw the paradigm shift in computer science. He predicted that students would need to learn object-oriented paradigm.

Most articles that discussed multiple paradigms or the dilemma choice mention the paradigm-shift issue. They especially claim that it is harder to switch from the imperative to the OO paradigm.

6.2Assessing the ripple effect of CS1 language choice

What is the best language to teach in CS1? This is a long debate. Much of the controversy on the ‘best’ language for use in CS1 centers on the goals of CS1. In most discussions, the effect of the language on subsequent courses in the CS curriculum is missing.

Dingle & Zander [5] focused on the choice of a programming language for CS1, and the resulting effects on students' progression in the CS curriculum.

6.2.1Overview

More than two decades ago, most CS departments taught CS1 in Pascal. There was little concern about the marketability since students were not expected to work professionally right after the first formal CS course. Faculty could argue that the language used in CS1 should be no more than a detail necessary for the implementation of the fundamental concepts covered in CS1.

Times have changed. Unlike other science or engineering disciplines, there is an expectation of proficiency following the first course in CS. There is a demand to use a language with significant market share. However, teaching a specific skill (program in language X) should not replace teaching core concepts of programming. Much of the continuing discussion on what language to use in CS1 centers in specific language features and their impact on a pedagogical review of the tenets of programming. It is important how easily a student learn the language, the language features that help understanding the fundamental concepts, and the features that help the novice to become a competent programmer. Dingle & Zander [5] look specifically how language choice impacts subsequent learning in later CS courses.