John Coleman said:
Greetings,
I teach math and computer science (though mostly math)
at a small liberal arts college. Because of our smallness
we don't have a huge course offering. To compensate,
we have a grab-bag "special topics course" where we cover
different topics each semester based on student's and/or
professor's interests.
Next fall I will be running a special topics course with
the title "Modern C Programming". The motivation for the
course is that currently our CS students are exposed to C++,
Java and a smattering of other languages (e.g. Lisp in an
elective AI course) but no C per se. While in principle
they learn some C naturally in the course of learning C++
they really don't learn all that much about things like
pointers, malloc, and the safe handling of C-style strings
and they definitely don't learn anything about C99.
The proposed class is intended to give a serious introduction
to C to students who have a working knowledge of either C++
or Java. This will allow me to blow through the basic syntax
of expressions, loops, etc. in a couple of weeks and to spend
the bulk of the semester on aspects of C which are different
from Java and even C++.
My question is - what would a good text be? My first tentative
choice was King's "C programming: a modern approach", but I have
also been looking at Kochan's book "Programming in C". More
recently I have been toying with the idea of using K&R.
On the one hand that seems on the face of it like a poor choice
for a course called *Modern* C programming. On the other hand -
it *is* a classic and seems to hit the right level of difficulty
(a course for students who already know at least one programming
language). My main question is - does the merits of K&R outweigh
the disadvantages of the lack of coverage of C99? I could of
course supplement K&R by e.g. O'Reilly's "C Pocket Reference"
which covers the C99 material. Where I'm at right now is that
my heart says to go with K&R but my head says go with King
(or Kochan). The bookstore wants a decision on my part sooner
rather than later.
Also - I am open to ideas about projects for the students to work on.
One idea that I had was to concentrate on the Mandelbrot Set.
Towards the beginning of the semester they could have a program
which just prints to the command line e.g. with '*' for points
in the set. Later on they could write it to a portable bit map
text file. Even later they could write it to a .bmp file in which
they have to get the header and the byte-alignment correct.
Finally, I could have them rewrite it in C99 with e.g. the
complex-number type and variable-length arrays so they don't
have to hard-wire in the size of the bitmap. This topic of course
reflects my interest as a mathematician. I have less ideas when
it comes to straight computer-science applications (although
Jacob Navia's idea about a hex-dump utility for pedagogical
purposes caught my eye).
Thanks in advance for any suggestions
-John Coleman
Not really sure about what book might be better. Where are
these students going next? I take it they're cs students
learning (if you have your way
a little math, rather than
math students learning cs. Of course, real cs requires lots
of math, but lots of cs curricula teach future programmers
how to program, not cs per se. I think real cs students
might gravitate more towards k&r; otherwise, maybe not.
But you're the one who's there and knows them and knows
the curriculum and available books. So you're the best
(if not only) one to make the right call.
As for Mandelbrot, that's a nice idea. But have them
construct a memory-resident raster structure, nrowsxncols,
along with a layer of output routines, the first being
your printf, and later maybe bmp, etc. That way the underlying
raster bitmap (or 3 bytemaps if you want color) structure is
flexible for any future purpose. Plus, it teaches them
a little more about structs. A straight printf program
is a dead end vis-a-vis future output option enhancements.
During a little recent downtime between contracts,
I wrote
http://www.forkosh.com/lineart.html based on that idea
(see example=6 and =7 when they happen to scroll by for fractals),
and also based on earlier
http://www.forkosh.com/onedwaveeq.html
which is an exercise trying to use gif animation as a visual
teaching aid (I still haven't figured out how to use it
really well, but am convinced there's a way, if I can find it).
These programs use existing libraries to drive gif creation from
the bytemap raster, and animated gifs using ImageMagick's convert
via a system() call. So once they have a memory-resident raster,
there's really lots of "cute" places they can go from there (e.g.,
besides the gifs, note the postscript output option on lineart).
Plus, using library routines to get to some of those places helps
teach them how to interface their own stuff with canned code,
an important skill.