Next: Texts
Up: Computer Science 270 Survey
Previous: Who Should Take This
If you're taking this course, you are already comfortable with the
notion of writing a program, and you've learned some of the techniques
and data structures most often used in computer programs, especially
Scheme and/or Java programs. But those are only two of literally hundreds of
computer languages, each with its own strengths and weaknesses. A
programmer who approaches every problem thinking about how to solve
it in, say, Java is like a carpenter who uses a hammer on everything, even
when a saw or a screwdriver would be more appropriate. A competent
programmer must be able to select the most appropriate language
for any given problem. Furthermore, a competent programmer must be able
to write idiomatically in each language, i.e, to write in
the style to which that language is suited: don't be like a carpenter who
chooses a screwdriver as the appropriate tool, but still uses
it like a hammer. Finally, a competent programmer must be able to
learn a new language and its idiom quickly.
We'll spend the first half of the semester learning the C++ language.
Java, which most of you learned last semester, was intentionally modelled
after C++, but with a number of simplifications and safety measures, and
with some useful features removed. The syntax will look extremely similar,
and most of the concepts are the same, so all we need to learn is how to
live without the simplifications and safety measures in C++. In brief:
- C++ allows functions and variables that are not associated with any class
(sorta like Scheme functions and variables).
- C++ allows local variables to be allocated automatically on the stack, rather than on the heap
with ``new'' (if you don't know what this means, just wait....)
- C++ allows the explicit use of pointers and references
(in Java, almost everything is a reference, and you seldom need to think about what is and what isn't).
- C++ arrays are less sophisticated than Java arrays, and are not bounds-checked (so you can easily
refer to the 15th, or even the -15th, element of a 10-element array).
- C++ requires you to deallocate any memory that you allocated (Java does this automatically
for you using a ``garbage collection algorithm'').
- C++ strings are just arrays of characters, so they can't do as many tricks as Java Strings
(but there's a standard C++ String class as well).
- A C++ subclass can override a method of its superclass, yet calling the method on an object
of that subclass may still invoke the superclass's method rather than the subclass's method unless
the object is referred to with a pointer.
- In C++, you can redefine the built-in operators like +, -, *, /, <, =, ==, ++, etc. to mean
just about anything you want, depending on the types of their operands.
- A C++ class can declare other specific classes to be its trusted ``friends'',
allowing those other classes to access the internals of this class.
(Or, to put it more lewdly, ``in C++, your friends can play with your private members.'')
- C++ allows you to define methods and classes parameterized by a type. (That sounds weird, but
it turns out really useful, and I wish Java had it.)
- C++ makes it much easier to do simple text I/O.
- There are lots of niggling little syntactic differences to memorize between C++ and Java.
After the midterm exam, we'll spend about a month on the C language, the (much simpler)
ancestor of C++. C, and to a lesser extent C++, is widely used
in connection with the
operating system, which most
of you are studying concurrently in CSC 271.
We'll also discuss how to use a debugger, an immensely valuable
program that helps you see where your C and C++ programs are going wrong and
how to fix them.
After Thanksgiving, we'll switch to a very different language named
Prolog. Prolog was developed in the 1970's for applications in
artificial intelligence, particularly expert systems, and it is still
widely used in that area. If switching between Scheme and Java required
you to ``shift mental gears'', Prolog will require you to shift into reverse,
as most Prolog programs basically say ``I could solve this problem if only
I could first solve those three other problems. I could solve those other problems
if only ...''.
Nonetheless, those of you who miss Scheme will find Prolog somewhat similar.
Prolog requires completely different ways of thinking about
programming: some of the problems you would work hard to solve in C++,
Java, or even Scheme are
trivial in Prolog, while other problems you wouldn't have even thought
of from those mindsets become serious and reasonable questions in Prolog.
Next: Texts
Up: Computer Science 270 Survey
Previous: Who Should Take This
2000-09-05