⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usingc.txt

📁 c语言开发方面的经典问题,包括源代码.c语言开发所要注意的问题,以及在嵌入式等各方面的应用
💻 TXT
📖 第 1 页 / 共 2 页
字号:
                             Using C in CS1                   Evaluating the Stanford Experience                            Eric S. Roberts                     Department of Computer Science                          Stanford UniversityPermission to copy without fee all or part of this material is grantedprovided that the copies are not made or distributed for directcommercial advantage, the ACM copyright notice and the title of thepublication and its date appear, and notice is given that copying is bypermission of the Association for Computing Machinery.  To copyotherwise, or to republish, requires a fee and/or specific permission.ACM-24thCSE-2/93-IN,USA(c) 1993 by ACM.ABSTRACTIn 1991, the Stanford Department of Computer Science decided to abandonPascal in its introductory computer science courses and to adopt ANSI Cas the language of instruction.  We based this decision on severalfactors: the inadequacy of standard Pascal as a base for teaching modernprogramming concepts, the need to prepare our students for more advancedcourses in which they will be expected to use C for programmingprojects, and increasing pressure from students and faculty throughoutthe School of Engineering for instruction in a language that has becomethe industry standard.  We also believe that it is not reasonable toexpect students to learn C on their own; students must receiveinstruction in C in order to become good C programmers.  C has severalknown deficiencies that make it a challenging language to teach.  Basedon our experience at Stanford, we believe that it is possible tominimize the problems associated with teaching C at the introductorylevel by applying standard software engineering strategies -- proceduralabstraction, modular decomposition, and information hiding -- to goodpedagogical effect.  This paper expands on the reasons behind Stanford'sdecision to adopt C and summarizes the pedagogical approach.1.  INTRODUCTIONAny introductory course in computer science has one overriding mission:to teach students the basic programming concepts and methodologies thatmake more advanced work possible.  To a large extent, these concepts andmethodologies are independent of any particular programming language.However, since most of these concepts are best mastered through use, theintroductory course must choose some programming language as its mediumof instruction.For many years, most universities in the United States used Pascal tointroduce programming concepts.  Compared with many other programminglanguages, Pascal is conceptually simple and easy to learn.  Pascal isalso highly constrained, in the sense that it does not include certainpowerful features that are easy to abuse.  Such features tend to confusestudents at the introductory level, even though they may be extremelyuseful to more experienced programmers.Over the last five years, however, many schools have begun to move awayfrom Pascal.  The reasons behind this shift include:   o  Pascal is getting old.  There are several modern programming      concepts, such as separate compilation, string manipulation,      and the use of functions as first-class objects, that are not      supported by standard Pascal and that are therefore difficult      to teach.   o  The restrictiveness of Pascal's design occasionally forces its      users to "program around the language." Doing so means that      students develop certain bad habits -- habits that they must      later unlearn when they begin to work with more modern      languages.   o  Pascal is not widely used beyond the introductory sequence,      and students are therefore being taught programming style and      the discipline of software engineering in the context of a      language that they will never again use.  The first course      must provide an introduction to good programming practice.      Unfortunately, the effectiveness of that instruction is      compromised when the linguistic tools used to illustrate the      underlying concepts are so quickly abandoned.Even though a consensus seems to be emerging among educators that Pascalis becoming increasingly obsolete, there is no corresponding consensuson what language should replace it.  Various informal surveys ofcolleges and universities indicate that the first course in computerscience is moving in several competing directions.  Many schools haveshifted their curriculum to a language that adheres to the generalphilosophy and tradition of Pascal, but includes more modern concepts.In this category, the principal contenders are Ada [Winslow89, Frank90]and Modula-2 [Gabrini86, Koffman88].  Other schools have begun to use aLisp-like language, the favorite being Scheme as it is presented in thetextbook Structure and Interpretation of Computer Programs [Abelson85].A growing number of institutions, however, are choosing to adopt ANSI C,in light of its status as the language most often used for systemsprogramming applications.  Each of these approaches has merit, and it isnot clear that there is a single answer that fits all academicinstitutions.  At Stanford, we have decided to adopt ANSI C as ourinstructional language in the introductory sequence, for reasons whichare developed in the next section.2.  THE REASONS FOR STANFORD'S CHOICEIn 1990-91, the faculty in Stanford's Computer Science department heldseveral meetings to address the question of what language should be usedin the first course.  Since our introductory course serves a largepopulation of non-majors from other engineering departments, thatdiscussion was broadened to include the Engineering School UndergraduateCouncil, which has curricular authority over courses, like introductorycomputer science, that are considered to be "engineering fundamentals."As the various options were discussed, the systems faculty in theComputer Science Department and the representatives from otherdepartments in the Engineering School argued strongly for using C in theintroductory course.  There was also general support for the proposalfrom the department as a whole.  As one of the major proponents of C, Ihad been prepared to encounter opposition, but the decision turned outto be almost entirely without controversy.  With the support of thedepartment, I developed an experimental course using ANSI C, and in1991-92 offered that course as an alternative to the Pascal-basedcourse.  Based on the success of that experience, the department hasdecided to revise the curriculum so that, starting in 1992-93, allintroductory programming courses will be taught in C.The most important reason for this decision comes from the fact that ithas become increasingly important to teach C somewhere in the computerscience curriculum.  C is used in most upper-level systems courses, andstudents are expected to know how to use the language by the time theyencounter those courses.  In previous years, the only instruction thatstudents received in C took place in a sophomore-level "ProgrammingParadigms" course, which introduced the students to several differentprogramming languages, including C.  This course teaches thefundamentals of C syntax and structure, and expects that students willlearn everything else they need to know on their own.Unfortunately, students are better at picking up the syntax andstructure of a new language than they are at developing discipline inthe use of that language.  The introductory sequence at Stanfordconcentrates -- as it should -- on instilling in students the importanceof good programming style.  Unfortunately, at Stanford, and at manyother schools, we have been teaching people to become good programmersonly in the context of a language that they never again use.  Studentslearn good programming style and methodologies in the context of Pascal,but are forced to develop their own styles and methodologies for theother languages they encounter.  For some students, these criticalsoftware engineering skills transfer well.  For others, however, many ofthe concepts seem to get lost in translation, and we are thereforegenerating a large number of students who program well in an arguablyuseless language and who program poorly in more useful ones.  This isnot an ideal state of affairs.  We believe that it is not enough toexpect students to learn C on their own; they must receive instructionin C in order to become good C programmers.  Turning out anothergeneration of mediocre C programmers is not in anyone's best interest.There is a serious oversupply of such programmers today.Student demand was also a factor in the decision to adopt ANSI C.  Intoday's computing industry, it is clear that C has become the dominantlanguage for systems development, and our students are not blind to thatfact.  Given the choice last year between an experimental C section anda well-established Pascal section taught by a popular instructor,students expressed a two-to-one preference for the C section, most oftenciting C's practicality as the reason for their choice.The importance of student demand is heightened by the fact that theintroductory programming course at Stanford -- as at manyinstitutions -- must serve the needs of a diverse clientele.Approximately 700 students enroll in the introductory computer sciencecourse each year; of these, only 60 will go on to become computerscience majors.  Most of the students take the course to fulfill therequirements of some other major in the School of Engineering, and thereis also a significant enrollment of students from various departments inthe School of Humanities and Sciences.  For many of these students, theintroductory course will be the only computer course they take, and itis important for it to provide a good foundation in the discipline ofcomputing.Finally, it is important to recognize that the value of followingconventional practice has risen in accordance with the increased size ofthe computer science community and with the increased complexity ofprograms written today.  Twenty years ago, it was easy to have studentsin the introductory course write programs that seemed exciting tothem -- programs that seemed as flashy and interesting as theapplications they had previously encountered on their own.  Today'sstudents have grown up with Macintoshes and fancy graphical interfaces.To them, a program that averages numbers or even one that plays asimple, interactive, text-based game will seem like pretty tame stuff.It is impossible today to construct from scratch a program that meetsthe student's heightened sensibility of what a "real" computer programmust be.  To do so, one must make use of sophisticated softwarelibraries, such as the X11 library or the Macintosh Toolbox.  To usesuch libraries, however, one must program in a way that is compatiblewith them.  In most cases, this means working with a programminglanguage, such as C, that is implemented on the vast majority ofplatforms and offers a clean interface to those libraries.3.  AVOIDING THE PITFALLSFor the most part, the advantages of using C discussed in the precedingsection are fundamentally strategic in nature.  We believe thatintroducing C at the introductory level will yield long-term advantagesas students apply the knowledge and engineering discipline they havelearned to more advanced courses or projects that require a knowledge ofC.  Viewed from the perspective of the introductory sequence alone, itis clear that using C presents a variety of tactical problems.  I do notdeny for a moment that it is harder to teach C to beginning studentsthan it is to teach Pascal; my claim is rather that the long-termbenefits more than compensate for the short-term costs.  I also believethat it is possible to minimize the problems associated with teaching Cat the introductory level by applying standard software engineeringstrategies -- procedural abstraction, modular decomposition, andinformation hiding -- to good pedagogical effect.For example, one of the most common complaints about teaching C is thatcertain conceptually simple operations are implemented in conceptuallysophisticated ways [Mody91].  Often, C's design follows an underlyinglogic that is only meaningful to the experienced programmer.  To thenovice, that logic is entirely obscure, and the student is given noconceptual framework for understanding the mechanism.As an example, consider the operation of reading an integer from theconsole and storing it in a variable -- an operation which is likely tooccur in conversational programs very early in the introductory course.The ANSI libraries include a function for this purpose, and theexperienced programmer would know to code this operation as follows:          scanf("%d", &value);Unfortunately, the use of scanf is extremely confusing to newprogrammers.  In order to achieve the effect of call-by-reference, scanfpasses a pointer to the variable used to store the input value.Explaining this mechanism in detail requires students to comprehendpointers and a great deal more about parameter passing than one wants tointroduce at the beginning of a course.  As it is, the scanf syntax hasto be presented as a linguistic rule: every variable that appears in ascanf call (except for character arrays, which turn up later andmultiply the confusion) must be preceded with an ampersand.  Thisapproach might be tolerable if C compilers were able to enforce thissyntactic rule.  Given C's structure and semantics, however, thecompiler cannot detect the extremely common error of leaving out theampersand.  The student writes          scanf("%d", value);the compiler doesn't complain, the value entered on the console getswritten into deep space, the program gives the wrong answer (assuming

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -