11. • Язык C++ предоставляет слишком
много возможностей
template <typename T> T f(T&& t);
#define M(...) { __VA_ARGS__ }
class virtual
publicdecltype
const
auto a = [](){}; throw
12. • Язык C++ предоставляет слишком
много возможностей
• Нет времени научиться использовать
их правильно
13. • Язык C++ предоставляет слишком
много возможностей
• Нет времени научиться использовать
их правильно
• Следствие: сложный и ненадёжный
код
27. std::vector<int> v = gen_v();
int s;
for (int i : v)
{
s += i;
}
...
f(s);
h(s);
28. std::vector<int> v = gen_v();
int s;
for (int i : v)
{
s += i;
}
...
f(s);
h(s);
29. > gcc –Wall –std=c++11 x.cpp
No warnings
std::vector<int> v = gen_v();
int s;
for (int i : v)
{
s += i;
}
...
f(s);
h(s);
30. > gcc –Wall –std=c++11 x.cpp
No warnings
> gcc –Wall –O –std=c++11 x.cpp
warning: ‘s’ may be used uninitialized
std::vector<int> v = gen_v();
int s;
for (int i : v)
{
s += i;
}
...
f(s);
h(s);
31. std::vector<int> v = gen_v();
int s = 0;
for (int i : v)
{
s += i;
}
...
f(s);
h(s);
32. std::vector<int> v = gen_v();
int s = 0;
for (int i : v)
{
s += i;
}
...
f(s);
h(s);
А вдруг?
void f(int&);
33. std::vector<int> v = gen_v();
int s = std::accumulate(begin(v), end(v), 0);
...
f(s);
h(s);
34. const std::vector<int> v = gen_v();
const int s = std::accumulate(begin(v), end(v), 0);
...
f(s);
h(s);
35. const std::vector<int> v = gen_v();
const int s = std::accumulate(begin(v), end(v), 0);
...
f(s);
h(s);
• Код становится проще
36. const std::vector<int> v = gen_v();
const int s = std::accumulate(begin(v), end(v), 0);
...
f(s);
h(s);
• Код становится проще
• Защищает от части ошибок
37. const std::vector<int> v = gen_v();
const int s = std::accumulate(begin(v), end(v), 0);
...
f(s);
h(s);
• Код становится проще
• Защищает от части ошибок
• Способствует рефакторингу
68. Magnifying Glass designed by Karl Schaeffler from the thenounproject.com
Book designed by Olivier Guin from the thenounproject.com
Поиск
Справочник
69. Magnifying Glass designed by Karl Schaeffler from the thenounproject.com
Book designed by Olivier Guin from the thenounproject.com
Map designed by Nicholas Menghini from the thenounproject.com
Поиск
Справочник
Карта
70. Magnifying Glass designed by Karl Schaeffler from the thenounproject.com
Book designed by Olivier Guin from the thenounproject.com
Map designed by Nicholas Menghini from the thenounproject.com
Folder Tree designed by Juan Pablo Bravo from the thenounproject.com
Поиск
Справочник
Карта
VFS
71. Magnifying Glass designed by Karl Schaeffler from the thenounproject.com
Book designed by Olivier Guin from the thenounproject.com
Map designed by Nicholas Menghini from the thenounproject.com
Folder Tree designed by Juan Pablo Bravo from the thenounproject.com
Поиск
Справочник
Карта
VFS
72. Magnifying Glass designed by Karl Schaeffler from the thenounproject.com
Book designed by Olivier Guin from the thenounproject.com
Map designed by Nicholas Menghini from the thenounproject.com
Folder Tree designed by Juan Pablo Bravo from the thenounproject.com
Поиск
Справочник
Карта
Обновления
VFS
73. Magnifying Glass designed by Karl Schaeffler from the thenounproject.com
Book designed by Olivier Guin from the thenounproject.com
Map designed by Nicholas Menghini from the thenounproject.com
Folder Tree designed by Juan Pablo Bravo from the thenounproject.com
Поиск
Справочник
Карта
Обновления
VFS