January 2020
Intermediate to advanced
454 pages
11h 25m
English
Example 3 demonstrates the principle of least surprise as follows:
#include <iostream>int add(int a, int b){ return a + b; }int main(void){ std::cout << "The answer is: " << add(41, 1) << '\n'; return 0;}
As shown in the preceding example, we're adhering to the principle of least surprise here. The API is designed to add two integers and return the result, and the API intuitively performs this action as expected.