Learning Standard C++ / PDF



Learning Standard C++ / PDF
Learning Standard C++ / PDF







Sample of the pdf document 








1 Introduction

We want our programs to be easy to write, correct, maintainable, and acceptably efficient. It follows that
we ought to use C++ – and any other programming language – in ways that most closely approximate this
ideal. It is my conjecture that C++ community has yet to internalize the facilities offered by Standard C++
so that major improvements relative to the ideal can be obtained from reconsidering our style of C++ use.
This paper focuses on the styles of programming that the facilities offered by Standard C++ support – not
the facilities themselves.

The key to major improvements is a reduction of the size and complexity of the code we write through
the use of libraries. Below, I demonstrate and quantify these reductions for a couple of simple examples
such as might be part of a introductory C++ course.

By reducing size and complexity, we reduce development time, ease maintenance, and decrease the cost
of testing. Importantly, we also simplify the task of learning C++. For toy programs and for students who
program only to get a good grade in a nonessential course, this simplification would be sufficient. However,
for professional programmers efficiency is a major issue. Only if efficiency isn’t sacrificed can we
expect our programming styles to scale to be usable in systems dealing with the data volumes and real-time
requirements regularly encountered by modern services and businesses. Consequently, I present measurements that demonstrate that the reduction in complexity can be obtained without loss of efficiency.
Finally, I discuss the implications of this view on approaches to learning and teaching C++


2 Complexity

Consider a fairly typical second exercise in using a programming language:
w r i t e a p r o m p t "P l e a s e e n t e r y o u r f i r s t n a m e "
r e a d t h e n a m e
w r i t e o u t "H e l l o "

In Standard C++, the obvious solution is:

#i n c l u d e // get standard I/O facilities
#i n c l u d e // get standard string facilities

i n t m a i n ()
{
u s i n g n a m e s p a c e s t d ; // gain access to standard library
c o u t << "P l e a s e e n t e r y o u r f i r s t n a m e :\ n ";
s t r i n g n a m e ;
c i n >> n a m e ;
c o u t << "H e l l o " << n a m e << ´\ n ´;
}


For a real novice, we need to explain the ‘‘scaffolding:’’ What is m a i n ()? What does #i n c l u d e mean?
What does u s i n g do? In addition, we need to understand all the ‘‘small’’ conventions, such as what \ n
does, where semicolons are needed, etc.

However, the main part of the program is conceptually simple and differs only notationally from the
problem statement. We have to learn the notation, but doing so is relatively simple: s t r i n g is a string, c o u t is output, << is the operator we use write to output, etc.

To compare, consider a traditional C-style solution†:.........




 Click here for  Download PDF / FREE

Learning Standard C++ / PDF




1 commentaire: