Pure functions in C++

5 years ago
Anonymous $oq8ACmxlDW

https://medium.com/software-design/pure-functions-in-c-fc102fd9c5e0

C++ is not a functional programming language. Functions causing side-effects is the norm. If a compiler does not see the body of a function, it assumes that the function causes side effects. This can result in missed optimization opportunities.

Consider the following code. Here the main function for (some reason) computes the square of the total number of arguments twice and returns the sum of the squares.

Last Seen
19 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
37 minutes ago
Reputation
0
Spam
0.000
Last Seen
15 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000