C++
is a productivity enhancement tool. Why else would you make the effort (and it
is an effort, regardless of how easy we attempt to make the transition)
to
switch from some language that you already know and are productive with to a
new language where you’re going to be
less
productive for a while, until you get the hang of it? It’s because
you’ve become convinced that you’re going to get big gains by using
this new tool.
Productivity,
in computer programming terms, means that fewer people can make much more
complex and impressive programs in less time. There are certainly other issues
when it comes to choosing a language, like efficiency (does the nature of the
language cause slowdown and code bloat?), safety (does the language help you
ensure that your program will always do what you plan, and handle errors
gracefully?), and maintenance (does the language help you create code that is
easy to understand, modify and extend?). These are certainly important factors
that will be examined in this book.
But
raw productivity means a program that formerly took three of you a week to
write now takes one of you a day or two. This touches several levels of
economics. You’re happy because you get the rush of power that comes from
building something, your client (or boss) is happy because products are
produced faster and with fewer people, and the customers are happy because they
get products more cheaply. The only way to get massive increases in
productivity is to leverage off other people’s code. That is, to use
libraries.
A
library
is simply a bunch of code that someone else has written and packaged together.
Often, the most minimal package is a file with an extension like
lib
and one or more header files to tell your compiler what’s in the library.
The linker knows how to search through the library file and extract the
appropriate compiled code. But that’s only one way to deliver a library.
On platforms that span many architectures, like Linux/Unix, often the only
sensible way to deliver a library is with source code, so it can be
reconfigured and recompiled on the new target.
Thus,
libraries are probably the most important way to improve productivity, and one
of the primary design goals of C++ is to make library use easier. This implies
that there’s something hard about using libraries in C. Understanding
this factor will give you a first insight into the design of C++, and thus
insight into how to use it.