4 ms·
I prefer functional programming because referentially transparent functions are easier to reason about and test. Brevity of control flow hasn't brought me much
by AlexCoventry 7y ago
I prefer functional programming because referentially transparent functions are easier to reason about and test. Brevity of control flow hasn't brought me much benefit.
- kbuchanan 7y agoCouldn't agree more! ... I just had to laugh to myself at how this, THIS is why functional programming is so... rarely adopted. Like, "referentially transparent functions"?! What happened to `website.run.now!`?!
- lemmsjid 7y agoReferential transparency is a handy thing to think about in OOP as well as functional programming. If you provide the same parameters to a function, will you always get the same result? If yes, and if the function is 'pure', e.g. does not result in some side effect like state manipulation, you could replace the function itself with the output of that function. If so, and the function is computationally expensive, you can memoize the function, which is a specific form of caching where you auto cache the results by the parameters passed to the function. This is a handy chain of reasoning in any language, and in a more dedicated functional language might be supported as a concept in the language itself. Like in OOP, you don't have to have that term memorized to actually use a functional language, just remember the pattern.
- tome 7y agowebsite.run.now is referentially transparent in Haskell (or rather, to mention the one I use, Happstack.Lite.serve: https://hackage.haskell.org/package/happstack-lite-7.3.6/docs/Happstack-Lite.html https://hackage.haskell.org/package/happstack-lite-7.3.6/doc...)
- carapace 7y agoYeah, in his Turing Award lecture introducing FP Backus made a big deal of the ability to reason about programs mathematically. I've been playing with a functional language Joy that combines (IMO) the best features of Forth and Lisp and one of the neat things about it is that you can derive functions from simple (almost geometric) syntactic manipulations as the whole language is just referentially transparent functions. ( http://joypy.osdn.io/notebooks/index.html http://joypy.osdn.io/notebooks/index.html )
- imtringued 7y agoUnfortunately nowadays the majority of my functions are not referentially transparent.