ICS 45C Spring 2022
Notes and Examples: Course Introduction


Course background and goals

This course introduces you to programming in a language called C++, with the assumption that you're already familiar with at least one programming language, at a level roughly equivalent to what you might get in our first-year computer science sequence (ICS 31, 32, and 33). If you did take our first-year sequence in recent years, you will have learned a fair amount about programming in Python; if you've taken your earlier coursework elsewhere, you may have learned any of a number of different programming languages. Ultimately, what's important here isn't which language or languages you know already; what's important is that you've achieved at least some depth in any one language already, meaning that you have successfully written programs of more than just a trivial size (i.e., hundreds of lines long, as opposed to tens), that you understand how to break larger problems apart into smaller ones and implement solutions to the smaller ones separately, that you have written programs using a variety of that language's features, that you know how to distinguish between appropriate and inappropriate times to use those features, and that you've developed some ability to reason about a program, so you can diagnose a problem and fix it in a carefully-thought-out way when it doesn't do what you expected. For all the praise and criticism given to individual programming languages, it's important to realize that you can write good or bad programs in just about any language. If you've learned techniques for writing good programs in any language, you'll be prepared for this course, no matter what language you learned previously.

C++ is a giant programming language with a rich history tracing back to the 1970s. It has evolved substantially over the decades, which means that it is full of complexities (large and small), and often offers more than one way to solve the same problem. Techniques and approaches have become popular and then fallen out of favor, with newer ones replacing them as the C++ community gains experience and discovers even better ways to organize their programs. Because of the size and complexity of C++, it will not be my goal to teach the language in its entirety — something I wouldn't be able to do in a full academic year, much less the one quarter that we have. Instead, our goal is to learn about what I think are the most important ideas that set programming in C++ apart from work you may have done in other languages, and the language features that let you gain experience with them, with an eye toward the things that make C++ useful for real-world programming and that are likeliest to expose you to new horizons that you may not have seen in the languages you've worked with in the past.

It's entirely possible that you'll only have ever learned one language in the past, which makes this course doubly important: This may well be your first experience learning a programming language when you already know one, which is a surprisingly important thing to be able to do, and something I still find myself both needing and wanting to do periodically, no matter how much experience I have.


Learning a second programming language

As we dive into C++ this quarter, you'll quickly observe that some parts of C++ bear a lot of similarity to the language you already know, while others are wildly different. This is a blessing and a curse, as it turns out. Seeing things that are familiar may make you — subconsciously or purposefully — gravitate toward the parts that are familiar and away from the parts that are new. However, it's vital to catch yourself when you're doing that and think more carefully; when you learn any programming language, it's vital to understand the ideas, idioms, and tools provided by that language. Just as you can't effectively speak or write a natural language like French simply by translating individual words from another like English, you similarly can't translate a Python program line-for-line into a good C++ program. You might be able to barely communicate with someone by translating individual words, and you might be able to barely write a working C++ program by translating it directly from Python, but you'll have written a much better C++ program if you approach it the way a C++ programmer would. You have to embrace what makes the language you're learning great and, in so doing, you might discover new techniques that you can bring back to the languages you already know.


Learning C++ as a second programming language

Learning C++ is very likely to be a big departure from what you're accustomed to. Compared to any other commonly-used programming language in the world, C++ is bigger, more complex, more nuanced, and more expressive. It requires more attention to the underlying implementation details, while also providing you more control over those details than you might be used to — to use it effectively means you have to know more about what's going on "under the hood." There are more knobs to turn, which means more ways to control how your program runs. But, on the other hand, there are more things to understand, more things you have to consider and control yourself, more ways to screw up, more care that you must take in designing your program to account for the additional complexity, and more difficulty in debugging when things go wrong (since a wider range of things can go wrong).

The payoff in learning about C++ at this stage of your development, from my perspective, is at least threefold:

In other words, learning C++ as a second programming language will make you a better programmer in any language, even if you never use C++ again.


Some historical perspective and the main design goals of C++

While learning any new language, it's important that you understand its main design goals: What was it intended to be used for, and how was it intended to be used? That's not to say that you can't sometimes find novel new uses for an existing language, but it really helps to understand why certain decisions were made, and sometimes even what alternatives were considered and rejected (and why). This will help you to develop the ability to "sense" how a language feature is supposed to work when you first encounter it, or when you use it in a new way.

C++ has a long history, dating back to the late 1970s, when work on designing and implementing what became C++ was begun by Bjarne Stroustrup. C++ was conceived as an improvement on an already-existing language called C, with the very general goal — one which, at a fundamental level, hasn't changed very much in the years since — to enable people to write programs that use the available computing resources as efficiently as possible (and no less efficiently than C), but with a better set of tools built into the language to enable the programs to be written in a clearer way: an improved type system, better checking at compile-time for type-related (and other) issues, and improved facilities for data abstraction, object-oriented programming, and generic programming.

In brief, some of the key design goals of C++ are:

Bearing this perspective in mind will make it easier to understand what lies ahead. Many times, when you find yourself wondering "Why was it designed this way?", one or more of these design goals will be the answer.

(If the philosophy of programming language design — understanding why languages are designed the way they are — is something you find interesting, check out a book titled The Design and Evolution of C++ by Bjarne Stroustrup. You might find that it makes more sense at the end of this quarter, since it assumes a certain amount of background in C++. But it's a fascinating read.)


Course organization and logistics

This course web site describes the logistical details of how this course is going to be run. Particularly, be sure that you read through the Course Reference, the front page of the Project Guide, and the early part of the Project #0 write-up, so you will know how this course operates, and how you'll be doing and submitting your work.