For this class,
you will need to program all of your projects and assignments in C++.
This is not a
statement about the language, or the appropriateness to doing graphics. It's
more a statement about what is a convenient environment for us to teach graphics
in. Just as we chose to give lectures in English, despite the fact that other
languages could have been used, we chose to give programming assignments and
projects in C++. In fact, most "real world" graphics programming is in C++. So
learning C++ is a useful skill if you want to go on and do more graphics. Plus,
C++ is a useful skill in general.
projects in C++ might be a problem if your previous programming experience was
in a different programming language. This is increasingly the case as we move
our introductory programming courses to Java.
First, it is
definitely possible to do well in CS559 if
it is your first exposure to C++. Many students (OK, some students) did very
well. In fact, knowledge of C++ beforehand is not a good predictor of how well
students do in 559.
learning C++ at the same time that you are learning the graphics material will
be a challenge. Plan to devote some extra time to it. While many students who
did not C++ prior to taking 559, all of those who were successful put in lots of
extra time and effort. While it is possible for students without C++ experience
to do well, it is not easy.
To be honest,
the biggest problem for most students transcends the language: its the ability
to build and debug non-trivial programs. For many students, 559 is the first
time that they have to write a program that is too big to wrap their head
around. Learning to write complicated programs is harder than picking up C++ if
you already know Java. So, you might be better off if you've written lots of big
programs in Java than if your programming experience is limited to short C++
If you really
don't want to learn C++, we will may allow students to use Java in the future
(probably not this year).
1. C++ vs. 559
Learning C++ is not part of 559.
We will not test you on knowing C++. We will not expect you to know any fancy
C++ features in order to use our example code.
We will help
you with C++ programming - to a point. We will help you enough that you can do
the projects. We cannot teach you to program. We will not help you use complex
2. Some Resources for Learning C++
Since a lot of people will ask...
offers a "course" (CS368) to teach student C++
after they have learned Java. It is a self-paced web tutorial. You can work
through it without registering (and getting credit). You can access the
tutorials from http://www.cs.wisc.edu/~hasti/cs368/.
2.1 Books to Learn C++ From:
Essential C++ by
Stanley Lippman Recommended
This is a really good book for getting started with C++. Its a thin little
book that tells you what you need to know, without going crazy. Its more
about the language and how to program in it than it is about a philosophy of
how to organize your program (which many books seem to do).
(Buy at Amazon) (Publisher
The C++ Primer by
Stanley Lippman, Josee Lajoie and Barbara Moo Recommended
(Buy at Amazon) (Publisher
learned C++ (1989), I went to the bookstore and there were 2 books. So when
I tell you the book that I used to learn C++, you have to take the
recommendation with a grain of salt.
The book I
learned from (and is probably my favorite C++ book) is C++
Primer.(published by Addison Wesley). With each version, it seems to
double in size (this time it added a second author). When I got the first
version it was a compact little volume. To be honest, I think it gets worse
as it grows bigger.
4th edition, the "getting bigger" has gotten to a crisis - there's so much
in here, and fancy stuff is mixed in with the basics. Part of this is that
C++ (the language) has gotten so big and complicated that there really is
900 pages of stuff to talk about.
author laments the fact that a comprehensive book on C++ is unwieldy, which
is why he wrote Essential C++
Two other books
that have been recommended to me are Wang's "Standard C++ with Object Oriented
Programming" and Deitel & Deitel's "C++, How to Program." I have not used either
of these, so no promises. Another well known book is Stroustrap's "The C++
Programming Language." This book was first (Stroustrap is the "inventor" of
C++). Like Lippman (who was 2nd) this book doubles in size with each version. .
One thing that
I dislike in C++ books is when they spend more time telling you their
programming philosophy, rather than the constructs of the language. There seems
to be no avoiding this.
with C++ books is that they like to show off how you can use the complicated
features of the language to do tricky things. There are whole books on these
kinds of things (that are probably better at it). My opinion is that you are
best off learning the basics first, and then moving on to fancier things later.
2.2 Web Tutorials
Aside from CS368,
there are a bunch out there. In fact, if you type in some C++ topic to your
favorite search engine, you will find something. (I did this the other night
when I couldn't remember how Templates worked). While you might wade through a
pile of junk (this is the web), you might find something good.
There are lots of "advanced" C++
(and programming in general) books out there. Once you learn the basics, reading
an advanced book really can teach you some new tricks and help you become a
better programmer. However, sometimes, these books get so caught up in debatable
tricks or picky details that they aren't that valuable.
Some books that
I would recommend that can help you become a better programmer:
C++ series by Scott Meyers
(buy at Amazon) (publisher's
agree with everything he tells you to do. However, in all cases, he give
good arguments. Its worthwhile to read his tips just to learn how to think
about the issues. Whether you agree with him or not. The whole series is
pretty good - the first book is probably the best place to start though.
C++ Coding Standards: 101
Rules, Guidelines, and Best Practices (C++ In-Depth Series) by
Sutter and Alexandrescu
(buy at Amazon) (publisher's
is full of useful tips and tricks as to how to use (or not to use) C++
effectively. Most of the tips in this book are good, and always well argued.
You may not want to use all of them, but its a good thing to browse to get
ideas on how to be a better C++ programmer.
4. Some Hints
This is based not only on my own
experience, but on my experience teaching CS367 back
when it was taught in C++, and in helping 559 students write their first
- Think before you code. That might sound obvious, but its amazing how often
people do this. It's really the key to doing anything non-trivial.
- Avoid using fancy features of the language - until you are really sure
that you need them. Templates, exceptions, and operator overloading are
complicated things to understand, and very difficult to use productively. Most
times when people make use of them, they are not helping themselves out.
- Use the "easy" parts of the STL, in particular vector.
- Read other people's code. Reading code is an important skill - that is
amazingly un-taught in the CS curriculum. Look for good code, and read it -
see how the author makes use of C++ features (or doesn't as the case may be).
The example code for 559, and the source code to FlTk are
good things to look at.
- Learn to use the debugger. "Print Statement Debugging" is still a useful
tool, but often its not the most effective one for squashing your bugs.
- If its available, make use of a memory leak/memory bug finder. In general,
a memory bug is a sign of a design flaw. You should squish these bugs early
because they only become harder to track down.
- Have a look at one of these "fancy" C++ books. You may not want to use all
of their complicated tricks, but they will get you thinking of how the
language works and can be used. See the list of
advanced C++ books above.
- Break down the problem into stages. Don't write 1000 lines of code and
then test it. Build a little piece, test it, and then add another piece to it,
test it, ... You will have to design your solution to be built this way.
Design top-down, but debug bottom-up.
- Try to understand what your program is doing before debugging. The "make
random changes until it work" paradigm really doesn't work as your program
gets bigger. Understand each piece individually, and then how the pieces fit
together. Design top-down, but debug bottom-up.
- Think in an object oriented way. Just because you use C++, or even use the
OO features in C++, you can still not be doing Object-Oriented Programming.
Object-Oriented is a way of thinking. Try to encapsulate functionality when
possible. This helps break big problems into lots of smaller ones.
- Think before you code. (yes, its worth saying again).