Example 3

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) << ' ';
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. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset