i wouldnt even go as far as multi threaded programs. imagine you have a Date and pass to a method that you dont have the source (say a proprietary library)
api.doSomethingWithIt(date, arg, etc) how can i know that the method didnt change the Date (since its mutable)? Id have to clone the Date before calling the method to be safe, unless Date is imutable. In the end, i guess Imutability has more to do with predictability than with performance (specially in multithreaded environments) On Thu, Apr 29, 2010 at 11:38 AM, Kevin Wright < [email protected]> wrote: > In a nutshell: > > I have a (mutable) list of customers, ordered by surname > In thread A, I take that list and display it on a webpage > In thread B, I take that same list, sort it by reverse order of when I last > phoned them, and display on a different page > > Because of the way concurrency works, thread A is interrupted by thread B > halfway through displaying the list, needless to say the output is not as > expected. > > So it would have been much safer if the list was immutable and thread B > created a copy of it that was sorted differently. > > Could locks have solved it? Probably, assuming your concurrent programming > skills are flawless and you've never encountered a deadlock or race > condition in your life, and it's also a pretty steep performance cost once > you've scaled up to 100s of threads. > > > > On 29 April 2010 15:17, Wildam Martin <[email protected]> wrote: > >> On Thu, Apr 29, 2010 at 14:41, egervari <[email protected]> wrote: >> > How many of you are currently programming in a hybrid language such as >> > Scala? >> >> I don't >> >> >> > I'm finding it difficult to make things immutable. While I am >> > definitely using more immutability than I ever have in the past, I >> > don't think it's practical for some applications. >> >> Fine, that I am not the only one thinking that way. And I might never >> understand why it is sooo good to have everything immutable. I >> definitely want a lot of objects to be mutable. I am dealing with >> software and not with statues of stone. ;-) >> >> -- >> Martin Wildam >> >> -- >> You received this message because you are subscribed to the Google Groups >> "The Java Posse" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<javaposse%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/javaposse?hl=en. >> >> > > > -- > Kevin Wright > > mail/google talk: [email protected] > wave: [email protected] > skype: kev.lee.wright > twitter: @thecoda > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<javaposse%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > -- http://mapsdev.blogspot.com/ Marcelo Takeshi Fukushima -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
