On 04/08/12 19:14, Warren Lynn wrote:
Here I am still creating immutable objects. You may say I am "setting" things, but that is for creating a new object.
I am not sure I follow...If you're just creating a new record yourself, you can pass whatever you want to the constructor...no need for 'setting' whatsoever...On the other hand if you're consuming an object then you might need to 'set' some fields before it is useful (where doto comes into play).
It makes sense because when you create an object, the values of the fields may need to meet certain integrity requirements, or some transformation from the caller's arguments.
I won't object to this for a simple reason... in OO languages it is good and idiomatic to have a single road to mutation (the set method) and always use that (even from the constructor when initialising) so you can easily, as you say, check for certain criteria or do some transformation in one place. However this is a result of uncontrolled mutation! People realised it is better to avoid using the "=" (assignment operator) in favour of setters and encapsulated all the null/type-checking, shoot me now code inside them. However, if you're in control of your objects and your field are always immutable then what is the point of a setter method? What does it protect you from? Do you really need so many integrity checks or transformations when you can only really set the value once?
Functionally, of course we can do it, as you can create a record with any values for the fields. But in my view it is not the main objective to say "it works" , "it is powerful", "it give user freedom" when designing a language. My classic answer to those arguments is: how about assembly language? It definitely works, definitely powerful, and put no restrictions on the user. I know nobody who is a fan of such language.
Deep inside, we are all fans of assembly or at least we should be... :) Jim -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en