Re:What's wrong with Object-Oriented Programming and Functio...
by quchen on Tuesday November 12, 2013 @06:14AM
(#6717087)
That is not true. In C++ you can always retrieve the current time, store parameters in a database, print to stdout, or retrieve a global variable without changing the interface. Merely announcing purity to other programmers does not solve this problem: announcements can be wrong, missing, incomplete, and maybe most importantly the compiler doesn't know about them.
Re:What's wrong with Object-Oriented Programming and Functio...
by emn13 on Tuesday November 12, 2013 @07:03PM
(#6722363)
Heck, mere "announcements" might even be quite useful, especially since it is slightly compiler supported. But const in C++ does not announce purity, nor does it announce thread-safety. I just announced that it won't observably change non-mutable members, that's it.
Re:What's wrong with Object-Oriented Programming and Functio...
by eru on Tuesday November 12, 2013 @05:43AM
(#6716987)
D actually has a better model for pure functions than C++. See http://dlang.org/function.html#pure-functions
Re:What's wrong with Object-Oriented Programming and Functio...
by luikore on Wednesday November 13, 2013 @03:19AM
(#6723999)
Modern C/C++ compilers can detect a sub set of pure functions and do possible aggressive optimisations. There's even an `__attribute__ ((pure))` in GCC for explicit pureness.
Yes, it's true that with casting and so on you are not actually ensuring anything when you declare a function const like you are with Haskell, but you announce to other programmers who will use your code that:
1) There will be no observable state changes
2) That the function is thread safe
This is a very useful thing for a language to support in it's function declarations, and other languages could do well to learn from that.