Timeline for If immutable objects are good, why do people keep creating mutable objects?
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 1, 2015 at 6:44 | comment | added | Asad Saeeduddin | @PéterTörök It's a little naive to assume that incorporating immutability into a program involves nothing more than dropping all setters. You still need a way for the state of the program to change incrementally, and for this you need builders, or popsicle immutability, or mutable proxies, all of which take about 1 billion times the effort just dropping the setters took. | |
Jun 2, 2015 at 7:53 | comment | added | Martijn |
Getters and setters are not the whole story; there are other aspects of a language that can support or discourage programming with immutable objects. Clojure, for example, by default provides functions such as swap! and update-in . I am by no means an knowledgable Clojure programmer, but I believe it can make a difference.
|
|
Jun 10, 2014 at 7:33 | comment | added | Pete | I think this is the most correct answer. Say you were developing in F# for example, you would create immutable types pr. default. I doubt that most developers would start adding 'mutable' keywords to their F# types, even if they came straight from an imperative programming style | |
Jun 10, 2014 at 7:29 | comment | added | Pete | @PéterTörök - it's also not just about the initial code that your tools can help you with. What about when you make changes? When you add a new field to your immutable type, do you remember to update equality and hashcode functions as well? | |
Aug 24, 2012 at 15:48 | history | made wiki | Post Made Community Wiki by supercat | ||
Jun 8, 2012 at 15:07 | history | rollback | Onorio Catenacci |
Rollback to Revision 1
|
|
Jun 8, 2012 at 14:35 | history | edited | user4051 | CC BY-SA 3.0 |
Remove the chatty opening.
|
Jun 8, 2012 at 1:15 | comment | added | emory | @PéterTörök In an imperative language mutable objects are the default behavior. If you want only immutable objects, it is best to switch to a functional language. | |
Jun 7, 2012 at 13:08 | comment | added | Péter Török | That might be overcome with more communication and education, e.g. it is advisable to talk or give a presentation to one's teammates about a new coding style before actually introducing it into an existing codebase. It is true that a good project has a common coding style which is not just an amalgam of the coding styles favoured by every (past and present) project member. So introducing or changing coding idioms should be a team decision. | |
Jun 7, 2012 at 12:37 | comment | added | Onorio Catenacci | @PéterTörök it's not just the additional effort--it's the fact that your fellow coders will want to hang you in effigy because they find your coding style so alien to their experience. That also discourages this sort of thing. | |
Jun 7, 2012 at 7:19 | comment | added | Péter Török |
In most modern IDEs I know, it takes practically the same amount of effort to generate only getters, as to generate both getters and setters. Although it is true that adding final , const etc. takes a bit of extra effort... unless you set up a code template :-)
|
|
Jun 6, 2012 at 15:13 | history | answered | Onorio Catenacci | CC BY-SA 3.0 |