Note that there are some explanatory texts on larger screens.

plurals
  1. POFunctional programming: immutability etc
    text
    copied!<p>I recently <a href="https://stackoverflow.com/questions/353912/functional-programming-state-vs-reassignment">asked a question</a> about functional programming, and received (good!) answers that prompted more questions (as seems to be the case with learning, sometimes). Here are a couple examples:</p> <ol> <li><p>One answer made reference to an advantage of immutable data structures: each thread can have its own copy. Now, to me, this sounds rather like a version control system (to use an analogy), where instead of locking code that someone has checked out so that it can't be modified by anyone else, everyone can check out their own copies. Sounds good. However, in VCS you have the concept of "merging" changes, in the case that two people changed the same stuff. It seems like this issue could certainly come up in a multithreaded scenario... so how is "merging" done when it's important that threads see the most recent data?</p></li> <li><p><a href="https://stackoverflow.com/questions/353912/functional-programming-state-vs-reassignment#355040">This answer</a> talked about the case where operations were being performed in a loop on an object, and how you can use a new object each time through instead of updating an old one. However, let's say the <code>bankAccount</code> is being updated in a non-loop scenario--for example a GUI banking system. The operator clicks the "Change Interest Rate" button, which fires an event that would (in C# for example) do something like <code>bankAccount.InterestRate = newRateFromUser</code>. I feel like I'm being dense here, but hopefully my example makes sense: there has to be some way that the object is updated, right? Several other things may depend on the the new data.</p></li> </ol> <p>Anyway, if you can help me get my head around the paradigm shift, I'd be appreciative. I remember my brain going through similar "stupid phases" when learning OOP after a background of the simple procedural imperative approach to coding.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload