Bjarne Stroustrup programming language p. Need good package managers and build systems

As promised in the first edition of the book, user requests determined the development of C++. It was guided by the experience of a wide range of users working in different areas programming. In the six years separating us from the first edition of the C++ description, the number of users has increased hundreds of times. Over the years, many lessons have been learned, various programming techniques have been proposed and confirmed by practice. Some of them will be discussed below.

The language extensions made over these six years were primarily aimed at increasing the expressiveness of C++ as a data abstraction language and object-oriented programming in general, and as a means for creating high-quality libraries with custom data types in

in particular. Library High Quality We consider a library that allows the user to define concepts using classes that combine convenience, efficiency, and reliability. Robustness means that a class provides a type-protected interface between users of the library and its developers. Efficiency means that using classes does not incur large memory or time overheads compared to manual C programs.

This book is a complete description of the C++ language. Chapters 1 to 10 are a textbook introduction to the language. Chapters 11 to 13 discuss design and development issues software. The book ends reference guide in C++ language. Naturally, all extensions of the language and ways of using them that have appeared since the publication of the first edition are part of the presentation. These include refined rules for name overload resolution, memory management and access controls, type-safe binding, static and persistent member functions, abstract classes, multiple inheritance, type templates, and exception handling.

C++ is a programming language general purpose. Its natural area of ​​application is system Programming, understood in in a broad sense this word. In addition, C++ has been successfully used in many application areas that go far beyond this scope. Implementations of C++ are now available on all machines, from the humblest microcomputers to the largest supercomputers, and for almost everyone operating systems. Therefore, the book provides only a description of the language itself, without explaining the features of specific implementations, programming environments or libraries.

The reader will find in the book many examples with classes that, despite their undoubted usefulness, can be considered toy. This style of presentation allows you to better highlight the main concepts and useful techniques, whereas in real, complete programs they would be hidden by a lot of detail. For most of the classes proposed here, such as related lists, arrays, character strings, matrices, graphics classes, associative arrays etc., - versions are given “with a 100% guarantee” of reliability and correctness, obtained on the basis of classes from a wide variety of commercial and non-commercial programs. Many of the "industrial" classes and libraries came out as direct or indirect descendants of the toy classes given here as examples.

In this edition of the book, compared to the first, more attention is paid to the task of learning. At the same time, the level of presentation in equally takes into account experienced programmers, without in any way detracting from their knowledge and professionalism. Discussion of design issues is accompanied by a broader presentation of material that goes beyond descriptions of language structures and ways of using them. This edition provides more technical detail and increased rigor. This especially applies to the reference manual, which incorporates many years of experience in this area. The idea was to create a book with enough high level presentation that would serve programmers as more than just a book to read. So, here is a book describing the C++ language, its basic principles and programming methods. We hope it brings you joy.

The CppCon 2017 conference is currently underway, and videos from there have already begun to appear on their YouTube channel. And I thought, why not try to take notes from interesting lectures. Of course, I'm not really sure how long it will last me, it depends on how much you like it.


This is the first introductory video. It’s not that interesting for me, but I couldn’t miss it either, it’s Stroustrup. Next, the text on his behalf. The titles are taken from the slides.



Disclaimer: all further text is a fairly brief retelling, which is the result of the work of my perception, and what I considered “water” and ignored could be important for you. Sometimes the speech was like this: “(important thought 1)(minute of water)(important thought 2).” These two thoughts smoothly flowed into each other, and I got quite sharp jumps. I smoothed it out where possible, but I found it inappropriate to completely comb the text; it would take a lot of time.

Introduction

When I was asked to speak at the opening of the conference, I wondered what I could tell you that is important to you and that you haven’t heard a million times. And I decided to talk about learning the C++ language.

We are all teachers and we are all students

Let's ask ourselves who we teach, what, why and how. We need to do this better. I'm not criticizing anyone in particular, but I feel like we need to do better. Not all of us are teachers, but nevertheless, cases constantly arise when we are engaged in teaching. For example, we tell colleagues about the latest features or give advice. We communicate on StackOverflow, Reddit, blog, etc. But you have to give good advice. Advice that moves the world forward.


One thing that really bothers me is that people often have very strange ideas about what C++ is. I will return to this problem a little later.


When you teach, think about what you want to achieve. And start from there. Do not start from “what we have already done” and “what is easier to start with”, and if you are a teacher, then from “what is easier to check”.

Programming training

No need to focus on language features. For example, you have seen examples that explain the problem of casting signed short to unsigned int [ talks about teaching the language in general, not about the specifics of C++]. This is not interesting and can be seen in the debugger or read in the manual. Teach in such a way that such a problem does not appear.


Don't try to teach everything, you won't be able to. Choose your language subset carefully.


One of the problems encountered in learning C++ is that the language is learned on its own, separately from the libraries. Vector on page 697, sort after 100 pages. This teaches that stl is boring, complicated crap. And at the same time: your own Linked List or Hash table is cool, cooler than stl.

Don't be too smart


People who want and demand “the very latest” often do not know the basics. Review the basics.


Keep it simple. Don't rush into the most complex and sophisticated. Don't use the most advanced algorithm you can find. I wouldn't choose bubble sort, but also would not choose "full general algorithm for everything." Offer the simplest example that illustrates a technique or feature.


Focus on general cases. Be rational. Don’t tell students, “Do only this, it’s the right thing, it builds character. And you can get an A if you answer this way.” It is necessary to explain why it is necessary to follow the rules, to give students good ideals, ideas, techniques.


Of course, when teaching, it is very tempting to stand in front of colleagues, a group of people and show with all your appearance: “Look, this complicated thing which you didn't understand. That means I'm smart." This is not very good learning.

Programming training

If you study only the language itself, then once you get into reality you can simply “drown”.
Use different tools. Not only a compiler and a tutorial, but also IDEs, debuggers, version control systems, profilers, unit testing, static analyzers, online compilers. The tools must be modern (sometimes I get questions about Turbo C++ 4.0:()


You need to study the principles and practice them. Use graphics, networking, internet, Raspberry Pi, robotics, etc. This is obvious to you, but not obvious to universities. Don't say it's easy and fast. And remember that no one can do everything.

Language is more than just syntax

How often do we teach? Explaining the language plus a little standard library. Without any graphics user interface, web, Email, databases... And many students believe that C++ is a boring, useless language. But this is not true, because such things as browsers, DBMS, CAD and others are written in C++. Before the lecture, spend 5 minutes on the practical application.

We must do better

For us in the C++ community, it's very important to make it easy to get started, to be able to use it "right now."

How are users in different industries divided into groups? Let's give an example with a photograph. The result depends on the equipment and the user. Personally, I'm new to photography. Most of the features of a professional camera would be useless to me. It weighs a lot and is expensive. There are many accessories for her that you can drown in. But with its help you can do superb photos, if you spend a lot of time learning. Likewise, there are many people who cannot use various language features and libraries.

Mass market

On the other hand, we have devices that can be used immediately. This device is cheap, simple, and “cute.” Forgiving of mistakes, does not require much effort to master. Is a "thing in itself". There are few, if any, extensions or additions. There are no interchangeable parts.


One day while teaching, I needed my students to have a GUI library installed. It turned out that installing the same library on student Macs, Linux, and Windows is very painful.

Language needs a "system"

Every camera manufacturer offers a "system" that allows you to gradually upgrade your equipment and move to next level as you learn.


Not necessary for a beginner professional camera with all the bells and whistles. In this case, he will have difficulties and the result will probably be worse than if he had used a soapbox. Therefore, no one solution will be suitable for everyone.

What should the main distributions be?

The language must be presented in three distributions. For beginners, amateurs and professionals.

Modules will help

import bundle.entry_level; //For beginners import bundle.enthusiast_level; //For advanced import bundle.professional_level; //For professionals

Extensions (which are not included in the base):


import graphics.2d; import graphics.3d; import professional.graphics.3d; import physlib.linear_algebra; import boost.XML; import 3rd_party.image_filtering;

Need good package managers and build systems

How can a student install a library in the second week after the start of school? GUI and working with databases? Different libraries and systems are built differently. Different libraries may not be compatible. A dozen incompatible package managers are not a solution. Need to make it simple to implement simple tasks


> download gui_xyz > install gui_xyz

Or in an equivalent way, for example in the IDE:


import gui_xyz; //in code

Modern C++

My vision of modern C++ (as usual):

  • Static type safety, well defined interfaces.
  • Resource security (constructors/destructors, RAII).
  • Abstractions without overhead.
  • Encapsulation, invariants.
  • Generalized programming, templates.
  • Simplicity for most developers, complexity hidden in libraries.

Change is hard

Modern C++ is not C, Java, C++98, or the language you programmed in 10 years ago. Inertia is the enemy good code. Teachers justifying non-use modern standards, they say that “we don’t do that”, “this cannot be inserted into my curriculum", "maybe in 5 years." Students have more confidence in the Internet than in teachers. Some believe that they are smarter than teachers, and sometimes they are right. Every year I have consistently had students in my course who are absolutely convinced that they smarter than me in programming. In these particular cases, I am reasonably sure that they are wrong [ laughter in the hall].

What is modern C++?

  • Best practices using the current ISO C++ standard
  • The quest for type- and resource-safe code

To implement this, the C++ Core Guidelines project was opened 2 years ago. He gives specific answers to questions. It has many many participants, including Microsoft and Red Hat.

Code examples

Don't separate examples from explanation. 5 pages of bare theory is a waste. Give examples and explanations for them. People don't generalize without explanation. They simply copy-paste and invent an interpretation themselves, sometimes a very strange one.

Code improvement

Always explain your reasons. For example:


//1 int max = v.size(); for(int i = 0; i< max; ++i) //2 for (auto x: v)

Why is 2 better than 1? Example 2 clearly shows the intent that v can be changed without rewriting the loop, and is less error prone. It should be noted that 1 provides more flexible options. But goto is even more versatile, and that's why we avoid it.

  • I.4: Make interfaces precise and strongly typed

[I.4 means item from Core Guidelines]


void blink_led1(int time_to_blink) //Bad - unclear type void blink_led2(milliseconds time_to_blink) //Good void use() ( blink_led2(1500); //Error: what unit of measurement? blink_led2(1500ms); blink_led2(1500s); / /Error: incorrect unit of measurement)

[Here milliseconds is some simple type not from the Chrono library, so the last line results in an error. The text below describes a generalization of the type for the unit of measurement taken from Chrono. If interested, you can read my work in this library]


template void blink_led(duration time_to_blink) ( auto ms_to_blink = duration_cast (time_to_blink); ) void use() ( blink_led(2s); blink_led(1500ms); )
  • ES.20: Always initialize the object
  • F.21: To return multiple values ​​from functions, prefer to use tuple, structure (or structured binding).
Error_code err; //uninitialized: potential problem //... Channel ch = Channel::open(s, &err); //out-parameter: potential problem if(err) ( ... ) Better: auto = Channel::open(s) //structured binding if(err) ...

Should this code use returning two parameters?

  • E.1: Have a bug-catching strategy early in development
  • E.2: Throw an exception to notify that a function cannot perform a task
  • E.3: Use exceptions only to report errors
auto ch = Channel::open(s);

Better? Yes, if unsuccessful opening was provided for in the program.

Code Improvement: Don't be too smart

The word "smart" in the context of using C++ is a dirty word. Find a bug:


istream& init_io() ( if(argc > 1) return *new istream ( argv, "r" ); else return cin; )
  • P.8: Avoid leakage
  • R.11: Avoid calling new and delete directly
  • R.4: Raw reference (T&) must be non-owned

Name: C++ programming language.

In this edition, Bjarne Stroustrup presents C++ in a form that is even more accessible to beginners. At the same time, it includes information and techniques that can be useful even for C++ experts.


Here is a special edition of the most widely read book on C++ containing the most reliable information. The book contains Full description the C++ language, its standard library (STL) and key program development techniques. Based on the ANSI/ISO standard, the book is the source of the most up-to-date and complete description of all features of the C++ language, including standard library components, including:

  • abstract classes as interfaces;
  • class hierarchy in object-oriented programming;
  • templates as the basis for type-safe generic programming;
  • handling exceptions resulting from common errors;
  • using namespaces to achieve modularity in large projects
  • Runtime type inference (RTTI) for loosely coupled systems;
  • a subset of the C++ language for compatibility with C and work at the system level;
  • standard containers and algorithms;
  • standard strings, I/O streams, and numeric data;
  • compatibility with C, localization (internationalization) and security in exception handling.
Brief contents
Author's preface to the third Russian edition.25
From the editors of the Russian edition.27
Preface.29
Preface to the second edition.31
Preface to the first edition.33
INTRODUCTION.35
1. Address to the reader.37
2. Overview of C++.57
3. Overview of the standard library.81
Part I Fixed assets. 105
4. Types and declarations. 107
5. Pointers, arrays and structures.127
6. Expressions and instructions.147
7. Functions.185
8. Namespaces and exceptions.209
9. Source files and programs.241
Part II. Abstraction mechanisms. 267
10. Classes.269
11. Operator overloading.309
12. Derived classes.349
13. Templates.377
14. Exception handling.407
15. Class hierarchies.443
Part III. Standard Library. 483
16. Library organization and containers.485
17. Standard containers.519
18. Algorithms and function objects.569
19. Iterators and memory allocators.613
20. Lines.645
21. Streams.671
22. Numerical methods.725
Part IV. Designing using C++. 757
23. Development and design.759
24. Design and programming.797
25. Class roles.841
Applications and index.869
Appendix A. Grammar.871
Appendix B. Compatibility.891
Appendix B. Technical details.903
Appendix D. Localization.947
Appendix E: Exception Safety
and standard library.1017
Subject index.1055

Free download e-book V convenient format, watch and read:
Download the book The C++ Programming Language - Bjarne Stroustrup. - fileskachat.com, fast and free download.

Download djvu
You can buy this book below best price at a discount with delivery throughout Russia.



The book was written by Bjarne Stroustrup, the author of the C++ programming language, and is a canonical presentation of the capabilities of this language. Besides detailed description language itself, on the pages of the book you will find proven approaches to solving a variety of design and programming problems. Numerous examples demonstrate how good style programming on a C-compatible C++ core, and a modern object-oriented approach to creating software products.
The book is addressed to programmers who use C++ in their daily work. It will also be useful to teachers, students and anyone who wants to get a first-hand account of the language.

Using the C++ language gives me more and more pleasure. Over the years, C++ design and programming support tools have improved dramatically, and many useful and convenient techniques for using them have been proposed. But we're talking about not just about pleasure. Practicing programmers have achieved significant improvements in productivity, support, flexibility and quality in projects of any level of complexity and scale. So far, C++ has lived up to most of my hopes for it, and it has also succeeded in solving problems I never imagined possible.

Only a third of the information from the first edition migrated to the second edition of this book. The third edition has been revised even more intensively. It has something that will be useful to the most experienced C++ programmers. At the same time, it is more accessible to beginners than previous editions of this book. This was made possible thanks to the explosive growth practical use C++ and the experience resulting from this practice.

The Standard Library allows you to reimagine the core concepts of the C++ language. Like previous editions, this book describes the C++ language independent of specific implementations. As in previous editions, all designs and concepts are presented from the bottom up, so that by the time they are used, they are already presented and described in detail. Note that a well-designed library can be used before readers can learn it. internal organization. In addition, the standard library itself is a valuable source of examples.
programming and design methods.

Only a perfect understanding of the ideas behind the means of language leads to true mastery. Supplemented with implementation details, the information in this book is sufficient to carry out real projects of significant scale.

C++ Language Overview

What is C++? - programming paradigms - procedural programming- modularity - separate compilation - exception handling -
data abstraction - user defined types - specific types- abstract types - virtual functions- object-oriented
programming - generalized programming - containers - algorithms - language and programming - tips.
This chapter explains what all this means, but without introducing the smallest details language definitions. Given general review C++ language and key ideas its use, not burdened detailed information, necessary to start real practical programming in C++.

If the perception of certain parts of this chapter seems difficult to you, do not pay attention and just move on. In subsequent chapters everything is explained in detail. It’s not a bad idea, however, to return to what you missed again later. Detailed knowledge of all linguistic properties and constructions, even their exhaustive knowledge, does not replace or cancel the need common understanding the role and place of this programming language, as well as familiarity with the fundamental ideas and techniques of its use.

Programming Paradigms

Object-oriented programming is a programming technique, one might say, a paradigm, for writing “good” programs for a certain class of problems. The term "object-oriented programming language" should primarily mean a language that supports the object-oriented programming style well.

Here two situations must be clearly distinguished. We say that a language supports a style of programming if it provides special
means that allow this style to be easily (conveniently, reliably, efficiently) implemented in practice. If a language requires exceptional effort and enormous experience to implement some programming technique, then we say that it only allows for the possibility of its application. For example, on Fortran language 77 you can write structured programs, and in C you can write programs in an object-oriented style, but all this requires inappropriately large efforts, since these languages ​​​​do not directly support these programming styles.

Object-oriented programming

Data abstraction is extremely important to good design and will be a major focus throughout this book.
However, user-defined types on their own are not flexible enough to meet all our needs. In this section, first
demonstrates the problem associated with simple custom type, and then shows how to overcome it using class hierarchies.

Standard Library Overview

No significant program is written solely in bare-bones programming language constructs. First, support libraries are developed. They then become the basis for further work.

As a continuation of Chapter 2, here is given short review basic library tools, giving an idea of ​​what can ultimately be created using
C++ language and its standard library. The following are being considered useful types standard libraries like string, vector, list and tar, as well as the most
common options for their use. This allows me to give more meaningful examples and more interesting exercises in later chapters of the book. As in Chapter 2, it is also strongly recommended that you do not become distracted or discouraged by not fully understanding the details of the material presented. The purpose of this chapter is to give you a feel for what you'll encounter as you continue to learn, and to help you learn the simplest ways to use the library's most useful tools. A detailed introduction to the standard library is given in...

Switch menu

Bjarne Stroustrup "The C++ Programming Language"

Now let's look at the book programming language C++, which really deserves the greatest attention and respect. And there are reasons for this, which we will consider further.

This book " ", performed by the legendary author B. Stroustrup, gives a complete description of the language, its key concepts and basic programming techniques, which is very important, first of all, of course, for a beginner. This is a complete manual written by the creator of the language (a brief introduction to the author below) that covers all the features of the C++ programming language, including exception handling, type templates (parameterized data types), and multiple inheritance. The book is divided into three parts: the first ten chapters are a textbook that serves as an introduction to the language, including a subset of C itself, and the next three chapters discuss designing and creating software using C++. The book concludes with a complete reference guide to the C++ language. The main advantages of this book:

  • a complete textbook and guide to the language.
  • full coverage of language features aimed at abstract data types and object-oriented programming.
  • discussion of programming and technical issues, arising in the process of designing and creating large software systems.
  • description of ways to build high-class libraries.
  • implementation examples key types user-defined data such as graphic objects, associative arrays and input/output streams.

This book, of course, will a good helper not only for a beginner, but also for an experienced programmer who decides to use C++ for non-trivial tasks. This book can be considered key in any collection of books on C++. I highly recommend starting to learn programming with this book, because... I once started with it myself. And now a little about the author of the book.

Bjarne Stroustrup is the developer of the C++ language and the creator of the first translator. I think that from now on many of you have already understood why exactly this book deserves the most attention. Bjarne Stroustrup is an employee of the AT&T Bell Laboratories Research Computing Center in Murray Hill (New Jersey, USA). He received a master's degree in mathematics and computer engineering from the University of Aarus (Denmark), and a doctorate in computer technology at Cambridge University (England). He specializes in the field distributed systems, operating systems, modeling and programming. Together with M. A. Ellis, Bjarne Stroustrup is the author complete guide for the C++ language - "C++ Guide with Notes".

Also very important point is that at the end of each chapter there are exercises for independent implementation. Of course, you cannot ignore them under any circumstances, because... it is theory, consolidated by practice, that is your golden fleece. It was not for nothing that it was said that " The best way learning to program is programming!"