{"action":"created","issue":{"url":"https://api.github.com/repos/fpinscala/fpinscala/issues/496","repository_url":"https://api.github.com/repos/fpinscala/fpinscala","labels_url":"https://api.github.com/repos/fpinscala/fpinscala/issues/496/labels{/name}","comments_url":"https://api.github.com/repos/fpinscala/fpinscala/issues/496/comments","events_url":"https://api.github.com/repos/fpinscala/fpinscala/issues/496/events","html_url":"https://github.com/fpinscala/fpinscala/issues/496","id":198151916,"number":496,"title":"Chapter 1: functional example of buyCoffee actually has less logic than non-functional one","user":{"login":"quiram","id":7751234,"avatar_url":"https://avatars.githubusercontent.com/u/7751234?v=3","gravatar_id":"","url":"https://api.github.com/users/quiram","html_url":"https://github.com/quiram","followers_url":"https://api.github.com/users/quiram/followers","following_url":"https://api.github.com/users/quiram/following{/other_user}","gists_url":"https://api.github.com/users/quiram/gists{/gist_id}","starred_url":"https://api.github.com/users/quiram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quiram/subscriptions","organizations_url":"https://api.github.com/users/quiram/orgs","repos_url":"https://api.github.com/users/quiram/repos","events_url":"https://api.github.com/users/quiram/events{/privacy}","received_events_url":"https://api.github.com/users/quiram/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-12-30T14:13:05Z","updated_at":"2017-01-08T16:55:37Z","closed_at":"2017-01-04T17:36:13Z","body":"First of all, I'd like to thank the effort put into this book, I'm finding it very interesting. However, I find that chapter 1, where the benefits of FP are portrayed, is a bit misleading.\r\n\r\nThe example shows how the `buyCoffee` method is difficult to test and to reason with because it has a side effect (the credit card transaction). This is solved by changing the method to return both `Coffee` and `Charge`, without any actual communication or transaction. That is, the second version of `buyCoffee` is \"incomplete\" with respect to the first one, since more processing is needed elsewhere to achieve the same result.\r\n\r\nThe objective of the chapter is to demonstrate how FP leads to better code but, while it is true that the second version of `buyCoffee` is more readable and testable, one could argue that this benefit doesn't come from FP, but from the fact that logic has been removed. I think a full example, i.e. one where an actual credit card transaction is recorded, is needed to do a proper comparison."},"comment":{"url":"https://api.github.com/repos/fpinscala/fpinscala/issues/comments/271163262","html_url":"https://github.com/fpinscala/fpinscala/issues/496#issuecomment-271163262","issue_url":"https://api.github.com/repos/fpinscala/fpinscala/issues/496","id":271163262,"user":{"login":"quiram","id":7751234,"avatar_url":"https://avatars.githubusercontent.com/u/7751234?v=3","gravatar_id":"","url":"https://api.github.com/users/quiram","html_url":"https://github.com/quiram","followers_url":"https://api.github.com/users/quiram/followers","following_url":"https://api.github.com/users/quiram/following{/other_user}","gists_url":"https://api.github.com/users/quiram/gists{/gist_id}","starred_url":"https://api.github.com/users/quiram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quiram/subscriptions","organizations_url":"https://api.github.com/users/quiram/orgs","repos_url":"https://api.github.com/users/quiram/repos","events_url":"https://api.github.com/users/quiram/events{/privacy}","received_events_url":"https://api.github.com/users/quiram/received_events","type":"User","site_admin":false},"created_at":"2017-01-08T16:55:37Z","updated_at":"2017-01-08T16:55:37Z","body":"Maybe I need to continue reading for me to grasp it fully, but so far it feels a bit like cheating. It's true that the logic to handle credit card payment isn't really included at the beginning either, but at least the call to such logic is there. In other words, the initial code, when run, would execute everything that needs to be executed to provide a full business requirement, while the final code doesn't (an actual credit card payment still has to be done). That is what led me to think that there was less logic at the end of the process.\r\n\r\nLet me try to say it in a different way: I agree that the credit card logic doesn't belong in this particular section of the code, but it does belong _somewhere._ I guess what I'm suggesting is that the example would be more illustrative if that _somewhere_ was included.\r\n\r\nIn any case, thanks a lot for dedicating the time to discuss this."}}
{"actor":{"display_login":"quiram"}}