On Oct 16, 2014, at 5:08 PM, Mark Engelberg <mark.engelb...@gmail.com> wrote: > But let's say later you decide you want your data model to be {:first-name > "Alice", :last-name "Beasley", :email "al...@example.com"}, and you want to > change name to be a computed value that concatenates first and last names -- > this is going to break all your existing code. If name were only accessed > throughout your code via the call `get-name`, then it would be trivial to > make this change.
But presumably you'd then be writing code that does (:first-name customer) and (:last-name customer) so you're likely modifying old code anyway? Even if you're only doing this in new code, your original make-customer presumably took "first last" "em...@addre.ss" and now will either need to change to "first" "last" "em...@addre.ss" - and you'll have to change every constructor call - or you'll modify it to split "first last" automatically to populate :first-name and :last-name - in which case you might as well still populate :name (and none of your code needs to change). So I think that's a bit of a straw man argument. > Many OO languages force, or encourage you stylistically, to hide everything > behind setters and accessors, so you get for free the ability to change your > mind about the data model later. But not the API of the class - that still forces changes to client code - and the setters and accessors are part of that API so adding getFirstName() / getLastName() changes your API anyway. > With Clojure, it is very common to allow your data model to be the API. This > puts some additional pressure to get it right the first time. You have to > explicitly think ahead about which fields might need to change in the future. In practice, I don't think it makes it any harder than in OOP - and given the ability to add fields to maps with no client code changes required, I think it's actually _easier_ in FP, in nearly all _real world_ cases. Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880)
signature.asc
Description: Message signed with OpenPGP using GPGMail