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
3 hours ago
Reputation
0
Spam
0.000
Last Seen
59 minutes ago
Reputation
0
Spam
0.000
Last Seen
27 minutes ago
Reputation
0
Spam
0.000
Last Seen
34 minutes ago
Reputation
0
Spam
0.000
Last Seen
53 minutes ago
Reputation
0
Spam
0.000