C++, fast system language and applications

The C language is provided with objects to simplify presentation of objects to be processed and code reuse. This made it possible to turn this system language, created in 1972, into a higher-level language - C++.
Over time, other features were added, such as patterns, tuples, competition.

C++ was created in 1981 by Bjarne Strutstrup, who discovered the orientation of the object in Simula 67 and wanted to add it to the C language, while remaining compatible with it and thereby maintaining its advantages, in particular, portability between systems .

Langage de programmation C++ pour systèmes

Its construction obeys a set of rules:

The first ISO standard for the C++ language dates back to 1998, it is C++ 98. Its successor was a new version in 2011 - C++ 11. With this version, which brings nothing when readability and modernity, language is cemented in its role as a systemic tool from which it has been distracted for a while.

The increasing complexity of C++ with versions 11, 14, etc. has been criticized by Donald Knuth and Edsger Dijkstra, among others. The designer himself is not satisfied with the functions added during the time to the syntax of the language, and he somehow hints at the history of "Vasa" - a Swedish boat, to which so much was added that it sank from the first meters. Bjarne Strustrup:

Inside C++, there is a simpler and clearer language that fights for emergence.

C++ is used as an application language thanks to graphical interfaces like Qt and GTK or with 3D motors like Unreal Engine. It is clear that it was designed to optimize computer performance and certainly not programmer performance. The mistakes that inevitably occur with its hard-core and unreadable syntax pay off dearly during debugging. Used where appropriate for system tools, it provides undeniable benefits for C, such as RAI, which will be discussed below.

Example code: Display string characters.

string s = "demo" + "suffixe";
int l = s.length();
for(int i = 0; i < l; i++) {
   char c = s[i];
   printf("%c\n", c);
} 

A brief history of the language

Formalized Action Objects

C++ describes classes in header files and method bodies in source files. By declaring instances of classes, you can reuse sets of variables and methods without having to declare them again.
Overloaded functions allow you to declare them with different parameters, but with the same name.

Classes inherit from each other and share their methods. He has a multifaceted heritage in itself, this was not accepted in derived languages.
Over time, the definition of a structure has evolved in such a way that it becomes the equivalent of a class definition and differs in that the default structure is public and the default class is private. Structures can be endowed with methods and maintain heritage, and in fact it is possible to do without classes completely in a subject-oriented program.

This conceptual model is criticized by Trigve Renskaug, the inventor of MVC and TIN, who considers it too static and not suitable for the reality of processing, for which the representation of objects should change depending on the context. But this shortcoming is shared by all current subject-oriented languages, except perhaps such as Go, which replace inheritance with composition.

Memory management

C++ introduced RAI (Resource Acquisition Is Initialization), the principle that when an object is created, and therefore memory space, it will be automatically released when the object is destroyed. This exempts from collection and free learning of the C language.
A resource can be an object, a class, an instance of a file. She is announced in the osprey and released when you leave the osprey .

C++ 11

The new C++ language is improving, its creator Bjarne Strustrup tells us in three ways:

  1. Language.
  2. Standard Library.
  3. Competition.

The definition of the standard was approved on March 25, 2011 by the C++ ISO committee.
Internal UTF-8 format is now supported for character strings.

New types and keywords

  1. car
    The variable type is determined by the assigned behavior.
    Example:
    vector<string> v = {"Alicia", "Bea", "Clara",  "Dara" };
    for (auto x : v) cout << x <<'\n';
  2. constant
    Constant expression.
  3. nullptr
    Word reserved for null pointer.
    Exempli gratia:
    char *x = nullptr;
  4. raw string.
    Strings in which release codes are not interpreted, for example, in simple quotes in PHP .
    They have the prefix R.
  5. decltype
    The way the type is used in the expression, returns the type and editors of any object, including the function.
  6. UTF 8 literals
    u8 "Any text."
    Used u for UTF16 and U for UTF 32.

Security for types

  1. Controls the value alignment.
  2. Manage default values.

New construction

Loop for one interval.
As implemented in most scripting languages.

int arr[5] = {2, 8, 21, 56, 995}; 
 
for (int &x : arr) {
  printf("%d\n", x);  
}

As you can see, the language retains the principle of minimal source code. It does not use the keyword in in the way most languages do, but rather is a symbol.
A tradition that was born at a time when we saved every character to reduce the size of the code! Memory cost a lot in 1972...

Lambda function.
Functions defined and used locally are contextual and ephemeral.

rvalue
This is a way of referencing the content of a variable, in which content B is assigned to A without copying it, but moving the pointer to the content in perspective or B is no longer used.

"Variadic" model.
Variable argument pattern.

Static approval
Entered with the static_assert keyword, it validates the statement at compile time.

Typical enumeration and scope

Classes

Delegation and legacy of builders. The class constructor can call the constructor of other classes.

Class attributes can be assigned directly in the class definition.

Standard Library

New objects appear that have become familiar in scripting languages ​ ​ such as PHP.

  1. regexp
    Regular expressions
  2. train
    Python-specific.
  3. massif
    Static table.
  4. unordered_map
    Waiting table.
  5. date.
  6. smart pointer
    Smart pointer
  7. ;

Plus various library components and improvements. For example, you can now statically assign a list to a vector in its application .

Competition

Multiple shared memory threads are easy to use. We create a function and call it using a function pointer using the thread command...

#include <thread>

void f(int a) {
  ... code...
}

int main() {
  ...
  thread t(&f, 1000);
  t.join();
  ...
}

The join () command starts the thread.
The asynchronous command calls the function in asynchronous mode, which has become familiar with Ajax .

Features of competition under C++ 11:

  1. Memory model for modern computers with multi-core processors.
  2. ABI flow.
  3. Atomic types.
  4. Mutexes and locks.
  5. Local thread storage.
  6. Asynchronous messaging.

Tools and documents

Objective C is an object-oriented version of C that is easier to use than C++. GnuStep is a development environment for Linux and Windows.

Safety

C++ is a language that gives programmers complete freedom, but it is not a safe language. The US National Security Agency does not recommend using it due to possible vulnerabilities in memory use. The disaffected could exploit flaws that appear with flexible language. When security is important, organizations will need to use other languages such as C #, Go, Java, Swift, or even Rust for masochists.

See also: C++ successor candidates.