aspose file tools*
The moose likes Scala and the fly likes Mutating state inside a function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Scala
Bookmark "Mutating state inside a function" Watch "Mutating state inside a function" New topic
Author

Mutating state inside a function

Gabriel Beres
Ranch Hand

Joined: Sep 09, 2006
Posts: 61
Hey,

I understand why mutating instance variables is a bad thing.
But what about mutating state inside a function? To my knowledge, variables inside the function are allocated in the stack and not in the heap, therefore they are not objects of any concurrency issue.

Scala and other functional languages say you should not mutate any state. Why it is so?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Gabriel Beres wrote:Hey,

I understand why mutating instance variables is a bad thing.
But what about mutating state inside a function? To my knowledge, variables inside the function are allocated in the stack and not in the heap, therefore they are not objects of any concurrency issue.

Scala and other functional languages say you should not mutate any state. Why it is so?


That is a good question. Have a look here about Referential Transparency to better answer your question.

http://en.wikipedia.org/wiki/Referential_transparency_%28computer_science%29


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mutating state inside a function