开发者

Do you have any experience teaching C to undergraduate students with the K&R book? [closed]

开发者 https://www.devze.com 2023-01-13 21:15 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. 开发者_如何学Python
Closed. This question is opinion-based. It is not currently accepting answers. 开发者_如何学Python

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 9 years ago.

Improve this question

Has anyone had any experience in teaching programming in C to undergraduate students, who can be presumed never to have seen an editor before in their lives?

I might soon face that predicament, and was thinking of basing myself on the K&R "The C Programming Language" book. Has anyone had a similar experience? What are your ideas/recommendations? Is C the right language to teach undergraduate engineers as a first language?


K&R is not a book for programming beginners. It assumes that readers are familiar with imperative programming. Pascal or C++ programmers can start C with K&R; Java or C# programmers can with a bit of coaching on not having safeguards such as array bound verifications. But typical absolute beginners will take at least one semester to get anything out of K&R.

K&R has a very good compilation of exercises; don't hesitate to draw from them. You'll still need to provide more simple exercises and break down some exercises into pieces that are easier to chew. But as a course text, you need something with a much gentler progression.

If your undergraduates are anything like mine were, expect the first lab to be about logging in, firing up the editor, typing in a program, compiling the program, understanding the error message, repeat until the program prints “hello”. Prepare an environment that is as easy to use and locked down as possible. Give very detailed instructions (preferably tested on a 5-year old).

I recommend exercise 1 to be about typing in and running a hello world program (source code supplied on paper), exercise 2 to be about changing “hello world” to ”hello everyone”, and exercise 3 to be about typing in a program with a mistake (something simple, like a missing semicolon), attempting to compile the wrong program, and modifying the program until it works. If you have some really bright students, exercise 4 (bonus) can be about typing in and running a supplied quine. Getting your students to read a compiler error message is the most important thing for lab 1.


I've TA'd before.

Generally the less magic you give the students, the better. "It just works" is not an acceptable answer for engineering students. It's comforting, but there's no lasting value in it.

Most of them won't know what a shell or a compiler is, however. C is good in that it doesn't have much magic. I've not found a good intro to programming book yet, K&R can't be worse than the usual drek.

If given the choice, I would teach either Assembly or Scheme as a programming language to comp sci majors(software engineers, computer engineers, etc) in an intro course. For a more general audience, I would teach R.


I've taught rank beginners to program in c using K&R. But as a tutor, rather than in a classroom setting.

I love K&R, but it is very tightly written: you often have to read (and think about) each and every word to get the point. That's OK for experienced programmers (who were the audience for the book as far as I can tell), but in the wider population there are many people who won't sit still for that.

In a tutoring setting you can overcome that. You know where the critical details are hiding and can take the time to make sure the student "gets it" before moving on. That's harder to do in a lecture.

I'd suggest another book.


I, too believe that C should be taught as an Intro course to programming, because it's something in the middle, it doesn't have that much 'magic' in it which is associated with newer high level languages plus it has the low level stuff. Syntax wise too, it will prepare them with Java or C# in the future. But I'll suggest that before teaching them programming, train their logic first during the first 1/4 of the semester by teaching them some problem solving and basic algorithm. Even if they master the syntax, if they don't have good problem solving skills, then they'll have a hard time whatever language they use.


If you're teaching under Windows, this kinda fails. I suggest using a good beginners book, for C and then move on to K&R.

If you're teaching under Linux, I would advice a beginners book as well, there's plenty good books out there, take O'Reilly for instance.

And don't force them into IDEs or editors with a steep learning curve like Vim.

I'll add some good learning books later.


I have experience as a beginner in programming, studying independently (while working full time as a public school teacher). Last year I bought the book "Principles and Practice Using C++". With my PowerBook, it wasn't too difficult at the beginning, but then after a couple of chapters it started getting really hard, and I just dropped it. I have come to realize that book isn't easy to follow as a beginner (working independently).

Then in the fall I bought a netbook and began using Linux for the first time. Early this spring I started going through "The C Programming Language" within a Linux environment. A lot of things (emacs, gcc, gdb ... even how to execute a file, how to change permissions to make it executable, how to navigate simple bash commands), I had to work through trial and error, it was very slow.

I think that if you as an instructor can make those things easy to work through and fill the gaps that Kernighan & Ritchie assume the students have, then it should work. Once yoiu get past that other stuff, as a beginning student it's really nice to have something explained in a very clear and understandable manner. For me, it combines a well-written text with exercises. Definitely though, some of the students will require more support with the problems. Sometimes I spent a week just working on one problem and it was very frustrating.


Is C the right language to teach undergraduate engineers as a first language?

A Brief language comparison.

Basic

DIM A As String = "Hello"
DIM B As String = "World"
DIM C As String = A + " " + B + "!"

C++

string a = "Hello";
string b = "World";
string c = a + " " + b + "!";

C

char a[] = "Hello";
char b[] = "World";
char* c = malloc(strlen(a)+strlen(b) + 3);
strcpy(c,a);
strcat(c, " ");
strcat(c,b);
strcat(c,"!");
/* don't forget to call free(c);  */

Now, which do you think you should be teach to folks who've never seen a text editor?

0

精彩评论

暂无评论...
验证码 换一张
取 消