Skip to content

Commit d552ab9

Browse files
committed
[doc] cppnow-2017
1 parent 396964f commit d552ab9

File tree

3 files changed

+51
-29
lines changed

3 files changed

+51
-29
lines changed

docs/cppnow-2017/images/done.png

50 KB
Loading

docs/cppnow-2017/images/pair.png

78.4 KB
Loading

docs/cppnow-2017/index.html

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@
472472

473473
### Feature: Print a value from a file
474474

475-
### KISS - ~~Keep it simple~~, STUPID
475+
#### KISS - ~~Keep it simple~~, STUPID
476476

477477
```cpp
478478
int main() {
@@ -486,15 +486,15 @@
486486
}
487487
```
488488

489-
##### Unit-Testing - **Give me a break!**
489+
##### Unit-Testing? - Give me a break!
490490

491491
----
492492

493493
### A few iterations later...
494494

495495
----
496496

497-
#### **Stupid** vs <strike>SOLID</strike>
497+
#### Stupid vs <strike>SOLID</strike>
498498

499499
```cpp
500500
class Manager { // Indescriptive Naming
@@ -510,8 +510,9 @@
510510
```cpp
511511
class App {
512512
public:
513-
App() { manager = new Manager; } // Tight Coupling
514-
~App() { delete manager; }
513+
App()
514+
: manager(std::make_unique<Manager>()); // Tight Coupling
515+
{ }
515516
516517
__attribute__((always_inline)) void run() { // Premature Optimization
517518
Logger::instance() // Singleton
@@ -522,13 +523,13 @@
522523
)
523524
}
524525
private:
525-
Manager* manager;
526+
std::unique_ptr<Manager> manager;
526527
};
527528
```
528529

529530
----
530531

531-
#### **Stupid** vs <strike>SOLID</strike>
532+
#### Stupid vs <strike>SOLID</strike>
532533

533534
#### Unit-testing?
534535

@@ -566,7 +567,7 @@
566567

567568
----
568569

569-
#### <strike>Stupid</strike> vs **SOLID**
570+
#### <strike>Stupid</strike> vs SOLID
570571

571572
```cpp
572573
/**
@@ -608,11 +609,12 @@
608609

609610
----
610611

611-
#### <strike>Stupid</strike> vs **SOLID** (Dependency Injection)
612+
#### <strike>Stupid</strike> vs SOLID
612613

613614
```cpp
614615
/**
615-
* "Depend on abstractions, not on concretions"
616+
* Dependency Inversion
617+
* "Depend on abstractions, not on concretions"
616618
*/
617619
class IReader { class IPrinter {
618620
public: public:
@@ -626,10 +628,10 @@
626628
IReader& reader;
627629
IPrinter& printer;
628630
ILogger& logger;
629-
630631
public:
631632
/**
632-
* "Don't call us, we'll call you", Hollywood principle
633+
* Dependency Injection
634+
* "Don't call us, we'll call you", Hollywood principle
633635
*/
634636
App(IReader& reader, IPrinter& printer, ILogger& logger);
635637
@@ -997,6 +999,24 @@
997999
9981000
----
9991001
1002+
### Automatic Mocks Injection - MAKE API
1003+
1004+
```cpp
1005+
namespace testing {
1006+
/**
1007+
* [Proposal - generic factories]
1008+
* http://.../wg21/docs/papers/2016/p0338r0.pdf
1009+
*/
1010+
template <class T, class... TArgs>
1011+
auto make(TArgs&&... args);
1012+
1013+
template <template<auto...> class T, ... TArgs>
1014+
auto make(TArgs&&... args);
1015+
}
1016+
```
1017+
1018+
----
1019+
10001020
####Test - Manual mocks injection
10011021
10021022
```cpp
@@ -1183,13 +1203,10 @@
11831203

11841204
```cpp
11851205
"[scenario] Value from a file is displayed"_test {
1186-
GIVEN("Hhe App is created") {
1187-
auto [app, mocks] = testing::make<App>()
1188-
}
1189-
GIVEN(mocks<Readable>(), read().WillOnce(Return(42));
1206+
auto [app, mocks] = testing::make<App>()
11901207
1208+
GIVEN(mocks<Readable>(), read().WillOnce(Return(42));
11911209
WHEN(app.run());
1192-
11931210
THEN(mocks<Printable>(), print(42));
11941211
}
11951212
```
@@ -1237,7 +1254,7 @@
12371254
12381255
When at least 1000 shares of GOOGL were bought at price $950
12391256
1240-
Then A buy order for 100 shares of GOOGL should be executed
1257+
Then A buy order for 100 shares of GOOGL should've be executed
12411258
And The TS should own 100 shares of GOOGL
12421259
And The TS should have $90'000
12431260
```
@@ -1249,7 +1266,7 @@
12491266
12501267
When 50 shares of MSFT were sold
12511268
1252-
Then A sell order for 50 shares of MSFT stock should have been executed
1269+
Then A sell order for 50 shares of MSFT stock should've been executed
12531270
And The TS should own 50 shares of APPL stock
12541271
```
12551272

@@ -1310,14 +1327,7 @@
13101327

13111328
----
13121329

1313-
TDD
1314-
eXtreme programming -> pairing, one test one implementation
1315-
1316-
> Always start from the expections (express intentions!)
1317-
----
1318-
1319-
1320-
#### 1. TDD/RED - Write a bit of test (start from expectations, intentions)
1330+
### 1. TDD/RED - Write a bit of test (start from expectations, intentions)
13211331

13221332
```cpp
13231333
"should not print anything when the input is empty" = [] {
@@ -1327,6 +1337,16 @@
13271337
```
13281338

13291339
----
1340+
1341+
## TDD and eXtreme programming / Pairing
1342+
1343+
<img src="images/pair.png" width="85%" />
1344+
1345+
> 1. One dev is writing a test and the other is making it pass (the simplest way)
1346+
> 2. Switch the rules!
1347+
1348+
----
1349+
13301350
#### 2. TDD/GREEN - Make it compile/pass (the simpler way)
13311351
#### 3. TDD/REFECTOR - Remove duplicates/extract
13321352

@@ -1433,8 +1453,10 @@
14331453

14341454
----
14351455

1436-
Take the next story...
1437-
* Pair with someone else of the team!
1456+
<img style="background:none; border:none; box-shadow:none;" src="images/done.png" />
1457+
1458+
* #### Take the next story...
1459+
* #### Pair with someone else of the team! (knowledge sharing)
14381460

14391461
==============================================================================
14401462

0 commit comments

Comments
 (0)