The Top 10 Reasons Why Object-Oriented Programming Can't Be ...

60 downloads 44456 Views 492KB Size Report
Programming. Can't Be Taught in CS 1. Rick Decker and Stuart Hi.rshfield. Department of Mathematics and Computer Science. Hamilton College. Clinton, NY ...
The Top 10 Reasons Why Object-Oriented

Programming

Can’t Be Taught in CS 1 Rick Decker and Stuart Hi.rshfield Department of Mathematics and Computer Science Hamilton College Clinton, NY 13323

Abstract. Over thepost year we have changed our CS 1 coursefrom a standard PascaLbased, procedural prograrnnu”ng

course into one that emphasizes C++

object-oriented experience

programming

to&e

indicates

[OOP).

and experiment

and

that this was a good the

_

to us to lack what are currently

software

engineering

produce working

did not come easy. We struggled long and hard with many, if not most, of the questions and Lrsues that decision

have come to be associated with teaching 00P

and so on), our experien~

skills.

ptugrsms,

capable-even

programs of their own. progr amtnittg

specifying,

many of the reasons we came up with for not using 00P in CS 1 are seen to rejlect our lack of urrderstaruiing of the paradigm, our fear of the kmguage, and our part ~erience teaching Pascal and the procedural paradigm. Furthermore, we believe that our reservatwns (which appear to be quite common) stemrnedfiom a grrnving experience

that k contrary

and that thti paper attempts

&signing,

&velopirtg

Rhetoric

and ettrrent

texts notwithstanding,

our students were

solvers,

skills that we regarded

eomerstoncs

frustration

with this situation

led us to question

our students’

in pm

had been teaching

to our

them.

If what we had been rcadmg and hearing was accurate

as our

(and it was consistent

with

HypetCard/HypetTalk

in our CS O course), objcct-

00P

our experience

appeared to extend the familiar

to effectively &scribed

The introductory

as emphasizing

and ttpper-

Such art approach,

are not ordy psrsmotm~

clearly reflected

in the resulting

that most of us have been advoeatirtg

out best efforts

interactive incorporating

complete

(teaching

and integrated extensive providing

on their own.

modem,

highly

now.

of Pascal,

software

implementations hands-on

students

sample programs

dil%cult

laboratory

with

interesting

and

of

the

publication

and

date

appear.

teaching and designing

and

notice

around 00P

design.

19 given

the level of abstraction included. higher-level

1994 ACM 6-89791 ~..$3.=

51

and testing,,

Most importantly,

an undergraduate

appeared to be justified

science education-is

many of the

terms: code reuse,

development

the real value of the paradigm-and computer

that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republieh, requires a fea and/or specific permission. SIGSCE 94-W, Phoenix ArfzonaJJSA @

incremented

life cycle

for some years

that are among the most

to convey in procedural

sn~ of emu-se, program

to read, analyze,

its

concepts

in which

but are alscI

development

was said to support directly

engineering

encapsulation

Permission to copy without fse ell or part of thie meteriel ie granted provided that tha copies ara not mada or distributed for direct commercial advantage, the ACM copyright notice and the titte

00P

was

brings us a stqp

co&,

model,

program

paradigm

00P

problem-solving

design decisions

closer to the idealized

and solve problems

In principle,

a strategic,

level courses presumed that students ecmld use them to analyze,

teaching

procedural

address all of our problems,

approach to progr amming.

to present and develop

skills with thetm and our middle-

Our not only

how we had been teaching our majom, but also what we

to dispel.

paradigm

of our curriculum.

sequence was intertd~

ex~ences,

and were not

as essential to bo{h

their subsequent emuse work and to their careers.

amrning tools in CS 1 for marry years. Ind@ Pa together they constituted the linguistic and problem

Despite

analyzing, even modest-sized

Onettted progr arrtming was the answer.

We had ttsed Pascal and the procedural

readabh>

Still fewer were

and managing

not bektg trained as problem

Introduction

solving

few wrote

as modular,

Cs 1 course-of

after our

pedagogical questwns that we considi?red. In hindsight,

folklore

relatively

traceable, testabl% or maintainable.

to

regarded as basic

Of those students who

programs that could be described

undergraduates. This paper recounts our struggles, and presents our responses to the more serwu of the

body of rru”sleading 00P

in recent

otherwise.

That is to say, alt but our very best students

While our

deciswn for both our students and our department,

wi~

years had indicated

curriculum

by our feeling that its significance

that it effectively

for all programmers,

to raises

novices

Who, after all, stands to benefit more from a progr arnming

interface

than do novices.

In practice, resmtcture

as is often the case, the decision

our ctmicuhun

L&e the many educators who had considered question before and sin%

extending

this

we were confronted

pogrammin g languages.

Order

to

was much more intimidating. with a

the procedural

forms of abstraction

provide

within

a context

decomposition

imagined)

effectively

for not changing

over to 00P.

The fact is, we

Reason

The bulk of this paper, though presenting

and responding

Letterman

tradition)

arguments

for not adopting

While

to (in the classic Turing55 the paradigm

of

long and hard

“advanced”

topic suitable this way, too.

finally

of the psradi~

commonly-used

languages

00P

biases derived

C++),

(3)

horn years of teaching

to using 00P

we describe briefly

programming

present our eventual

rationale

to using 00P,

experience.

Reason

#10:

experience,

“pizzazz”

of these programs

This objection outdated

andfor obsolete next year?’

being somewhat 00P,

from our

programs

sequence. invest my time

course was populated

initially

programming

is not new.

Neither

programming

FirsL they wished they had to 00P/C++,

parallels

Many

between these

felt let down going from

CS O to a Pescrd course because they were suddenly forca

is the idea of

to teach novice. programmers

think they call it Smalltrdk?).

00P

or academi~

progr smrning

(why do you

has survived

ss it has, despite not being widely

supported

because it is a powerful

together

of a number

(for example,

of seemingly

the software

of code reuse, data-oriented

as long

desig~

and modularity,

notions

of declarative

Even more telling

means for

end scripts),

all applied

Most convincing this is particularly

true when thinking

is a natural

and

Intelligence

suddenly

saw virtue

careful

designed.

as

concepts that we

attention

Furthermore,

scratch with 00P/Ctt

of higher-

We maybe

52

belatedly)

taken on

The students

in distinguishing in developing

far more comfortable

(and

in terms of C++)

step in the evolution

and had (somewhat

in the context of 00P/C++.

paying

frames,

is the response

engineering

meaning

an implementation,

to the task of programming.

to us, thoug~

they

had harped on in the Pascal course had at long last become tangible

dkparate

representatio~

the programs

was their (rind our) recognition

that many of the software

engineering

and the ArtMcial knowledge

In sho~

those they could write in CS O.

by either

analysis

minutiae.

could write in CS 1 were nowhere near as interesting

modelling real word applications, particularly those with sophisticated user interfaces. Also, it can be seen as the

that 00P

in CS 1.

with students

to deal with what they regarded as a great deal of

using 00P

concepts

“worlds.”

were far

response to the cottme

because of the more obvious

put off by all of the hoopla surrounding

First off, 00P

principles

introductory

gone right from HyperCsrd/HyperTsllt

we don’t see it that way any more for a number of

coming

OUT

collective

to the

than were the Pascal

our CS 1 students were producing

Their

of sampling

but still we were impressed

expressed two basic themes.

that will be

After

turned in by

To be sure, much of the

better designed and organized

reasons.

industry

amazed at the

projects

by the fact that many of these CS O projects

CS 1 to fit a paradigm

and

survey course (CS

for considering

a fad!

can be restated as: “Why

and energy revising

and C++ that

was attributable

graphic nature of HyperCarc$

who had been through is just

in 00P

and no intention

any further.

The 00P/C++

OOP

elective

us to take the CS 1 plunge.

end then

response as it has evolved

teaching

majors.

In fac~ it was our experience

of the progr amming

our CS curriculum

in CS 1, and to dispel

our original

the

these students, most of whom had no previous

For each of the top ten objections,

detetrent

1

CS

to acknowledge

as part of our introductory,

sophistication

them we attempt at once to

some of these myths. it as a legitimate

of

most still regard it as an

O). Each semester we were repeatedly

body of 00P

our responses to ten of the most commonly

cited objections

my

only for upper-level

an upper-level

convinced

HypetTalk

a number of myths about 00P.

In what follows, articulate

can

We had for many years been teaching HyperCard

(2) our fear of the

or (4) what we now see as a growing that refleets

(1) our

(most notably

for

are willing

We thought in teaching

lack of understanding

hard

value of the paradigm,

them all to reflect

one or more of the following:

is too

many instructors

potential

some of the more compelling 00P

00P

#9:

with eaeh of these, but have since come to recognize

folklore

development

take place (more on this in our discussion

students!

is devoted to

choice for CS 1. To be sure, we struggled

Pssc~

and algorithm

but also to

functional

we and our students have derived

from the decision.

our procedural

which

Reason #7, below).

At the end of this paper, we will

describe the benefits

to not ordy allow for

new data-oriented

long list of reasons (some real and some, as it turns OUL did it and we’re glad.

JndeecL we see OOP 55

paradigm

sn interface

reuseable

from

code, and in

to how their programs

were

many students said that they felt attacking

a complex

problem

from

than they did with Pascal.

slow, but it eventually

occurred to us that

OOP fit much more closely introductmy upper-level

electives.

In=

skills that we wanted to instill beginning

CS 1 topics could fit with the the 00P and couldn’t

these were the kinds of

interesting

programs

in our majors horn the

previous

of their programming

use, as we’ll playing

traditional paradigm,

with the goals of OUT

sequence than it did with those of any of our

describe later, was to introduce

to the paradigm’s

strengths-that

00P

but tha~ we now realize,

More generally,

00P

which

deiiming,

functional

decomposition,

algorithm

control

Reason

and using classes. #8:

The

psychologists

would be likewise

confused.

shif~ from procedural

ones, that had confronted

situation

texts,

crack at an algoritilc

breaking

a problem

subproblems.

of our

always taught our students about algorithm

Reason

“OOP-lsh”

We considered

those of our students who

students to cool

along with

that wss new to most of

00P

l—it

renders the notion

virtue of using 00P

of a paradigm

in CS

shift moot.

There

and for those with

notation

it is most often a

their

change.

their procedural particularly

That is, these students programming g expertise

avoids having

software

engineering

can exploit

to defiig formalism

concepts.

to shift gears when introducing

and pseudo-language

History

it later,

convinced

and our brief experience

Using 00P

as a

in turn led to the development

progr Smming

skills

much easier, in p@ paradigms context Reason

procedural

becaose it reflects

is

providing

devoted a

This objection

You

chapters

the paradigm. still

need

(and we certainly programming”

such a

we feared that our teaching 00P qualify)

paradigm

cart be restated in a number of forms,

work~

the early

movemen~

which

They, too,

illustrating,

via structure

and the like, the salient features of

These formalisms

perhaps more directly

algorithms!

has

of Pascal, recall the fiirst

to graphically

charts, IPO diagrams,

for functions. #7:

If mastering

texts that used that phrase in their titles.

how the

are meant to fit together-lasses

helped to express,

than a program

cm

how the

what it was capable of representing,

most of which translate into “but how can you ignore loops, or selection statements, or stepwise refiiemen~

and how to exploit

and the like?”

The fact remains that as we all become more familiar

As 00P

noviax

We were particularly we couldn’t

and

us that such is not the case. Those of us old

days of the “structured

means for developing

to 00P,

clsses

many chapters

CS 1 students might never get to write a program. It also

enough to remember

to 00P.

Every text that

for describing

and using the formalism. were a prerequiahe

is tough only in one

procedural

amount of

some devoting

say in CS 2. Many who have made the leap, including direction-from

inordinate

one of

aspects of

associated with the paradigm.

us, now see that the paradigm

shift

Inded

and least appealing

interrelationships,

(agb

in C++), and extend it to address the

aforementioned

of the paradigm,

perspective.

we picked up seemed to describe its own cumbersome

simple isn’t one for most students,

positive

as better appreciation

to us was the seemingly

more extensive

Pascal experience,

to usrng 00P

much less in CS 1, until ‘we

a bit of historicrd

formalism

overhead!

this a serious objection

the more intimidating

them. Herein lies a stunning

The

had developed

heels for a semester, and to solve

using a paradigm

#6:

anywhere in the curricuhun,

In fac~ this was one of our reasons for developing

problems

development

By and

new, more principled

forced incoming

of

(in C+-+)

down into more manageable

progr amrning habits and to pickup

their programming

functions

At that point, much of what we have

large, we want such students to unlearn their bad

our CS O course-it

reflects but also

description

By associating

it works!

ones.

paradigm is

with classes, you have already taken a giant step, and for

languages to

with programming g experience.

and

but must still

that not only clearly

comes into play—and

come to college

retlmemert~

not only c-

many students this is the toughest step by far, toward

is that we have for many years devoted a good

deal of energy to nun-teaching”

within

(including

classes one imposes an

on a problem

those same aspects.

confront

us. The reality

a framework

development

stepwise

structures)

describing

serves as a fiist

The fault in our argument

that our students would

provides

tdgorithm

those aspects of the real world being modelle4

and assumed that our students

lay in the presumption the same paradigm

organization

to

a few 00P

for

is only part of the

One of the beauties (to us) of the 00P

that by merely

of what

and we fell prey to it,

in CS 1, we looked through

conventional

oaur.

shift! example

begart to give serious wnsideration

found it tough going,

00P

paradigm

call “projection”

When we fiit using 00P

dreaded

appears to be a textbook

We said in our

a context

story.

by

is, by letting

students focus from the start of CS 1 on declaring,

This objection

how smdettts could write

using them.

response that classes provide

functions,

careers. The trick for

imagine

without

served a similar

naive in this regard.

see how all of these

a particular

53

it as a programmer.

Flowcharts

purpose for the FORTRAN

paradigm,

generation.

we have less need for the

with

associated formalism-either

or when we try to teach it to others.

gaining

experience

with a paradigm

recognizing

its important

themselves

in programs.

features

From our perspective, experience

with 00P

directly

in a progr~

written

in C++.

(declarations)

as they manifest

particularly

take much

files (a main function

some nice side benefits.

In effec~

adequate formalism.

describes

by

detail.

a problem

Secon~

revealing

it provides

level of &tail.

Finally,

problem-solving

a variety

00P

languages

speaking

of pro *g who has resisted teaching

are

programming

programming

thsn our gO&

notational

solving

order in which

they acquired

algorithm

development.

It simply

developed

proficiency

pressure from industry

and our stttdenta notwitbstandittg,

most of the reasons we had for adopting as the language for teaching

inverting

Pascal (over C)

CS 1 some years ago still

algorithms,

held. As soon as we began to apply the language to a of sample programs

C++ succeeds in overcmning the awkwardnesses reference

parameters,

the preprocessor). almost entirely

and loo setting its dependence

The ugliiess to the detailed

and cart be minimized concentrating

providing

that remains description

by sticking

on the 00P

on

of algorithms,

paradigm.

C-I-+ as much more than “a better C.”

In shofi

to procedural

and many talk additionally

techniques

about problem

as they relate to the paradigm.

these portions

coverage of 00P

of a course with comparable

represents an even exchange in tcnns of

amount of material.

Based upon its

as a design too~ and its support of the entire

Reason

software

engineering

curriculum!

(which

with

to a syllabus.

an introduction

strengths

life cycle,

one paradigm

add anything

texts spend at least one chapter on

Replacing

we regard

the goals for a

sequence.

what is essentially solving

fast to and

accomplish

of

emphasis on

Most Pascal-based progr amming,

pertains

Thus, by

the procedural

note-replacing

another in CS 1 doesn’t

most of what we regarded as

of C (by, for example,

reflects

introductory

One fiial

it became clear to us that

after one has a

description.

CS 1 and CS 2 ordering

one can easily

conventional

vmiety

clearly

means that

of-and

for-data

the traditional

topics, which

As we

doesn’t mean that one ignores

C’”!

We felt thaL

The

so long as they had them all before

come in the context

of C++.

skills.

those skills was

algoritbnts

we were petrifkd

sequence with a certain

to the upper level of the curriculum.

said befor% using 00P

l~suagess why WO~d snYone C to novice programmers for

that our goals

sequence were more

and progr atmning

set of problem

proceeding

ugly!

it

for CS 1. That is, we wanted

15 years now want to teach those same students “a better Truth be told

topics in a

The fact is we can’t-and

students to leave the introductory

unimportant #5:

course?

matter.

irnpo~t

overhead. Reason

are extremely

The trick here for us was to recognize

for each

minimal

even just considering

could we ever expect to cover

and all of the traditional

for the introductory

levels of

a readable notation

Still,

most standard CS 1 syllabi

How, we though~

doesn’t

didn’t

in CS 1 while sise trying

of other non-prograttutimg

science topics.

single-semester

FirsL it

successive

with

to incorporate

00P

has

So, in one sense, we

amtning.

about using 00P

that uses the

it engenders a poweriid

methodology

prOgr

have to worry

tight.

the language itself

serves as a perfectly

otu as most of us have for years, problem

and

programming,

to solve a problem),

experience

we are free m our version of CS 1 to

solving

(definitions)

files

science, and is required of ail

concentrate

computer

is

header files

implementation

and definitions

its virtues

when the program

Distinguishing

and from program declarations

they enter wi*

we get good at

it doesn’t

survey of computer

majors no matter how much programming

After

to be able to identify

from

blown

when we use the paradigm

ourself,

and its hybrid

allows our, and some of our students’,

nature experience

#3:

It

screws

up

the

rest

of

our

We were led to believe (we aren’t sure by whom or by

with algorithms and top-down design to come more directly irtto play than it might had we chosen a “pure”

what) that adopting 00P as the programming paradigm for CS 1 would cause grievous harm to our entire

00P

curriculum.

language),

we consider it as a better Pascal, and thus

as a solid choice for teaching

CS 1.

In hindsigh~

was that using 00P our introductory

Reason

#4:

materiai

in

There’s CS

already

too

much

is a particularly “breadth-fiist”

timely

Programming,

about our CS O course.

which

courses, with

sequence (which,

and data structures)-attd

Once, thougk

one given the move toward

introductory

programming

case, is only two courses that cover problem

1!

We should preface our response to this objectiou

what we might have suspected

in CS 1 would cause a restructuring

one is willing

of the order in which

a reminder

introductory

Since our CS O course is a fuU-

progr amming

54

solving,

it did.

to be flexible

in terms

topics are presented witbin

sequence (whatever sequence entails),

of

in our

the

your introductory the remainder

of the

curriculum

remains

is that middle-

intact.

The only substantive

and upper-level

built around Pascal.

The advantages

change

courses can no longer be for that matter)

of this approach

are both numerous

the object-oriented

works as well in academia as it is alleged to work in

beginning

allows us to exploit

industry,

Second

it should be even better-suited

offerings,

particularly

scale programs,

to the upper-

those that involve

lerge-

than was Pascal.

refinement) solvittg

Reaaon data

It

#2:

fits

perfectly

with

CS

2 and

perfectly

with material

that has traditionally

covered in CS 2 and in data structures

and most importantly,

been

problem

courses.

For this

to these later courses.

didn’t

We thought

First

programming

programmers

for solving

it does and is-then

as a paradigm

available

the paradigm

we believe

that

%cort~

and equally

and software

importartq

engineering

the kind of problem

Inc.,

San Francisco,

Publishing,

Inc.,

to ComD uter Prom ammirw

Publishing,

Inc.,

Undergraduate

Bostom

D. “The Object-Oriented Curriculum

Oriented

SIGCSE,

them procedural solving

paradigm

1991.

and then asking them to make the aforementioned paradigm

shift in their second programming

Reason

It’s

#1:

This objection brutally

too

00P

going to take a great &al

ourselves, teach it.

us!

into our curriculum,

of effort.

it was

If we did so in a way

more than one course, it would

take even

FirsL we would have to learn the material and become comfortable

We would

implementation

of it.

secure, and learn a particular

An&

what about a text?

Second, it is the one objection response for, especially Doing

enough with it to

have to choose a programming

language, and then fm~

00P.

FirsL it is

No matter what we decided to do in

terms of incorporating

that impacted

for

is ranked #1 for two reasons.

honest.

more effort.

hard

course.

so certainly

after having

Ugh . . .

that we have no good made the change to

entailed much more work than

it would have been to teach Pascal again,

Fortunately

us, and thanks in large part to the support

and

enthusiasm

for

of our students, we feel it was well worth the

effort.

55

SIGCSE,

Paradigm”

1991.

using

c ++, Pws

Paradigm

in {the

A Survey of Implementations

We couldn’t

problem

1989.

1994.

Begin Introducing

as art operative

En-

S. The Obiect Concq~

Introduction

[4] Mazaitis,

that 00P

San Francisco,

[5] Temte, M. “Let’s

progr amtning

their

their

Science Using H VDerim,

and Issues,”

teaching

with

S. The Analytical

to Commter

mpports most directly me those that we want our students to adopt when they write their fiit programs. see ourselves

Finally,

ones.

[3] Decker, R. and Hirshlield,

course simply

skills

in conjunction

Publishing,

Wadsworth

does not play to its strengths.

solving

g.

[2] Decker, R. and Hirshfield, S. Pascal’s Triangle: . . ~eadiniz. Wntum and Reasortim Abo Ut Pro erarr@,

the most from it.

after the fiist

skills

Introduction

Wadsworth

this tool to precisely

those students who stand to benefit Introducing

is that

to all

problem-and

why &ny

from procedural

programtnin

it helps students to develop

[1] Decker, R. and Hirshfleltl

up

~

if the real virtue of 00P

(at lesa~ for the

References

about i~ too, but

responses.

it raises the level of abstraction

shift”

of

for two resaorta that have already been brought

in previous

solving

(alcng

and useful problcm-

it eliminates

g to object-oriented

does fit

reason many teachers choose to defer presentation 00P

‘fltir~

paradigm

design and stepwise

into a meaningful

context.

programtnin 00P

of top-down

FirsL from the

it as a design medium.

student! ) the dreaded “paradigm

structures!

It is tough to argue with this objection.

paradigm

doing so puts the procedural

with the i&as

to teaching

and tangible.

introducing

level

If C++ (or Small~

novices

Vol. 25 No. 3, pp. 58-64, 1993. the Object-

Vol. 23 No. 1, pp. 73-78,

Suggest Documents